:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #22d3ee;
  --accent-ink: #082f3a;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.45);
  --speed: 180ms;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(34, 211, 238, 0.08), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.4;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: var(--text);
  text-shadow: 0 0 12px rgba(34, 211, 238, 0.55);
}

.actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn {
  min-height: 40px;
  min-width: 40px;
  padding: 0 14px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(2, 6, 23, 0.35);
  transition: background var(--speed) ease, border-color var(--speed) ease, transform var(--speed) ease, color var(--speed) ease;
}

.btn:hover {
  background: var(--surface-2);
  border-color: rgba(34, 211, 238, 0.5);
}

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

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.primary:hover {
  background: #67e8f9;
}

.btn.icon {
  padding: 0;
  width: 40px;
  display: inline-grid;
  place-items: center;
}

.btn.icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.btn.lang {
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.i-play,
.is-paused .i-pause,
.i-off,
.is-muted .i-waves {
  display: none;
}

.is-paused .i-play,
.is-muted .i-off {
  display: inline;
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0 8px;
}

.table {
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(3px);
  animation: fade-in 200ms ease;
  overflow-y: auto;
}

.overlay[hidden] {
  display: none;
}

.card {
  width: min(100%, 360px);
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid rgba(34, 211, 238, 0.25);
  box-shadow: var(--shadow), 0 0 30px rgba(34, 211, 238, 0.12);
  text-align: center;
  animation: rise 220ms ease;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1.35rem;
}

/* Two-player mode: a copy of the result, upright for the player at the top. */
.over-top {
  transform: rotate(180deg);
  margin: 0 0 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.over-top[hidden] {
  display: none;
}

.over-top-title {
  margin: 6px 0 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.field {
  margin: 0 0 14px;
}

.field[hidden] {
  display: none;
}

.label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.seg {
  display: flex;
  gap: 6px;
}

.seg .btn {
  flex: 1 1 0;
  padding: 0 8px;
}

.seg .btn[aria-pressed="true"] {
  background: rgba(34, 211, 238, 0.16);
  border-color: var(--accent);
  color: #a5f3fc;
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.25);
}

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

.row .btn {
  flex: 1 1 0;
}

.row .btn[hidden] {
  display: none;
}

.muted {
  color: var(--muted);
}

.small {
  margin: 8px 0 0;
  font-size: 0.85rem;
}

.score-line {
  margin: 0;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.footer {
  padding: 6px 16px max(8px, env(safe-area-inset-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
  display: inline-block;
  padding: 4px 2px;
}

.footer a:hover {
  text-decoration: underline;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes rise {
  from { transform: translateY(8px); opacity: 0; }
}

@media (max-width: 400px) {
  .title {
    font-size: 1.02rem;
  }

  .btn {
    padding: 0 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
