:root {
  --night: #121436;
  --night-2: #1b1f55;
  --night-3: #262b6e;
  --line: #333a86;
  --led: #ffb627;
  --ball: #c8243a;
  --chalk: #eef0ff;
  --muted: #a3a8d6;
  --hit: #2fb36d;
  --near: #e9b92f;
  --miss: #2c3168;
  --dot: "Doto", "Courier New", monospace;
  --body: "Barlow Condensed", "Arial Narrow", sans-serif;
}

* { box-sizing: border-box; min-width: 0; }
html { color-scheme: dark; }
body {
  margin: 0; min-height: 100vh; overflow-x: clip;
  background: linear-gradient(180deg, transparent 65%, rgba(29, 107, 63, .38) 100%), var(--night);
  color: var(--chalk); font-family: var(--body); font-size: 18px; line-height: 1.35;
}
header, main { position: relative; z-index: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button { font-family: inherit; }

/* ---------- scoreboard ---------- */
.board {
  max-width: 1180px; margin: 0 auto; padding: 20px 20px 16px;
  display: grid; grid-template-columns: 1fr auto auto; gap: 32px; align-items: end;
  border-bottom: 2px solid var(--night-3);
}
h1 {
  font-family: var(--dot); font-weight: 900; font-size: clamp(32px, 5vw, 50px);
  line-height: 1; margin: 0 0 12px; color: var(--led);
  text-shadow: 0 0 14px rgba(255, 182, 39, .45);
}
.seg { display: inline-flex; background: var(--night-2); border-radius: 999px; padding: 4px; gap: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); font-weight: 600; font-size: 17px;
  padding: 7px 16px; border-radius: 999px; cursor: pointer; min-height: 38px;
}
.seg button[aria-selected="true"] { background: var(--night-3); color: var(--chalk); }
.seg button span { color: var(--led); }
.pot { display: flex; flex-direction: column; align-items: flex-end; }
.pot-label, .over-label { color: var(--muted); font-size: 15px; }
.pot-value {
  font-family: var(--dot); font-weight: 900; font-size: clamp(50px, 7vw, 76px); line-height: .95;
  color: var(--led); text-shadow: 0 0 18px rgba(255, 182, 39, .55);
  font-variant-numeric: tabular-nums; min-width: 3.2ch; text-align: right;
}
.pot-value.drop { animation: potdrop .5s ease-out; }
@keyframes potdrop { 0% { color: #ff6b5e; transform: translateY(3px); } }
.over { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.balls { display: grid; grid-template-columns: repeat(5, 18px); gap: 6px; list-style: none; margin: 0; padding: 0; }
.balls li {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--night-3); box-shadow: inset 0 0 0 2px #39408a; transition: transform .25s;
}
.balls li.used { background: radial-gradient(circle at 35% 30%, #ff6a7b, var(--ball) 55%, #7c0f1f); box-shadow: none; }
.balls li.used.won { background: radial-gradient(circle at 35% 30%, #7ff0b0, var(--hit) 55%, #136b3b); }
.balls li.next { transform: scale(1.2); box-shadow: inset 0 0 0 2px var(--led); }

/* ---------- guess bar ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 20px 20px 40px; }
.guess-bar { display: flex; gap: 10px; }
.search { position: relative; flex: 1; }
#guessInput {
  width: 100%; height: 56px; padding: 0 18px;
  font: 600 22px var(--body); color: var(--chalk);
  background: var(--night-2); border: 2px solid var(--line); border-radius: 12px;
}
#guessInput::placeholder { color: #7d83bd; }
#guessInput:focus { outline: none; border-color: var(--led); box-shadow: 0 0 0 4px rgba(255, 182, 39, .15); }
#guessInput:disabled { opacity: .5; }
#suggestions {
  position: absolute; z-index: 5; top: 62px; left: 0; right: 0; margin: 0; padding: 6px;
  list-style: none; background: var(--night-2); border: 2px solid var(--line); border-radius: 12px;
  max-height: 360px; overflow-y: auto; box-shadow: 0 18px 40px rgba(0, 0, 0, .5);
}
#suggestions li {
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; font-weight: 600;
}
#suggestions li[aria-selected="true"], #suggestions li:hover { background: var(--night-3); }
#suggestions .chips { justify-content: flex-end; max-width: none; }

.btn {
  font: 600 18px var(--body); color: var(--chalk); cursor: pointer;
  background: var(--night-3); border: 0; border-radius: 12px; padding: 0 18px; min-height: 46px;
}
.btn:focus-visible, .seg button:focus-visible, .hint-card:focus-visible, .link:focus-visible { outline: 3px solid var(--led); outline-offset: 2px; }
.btn-icon { width: 56px; padding: 0; display: grid; place-items: center; }
.btn-icon.muted { color: var(--muted); }
.btn-primary { background: var(--led); color: #1a1300; }
.btn-ghost { background: transparent; color: var(--muted); }

.commentary { margin: 18px 0 14px; min-height: 1.4em; font-size: 21px; font-weight: 500; }
.commentary.flash { animation: flash .6s; }
@keyframes flash { from { color: var(--led); } }

/* ---------- hint cards ---------- */
.hints { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.hint-card {
  text-align: left; border: 2px dashed var(--line); background: transparent; color: var(--muted);
  border-radius: 14px; padding: 12px 16px; min-height: 64px; font-size: 18px; cursor: default;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.hint-card b { font-weight: 700; color: var(--chalk); font-size: 18px; }
.hint-card small { font-size: 15px; }
.hint-card.ready {
  cursor: pointer; border-style: solid; border-color: var(--led); color: var(--led);
  background: rgba(255, 182, 39, .08); animation: hintpulse 2.2s ease-in-out 3;
}
.hint-card.ready b { color: var(--led); }
.hint-card.ready:hover { background: rgba(255, 182, 39, .15); }
.hint-card.open {
  border: 0; background: linear-gradient(135deg, #2b2f78, #222663); color: var(--chalk);
  animation: reveal .5s ease-out;
}
.hint-card.open small { color: var(--led); }
.hint-card.open b { font-size: 20px; }
@keyframes hintpulse { 50% { box-shadow: 0 0 22px rgba(255, 182, 39, .45); } }
@keyframes reveal { 0% { transform: rotateY(90deg); } 100% { transform: none; } }

.legend-row { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; margin: 0 0 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 15px; margin: 0; }
.giveup {
  background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 999px;
  font-size: 16px; font-weight: 600; padding: 6px 16px; min-height: 40px; cursor: pointer; margin-left: auto;
}
.giveup:hover { color: var(--chalk); border-color: var(--muted); }
.btn-danger { background: transparent; color: #ff8a7a; box-shadow: inset 0 0 0 2px #ff8a7a; }
.giveup:focus-visible { outline: 3px solid var(--led); outline-offset: 2px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.sw.hit { background: var(--hit); } .sw.near { background: var(--near); } .sw.miss { background: var(--miss); box-shadow: inset 0 0 0 1px #4a51a0; }

/* ---------- grid ---------- */
.grid-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 6px; }
.grid { border-collapse: separate; border-spacing: 5px; min-width: 1060px; width: 100%; }
.grid th { font-weight: 600; font-size: 15px; color: var(--muted); text-align: center; padding: 0 2px 2px; white-space: nowrap; }
.grid .col-name { text-align: left; }
.grid td { height: 66px; padding: 0; text-align: center; vertical-align: middle; perspective: 600px; }
.grid td.name-cell {
  position: sticky; left: 0; z-index: 2; background: var(--night);
  text-align: left; font-weight: 700; font-size: 19px; min-width: 160px; padding: 0 10px 0 12px;
  border-left: 4px solid var(--team, var(--line)); border-radius: 4px;
}
.name-cell small { display: block; font-weight: 500; font-size: 14px; color: var(--muted); }
.tile {
  height: 100%; min-height: 66px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 8px; padding: 4px 6px; font-weight: 600; font-size: 17px; line-height: 1.1;
  background: var(--miss); color: var(--chalk);
  animation: flip .5s ease-out both; animation-delay: calc(var(--i) * 120ms);
}
.tile { width: 100%; border: 0; font-family: inherit; cursor: pointer; }
.tile:focus-visible { outline: 3px solid var(--led); outline-offset: 2px; }
.tile.hit { background: var(--hit); color: #06210f; }
.tile.near { background: var(--near); color: #2a1f00; }
.tile .arrow { font-size: 14px; display: block; margin-top: 2px; }
.tile .lbl { display: none; }
@keyframes flip {
  0% { transform: rotateX(90deg); filter: brightness(1.6); }
  60% { transform: rotateX(-12deg); }
  100% { transform: none; filter: none; }
}
tr.fresh .name-cell { color: var(--led); }
tr.wrong { animation: shake .45s; animation-delay: 1.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
tr.correct .name-cell { color: var(--hit); }

.chips { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; max-width: 170px; }
.chip {
  font-size: 13px; font-weight: 700; padding: 2px 5px; border-radius: 4px;
  background: var(--team, #444); color: var(--team-ink, #fff);
}
.tile .chip { opacity: .5; }
.tile .chip.match { opacity: 1; box-shadow: 0 0 0 2px #fff; }
.col-teams { min-width: 170px; }

.empty { color: var(--muted); font-size: 18px; max-width: 62ch; margin-top: 6px; }
.footer-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; margin-top: 24px; border-top: 2px solid var(--night-3); padding-top: 12px; }
.link { background: none; border: 0; color: var(--led); font-size: 17px; font-weight: 600; cursor: pointer; padding: 6px 0; min-height: 44px; }
.stats-line { color: var(--muted); font-size: 16px; }
.credits { color: #6f74a8; font-size: 14px; margin-top: 18px; }
.credits a { color: inherit; }

/* ---------- dialogs ---------- */
dialog.end {
  border: 0; border-radius: 18px; padding: 0; max-width: 440px; width: calc(100% - 32px);
  background: var(--night-2); color: var(--chalk); box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}
dialog.end::backdrop { background: rgba(8, 9, 30, .72); }
dialog[open] { animation: rise .35s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.end-inner { padding: 26px 26px 22px; text-align: center; }
.end-photo { margin: 0 auto 10px; }
.end-photo img { width: 120px; height: 120px; object-fit: cover; border-radius: 50%; border: 3px solid var(--led); }
.avatar {
  width: 110px; height: 110px; margin: 0 auto; border-radius: 50%;
  display: grid; place-items: center; font-family: var(--dot); font-weight: 900; font-size: 46px;
  background: var(--team, var(--night-3)); color: var(--team-ink, #fff);
}
.end-verdict { margin: 4px 0 0; color: var(--muted); font-size: 18px; }
.end h2 { font-size: 34px; margin: 2px 0 4px; line-height: 1.05; }
.end-meta { color: var(--muted); margin: 0 0 12px; }
.end-score { font-family: var(--dot); font-weight: 900; font-size: 42px; color: var(--led); margin: 6px 0; }
.end-next { color: var(--muted); font-size: 16px; min-height: 1.2em; }
.end-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.how { text-align: left; }
.how ul { padding-left: 20px; }
.how li { margin: 7px 0; }
.k { padding: 0 6px; border-radius: 4px; }
.k-hit { background: var(--hit); color: #06210f; }
.k-near { background: var(--near); color: #2a1f00; }

.how .yellows { margin: 6px 0 4px; padding-left: 18px; }
.how .yellows li { margin: 4px 0; font-size: 16px; }
.board-inner { text-align: left; }
.board-inner h2 { text-align: center; font-size: 28px; }
.board-list { list-style: none; margin: 12px 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.board-list li { display: grid; grid-template-columns: 2.2em 1fr auto 3.2em; gap: 10px; align-items: baseline; padding: 8px 6px; border-bottom: 1px solid var(--night-3); }
.board-list li.me { background: rgba(255, 182, 39, .1); border-radius: 8px; }
.board-list .rk { color: var(--muted); font-variant-numeric: tabular-nums; }
.board-list .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list .bl { color: var(--muted); font-size: 15px; }
.board-list .pt { font-family: var(--dot); font-weight: 900; color: var(--led); text-align: right; font-size: 22px; }
.board-list .board-empty { display: block; color: var(--muted); border: 0; text-align: center; }
.name-form label { display: block; color: var(--muted); font-size: 15px; margin-bottom: 6px; }
.name-row { display: flex; gap: 8px; }
.name-row input { flex: 1; height: 46px; padding: 0 12px; border-radius: 10px; border: 2px solid var(--line); background: var(--night); color: var(--chalk); font: 600 18px var(--body); }
.name-row input:focus { outline: none; border-color: var(--led); }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; width: 100%; height: 100%; }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 60;
  background: var(--chalk); color: var(--night); font-weight: 700; padding: 10px 18px; border-radius: 10px;
}

/* ---------- phones: each guess becomes a card ---------- */
@media (max-width: 760px) {
  body { font-size: 17px; }
  .board { grid-template-columns: 1fr auto; gap: 14px 16px; padding: 14px 14px 12px; }
  .board-title { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
  h1 { margin: 0; }
  .pot { align-items: flex-start; }
  main { padding: 14px 14px 32px; }
  #guessInput { height: 52px; font-size: 19px; }
  .btn-icon { width: 52px; }
  .commentary { font-size: 19px; margin: 14px 0 12px; }
  .hints { gap: 8px; }
  .hint-card { padding: 10px 12px; font-size: 16px; }
  .hint-card b { font-size: 16px; }
  .hint-card.open b { font-size: 17px; }
  .grid-wrap { overflow: visible; }
  .grid, .grid tbody { display: block; min-width: 0; }
  .grid thead { display: none; }
  .grid tr {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px;
    background: var(--night-2); border-radius: 14px; padding: 8px; margin-bottom: 10px;
  }
  .grid td, .tile { height: auto; min-height: 54px; }
  .grid td.name-cell {
    grid-column: 1 / -1; position: static; background: none; min-width: 0;
    font-size: 19px; padding: 2px 6px 4px 10px; display: flex; align-items: baseline; gap: 8px;
  }
  .name-cell small { display: inline; }
  .grid td.teams-cell, .grid td.years-cell { grid-column: span 2; }
  .tile { font-size: 14px; padding: 4px 3px; border-radius: 7px; }
  .tile .lbl { display: block; font-size: 11px; font-weight: 600; opacity: .75; margin-bottom: 1px; }
  .chips { max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition: none !important; }
}
