:root {
  color-scheme: light;
  --bg: #eafbea;
  --bg-2: #d4f5d0;
  --card-bg: #ffffff;
  --text: #1c2b1a;
  --muted: #5c6b58;
  --accent: #2f9e44;
  --gold: #f2b705;
  --a-color: #2b6cb0;
  --b-color: #e8590c;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  --radius: 18px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #10190f;
    --bg-2: #162313;
    --card-bg: #1d2b1b;
    --text: #eafbea;
    --muted: #9db298;
    --accent: #4ad66d;
    --gold: #ffd23f;
    --a-color: #6fb1ff;
    --b-color: #ff9457;
    --shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: linear-gradient(180deg, var(--bg-2), var(--bg) 160px);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

.topbar {
  padding: env(safe-area-inset-top) 20px 8px;
  text-align: center;
}

.topbar h1 {
  margin: 12px 0 2px;
  font-size: 1.6rem;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 4px 14px 20px;
}

.game-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-title {
  margin: 4px 0 0;
  font-size: 1.3rem;
  text-align: center;
}

.leader-banner {
  background: linear-gradient(135deg, var(--gold), var(--accent));
  color: #14260f;
  border-radius: var(--radius);
  padding: 16px 18px;
  font-weight: 700;
  font-size: 1.05rem;
  text-align: center;
  box-shadow: var(--shadow);
  min-height: 1.4em;
  animation: pop 0.25s ease;
}

.streak-line {
  margin-top: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0.85;
}

@keyframes pop {
  from {
    transform: scale(0.96);
    opacity: 0.6;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.live-score {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.live-side {
  flex: 1;
  text-align: center;
}

.side-name {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

.side-games {
  font-size: 2.4rem;
  font-weight: 800;
}

.live-versus {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
}

.sub-score {
  text-align: center;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.action-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.action-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  flex: 1;
  border: none;
  border-radius: 14px;
  padding: 14px 10px;
  font-size: 0.95rem;
  font-weight: 700;
  color: white;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease;
}

.btn:active {
  transform: scale(0.96);
}

.btn-a {
  background: var(--a-color);
}

.btn-b {
  background: var(--b-color);
}

.btn-generic {
  background: var(--accent);
}

.tally-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 0.95rem;
}

.tally-row + .tally-row {
  border-top: 1px solid rgba(128, 128, 128, 0.15);
}

.board-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 0.98rem;
}

.board-row + .board-row {
  border-top: 1px solid rgba(128, 128, 128, 0.15);
}

.board-row .name {
  display: flex;
  align-items: center;
  gap: 6px;
}

.board-row .wins {
  font-weight: 800;
}

.undo-link {
  align-self: center;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.activity-card {
  margin-top: 22px;
}

#activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}

#activity-list li {
  font-size: 0.85rem;
  color: var(--muted);
}

#activity-list li b {
  color: var(--text);
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card-bg);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.1);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  gap: 4px;
}

.tab-btn {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tab-btn.active {
  color: var(--accent);
  background: rgba(47, 158, 68, 0.12);
}

.tab-emoji {
  font-size: 1.4rem;
  pointer-events: none;
}

@media (min-width: 520px) {
  #app {
    padding-top: 10px;
  }
}
