:root {
  --bg: #121820;
  --panel: #1a2430;
  --text: #e6e4dc;
  --muted: #8a93a0;
  --you: #62cfbe;
  --ai: #ba8cd6;
  --win: #e8c46a;
  --accent: #0b6e4f;
  --line: #3a4656;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(900px 500px at 20% -10%, #1e3a32, transparent 55%),
              radial-gradient(800px 480px at 100% 0%, #2a2440, transparent 50%),
              var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.75rem 0.7rem calc(1rem + var(--safe-b));
}
header { text-align: center; margin-bottom: 0.25rem; width: 100%; }
h1 {
  margin: 0;
  font-size: clamp(1.45rem, 5vw, 2.4rem);
  letter-spacing: -0.03em;
  font-weight: 750;
}
.sub { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.88rem; }
.bar {
  display: flex;
  gap: 0.85rem;
  flex-wrap: wrap;
  justify-content: center;
  margin: 0.45rem 0 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
  width: 100%;
}
#status { color: var(--win); font-weight: 600; }
.bar.match-hud {
  display: block;
  width: min(1100px, 100%);
  margin: 0.7rem 0 0.65rem;
}
.scoreboard {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px minmax(0, 1fr);
  align-items: stretch;
  gap: 12px;
  padding: 12px;
  color: #eef3fc;
  background: linear-gradient(120deg, #172733, #141c2a 52%, #251f36);
  border: 1px solid #3b4558;
  border-radius: 18px;
  box-shadow: 0 8px 24px #080d1626, inset 0 1px 0 #ffffff0a;
}
.score-side {
  --team-color: #62cfbe;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 12px 16px 10px;
  border: 1px solid #62cfbe35;
  border-top: 3px solid var(--team-color);
  border-radius: 12px;
  background: #62cfbe08;
  transition: background 200ms, box-shadow 200ms;
}
.score-ai { --team-color: #ba8cd6; border-color: #ba8cd635; border-top-color: var(--team-color); background: #ba8cd608; }
.score-name { display: flex; align-items: center; gap: 8px; color: var(--team-color); font-size: 0.82rem; font-weight: 800; letter-spacing: 0.14em; }
.score-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 12px currentColor; }
.score-value {
  display: block;
  margin: 2px 0 0;
  font-family: "Bahnschrift", "Arial Black", system-ui, sans-serif;
  font-size: clamp(3rem, 9vw, 5.5rem);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.04em;
  color: var(--team-color);
  text-shadow: 0 0 24px #ffffff12;
}
.score-value.is-long { font-size: clamp(2rem, 6vw, 4rem); }
.score-caption { min-height: 1.2em; margin-top: 5px; color: #a5afbf; font-size: 0.6rem; font-weight: 800; letter-spacing: 0.12em; }
.score-side[data-result="leading"] .score-caption { color: var(--team-color); }
.score-side[data-result="winner"] { background: #e8c46a14; box-shadow: inset 0 0 28px #e8c46a12, 0 0 0 1px #e8c46a80; }
.score-side[data-result="winner"] .score-caption { color: #f2d78f; }
.score-center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.score-versus { display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid #566075; border-radius: 50%; background: #101722; color: #c4cbd8; font-size: 0.85rem; font-weight: 900; font-style: italic; }
.score-draws { display: flex; flex-direction: column; align-items: center; gap: 3px; color: #8e9aaf; font-size: 0.55rem; font-weight: 700; letter-spacing: 0.1em; }
.score-draws strong { color: #d2d9e5; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.match-status { display: flex; align-items: center; justify-content: center; gap: 7px; min-height: 24px; margin-top: 7px; font-size: 0.78rem; text-align: center; }
.status-dot { width: 5px; height: 5px; flex-shrink: 0; background: #e8c46a; border-radius: 50%; }
.play-shell .bar.match-hud { display: block; width: auto; margin: 0 0.35rem 0.65rem; }
@media (max-width: 420px) {
  .scoreboard { grid-template-columns: minmax(0, 1fr) 42px minmax(0, 1fr); gap: 7px; padding: 8px; border-radius: 14px; }
  .score-side { padding: 10px 8px 9px; }
  .score-versus { width: 34px; height: 34px; font-size: 0.72rem; }
  .score-name { font-size: 0.72rem; }
  .score-caption { font-size: 0.52rem; letter-spacing: 0.07em; }
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: center;
  align-items: center;
  width: min(1100px, 100%);
  margin: 0 0 0.55rem;
}
.actions { display: inline-flex; gap: 0.4rem; }
.action-btn {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0.55rem 0.95rem;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.action-btn.ghost {
  background: #1a2430;
  border-color: var(--line);
  color: var(--text);
}
#c {
  width: min(1100px, 100%);
  height: auto;
  background: #0e141c;
  border-radius: 12px;
  border: 1px solid #2a3544;
  outline: none;
  touch-action: none;
  display: block;
}
.hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0.55rem 0 0;
  text-align: center;
  max-width: 36rem;
  line-height: 1.4;
  padding: 0 0.25rem;
}
.difficulty {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.difficulty span { margin-right: 0.15rem; color: var(--muted); font-size: 0.85rem; }
.difficulty button {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  padding: 0.5rem 0.75rem;
  min-height: 44px;
  min-width: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #1a2430;
  color: var(--muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}
.difficulty button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Round clock and one settings entry for input and audio. */
.round-clock {
  width: min(1100px, 100%);
  margin: 0.15rem 0 0.7rem;
}
.clock-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.09em;
}
#time-left { font-size: 0.9rem; font-variant-numeric: tabular-nums; letter-spacing: 0; }
#time-progress {
  display: block;
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 7px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: var(--line);
  accent-color: var(--accent);
}
#time-progress::-webkit-progress-bar { background: var(--line); border-radius: 999px; }
#time-progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
#time-progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
.round-clock[data-urgent="true"] #time-left { color: #ba5333; }
.round-clock[data-urgent="true"] #time-progress { accent-color: #ba5333; }
.round-clock[data-urgent="true"] #time-progress::-webkit-progress-value { background: #ba5333; }
.round-clock[data-urgent="true"] #time-progress::-moz-progress-bar { background: #ba5333; }
#c[data-controls="drag"] { cursor: crosshair; }
#c:focus-visible, .action-btn:focus-visible, select:focus-visible, input:focus-visible {
  outline: 3px solid var(--you);
  outline-offset: 3px;
}
.game-settings {
  width: min(420px, calc(100% - 2rem));
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
}
.game-settings::backdrop { background: rgba(8, 20, 17, 0.55); }
.settings-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.7rem; }
.settings-heading h2 { margin: 0; font-size: 1.25rem; }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
  border-top: 1px solid var(--line);
  font-size: 0.95rem;
  cursor: pointer;
}
.setting-row small { display: block; margin-top: 0.25rem; color: var(--muted); font-size: 0.75rem; }
.setting-row select {
  max-width: 55%;
  min-height: 44px;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
}
.setting-row input { width: 22px; height: 22px; margin: 0 0.6rem; accent-color: var(--accent); flex-shrink: 0; }
.setting-row input[type="number"] {
  width: 5rem;
  height: 44px;
  box-sizing: border-box;
  margin: 0;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.settings-note { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.75rem; line-height: 1.5; }

@media (max-width: 720px), (pointer: coarse) {
  #c { border-radius: 10px; }
  .hint { font-size: 0.75rem; }
  body { padding-top: 0.55rem; }
}

@media (max-width: 420px) {
  .toolbar { gap: 0.4rem; }
  .difficulty button { padding: 0.45rem 0.55rem; font-size: 0.8rem; }
  .action-btn { padding: 0.5rem 0.75rem; font-size: 0.85rem; }
}
