:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1e1c;
  --text-muted: #6b706b;
  --border: #e2e4e0;
  --accent: #1f6f4a;
  --accent-contrast: #ffffff;
  --warn-bg: #fdf1e6;
  --warn-text: #8a4b1c;
  --danger: #b3261e;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121412;
    --surface: #1b1e1b;
    --text: #edefec;
    --text-muted: #9aa39a;
    --border: #2c302c;
    --accent: #4cae7d;
    --accent-contrast: #0c150f;
    --warn-bg: #2e2314;
    --warn-text: #e3a26a;
    --danger: #e5766d;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .9rem; color: var(--text-muted); font-weight: 600; }

button, input {
  font: inherit;
  color: inherit;
}

/* Login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem;
}
.login-sub { color: var(--text-muted); margin-top: -.25rem; margin-bottom: 1.25rem; }
.login-card form { display: flex; flex-direction: column; gap: .3rem; }
.login-card label { font-size: .85rem; color: var(--text-muted); margin-top: .5rem; }
.login-card input {
  padding: .65rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.login-card button {
  margin-top: 1.25rem;
  padding: .75rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}
.error { color: var(--danger); font-size: .9rem; }

/* App shell */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .85rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-actions { display: flex; align-items: center; gap: .75rem; font-size: .85rem; }
.user-name { color: var(--text-muted); }
.logout-link { color: var(--accent); text-decoration: none; font-weight: 600; }

.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 52px;
  z-index: 5;
}
.tab {
  flex: 1;
  padding: .75rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-weight: 600;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.view { display: none; padding: 1rem; max-width: 640px; margin: 0 auto; }
.view.active { display: block; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.panel-header { display: flex; align-items: center; justify-content: space-between; }
.hint { color: var(--text-muted); font-size: .85rem; margin-top: -.25rem; }

#import-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
input[type="file"], input[type="text"] {
  padding: .55rem .65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
#import-form input[type="file"] { width: auto; flex: 1; }

.btn-primary, .btn-secondary, #import-form button {
  padding: .55rem 1rem;
  border-radius: 8px;
  border: none;
  font-weight: 600;
}
.btn-primary, #import-form button {
  background: var(--accent);
  color: var(--accent-contrast);
}
.btn-secondary {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
}
#save-round-btn { width: 100%; margin-top: 1rem; padding: .75rem; }

.feedback { font-size: .85rem; color: var(--text-muted); min-height: 1.2em; }

.player-list, .pool-list, .team-slot, .round-history {
  list-style: none;
  margin: .5rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.player-list li, .pool-list li, .team-slot li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.pool-list li { cursor: pointer; }
.pool-list li.disabled { opacity: .4; cursor: default; }
.pool-list li button, .team-slot li button, .player-list li button {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0 .25rem;
}
.player-list li .remove-btn { color: var(--danger); }

.team-columns { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-top: .75rem; }
.team-column h3 { display: flex; justify-content: space-between; }
.count { color: var(--text-muted); font-weight: 500; }

.warning {
  margin-top: 1rem;
  padding: .75rem;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: .9rem;
}

.round-history li {
  flex-direction: column;
  align-items: flex-start;
  gap: .3rem;
}
.round-history .round-title { font-weight: 600; }
.round-history .round-teams { font-size: .85rem; color: var(--text-muted); }
.round-history .round-repeat { font-size: .85rem; color: var(--warn-text); }

@media (min-width: 700px) {
  .view { max-width: 720px; }
}
