:root {
  --pitch-1: #0d4a2b;
  --pitch-2: #0b4126;
  --night: #07291a;
  --chalk: #f4f7f2;
  --chalk-dim: #b9cdbf;
  --line: rgba(244, 247, 242, .18);
  --gold: #ffcf3f;
  --good: #35d07f;
  --bad: #ff3b3b;
  --t100: #35d07f;
  --t60: #b6e04a;
  --t40: #ffcf3f;
  --t20: #ff9440;
  --display: 'Barlow Condensed', 'Arial Narrow', Impact, sans-serif;
  --body: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --gutter: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body {
  background: var(--night);
  background-image: repeating-linear-gradient(180deg, var(--pitch-1) 0 64px, var(--pitch-2) 64px 128px);
  color: var(--chalk);
  font-family: var(--body);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.screen {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) var(--gutter) calc(env(safe-area-inset-bottom) + 14px);
}

h1, h2, h3, .btn, output, .eyebrow { font-family: var(--display); }

.eyebrow {
  margin: 0;
  color: var(--gold);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.btn {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 15px 18px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s ease;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible, .card:focus-visible, input:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn.primary { background: var(--gold); color: #1c1600; }
.btn.small { width: auto; padding: 10px 20px; font-size: 22px; background: var(--chalk); color: #10231a; }

/* ---------- start ---------- */
.start { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.start h1 { margin: 2px 0 8px; font-size: clamp(68px, 22vw, 104px); line-height: .86; font-weight: 800; text-transform: uppercase; }
.start h1 span { color: var(--gold); }
.lede { margin: 0; font-size: 18px; line-height: 1.35; color: var(--chalk-dim); }

.tiers { width: 100%; border-collapse: collapse; border-top: 2px solid var(--chalk); border-bottom: 2px solid var(--chalk); }
.tiers tr + tr { border-top: 1px solid var(--line); }
.tiers th { text-align: left; padding: 7px 0; font-weight: 500; }
.tiers td { text-align: right; font-family: var(--display); font-size: 25px; font-weight: 800; padding: 3px 0; }
.t100 { color: var(--t100); } .t60 { color: var(--t60); } .t40 { color: var(--t40); } .t20 { color: var(--t20); }
.t0 { color: var(--bad); font-size: 21px !important; }

.rule { display: flex; align-items: center; gap: 10px; margin: 0; line-height: 1.3; font-size: 15px; }
.mini { width: 26px; height: 26px; flex: none; }
.best { margin: 0; text-align: center; color: var(--gold); font-weight: 700; }
.credits-link { display: block; text-align: center; color: var(--chalk-dim); font-size: 14px; padding: 4px; }

/* ---------- play ---------- */
.play {
  position: fixed;
  inset: 0;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 8px;
  padding-top: calc(env(safe-area-inset-top) + 10px);
  overflow: hidden;
}

.hud { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.strikes { display: flex; gap: 6px; }
.strike { position: relative; width: clamp(34px, 10.5vw, 44px); aspect-ratio: 1; }
.strike svg { display: block; width: 100%; height: 100%; }
.strike .x { position: absolute; inset: 0; opacity: 0; transform: scale(2); }
.strike.hit .ball-img { opacity: .72; }
.strike.hit .x { opacity: 1; transform: scale(1); transition: transform .22s cubic-bezier(.2, 1.6, .4, 1), opacity .1s; }

.score-box { text-align: right; line-height: 1; }
.score-box .label { display: block; font-size: 12px; color: var(--chalk-dim); text-transform: uppercase; letter-spacing: .08em; }
.score-box output { font-size: 36px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }

.clock-track { position: relative; height: 12px; border-radius: 6px; background: rgba(0, 0, 0, .4); overflow: hidden; }
.clock-fill { position: absolute; inset: 0; transform-origin: left; background: var(--t100); }
.clock-track i { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(0, 0, 0, .55); }
.clock-read { display: flex; justify-content: space-between; margin-top: 3px; font-family: var(--display); font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

.player-name {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 2.0em;
  margin: 0;
  text-align: center;
  font-size: clamp(32px, 10.5vw, 46px);
  font-weight: 800;
  line-height: .98;
  text-transform: uppercase;
}

/* Cards stay close to 4:5 so faces aren't sliced on tall phones, and shrink to fit on short ones. */
.cards {
  --card-w: calc((min(100vw, 480px) - 2 * var(--gutter) - 10px) / 2);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: min(calc(var(--card-w) * 1.25), calc((100dvh - 232px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) / 2));
  align-content: center;
  gap: 10px;
  min-height: 0;
}

.card {
  position: relative;
  padding: 0;
  border: 4px solid var(--chalk);
  border-radius: 14px;
  background: #1c3a2a;
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 0;
  color: inherit;
  font: inherit;
  transition: transform .08s ease;
}
.card:active:not(:disabled) { transform: scale(.97); }
.card:disabled { cursor: default; }
.card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.card .caption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 16px 6px 5px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .9) 55%);
  color: #fff;
  font-family: var(--display);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  opacity: 0;
}
.cards.revealed .caption { opacity: 1; }
.cards.revealed .card:not(.right):not(.wrong) img { filter: grayscale(.8) brightness(.6); }
.card.right { border-color: var(--good); box-shadow: 0 0 0 3px var(--good); }
.card.wrong { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.flash {
  position: absolute;
  top: 46%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 6px 20px;
  border-radius: 10px;
  font-family: var(--display);
  font-size: 54px;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}
.flash.show { animation: pop .95s ease-out forwards; }
.flash.good { background: var(--good); color: #052414; }
.flash.bad { background: var(--bad); color: #fff; }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  30%, 75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

.loading { position: absolute; top: 55%; left: 0; right: 0; text-align: center; color: var(--chalk-dim); }

/* ---------- game over ---------- */
.over { display: flex; flex-direction: column; gap: 18px; text-align: left; padding-bottom: calc(env(safe-area-inset-bottom) + 28px); }
.over h3 { margin: 0 0 8px; font-size: 24px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; border-bottom: 2px solid var(--chalk); padding-bottom: 4px; }
.final { display: flex; align-items: baseline; gap: 10px; margin-top: -14px; }
.final output { font-size: 104px; font-weight: 800; line-height: 1; color: var(--gold); font-variant-numeric: tabular-nums; }
.final span { font-family: var(--display); font-size: 28px; font-weight: 700; }

.name-form label { display: block; margin-bottom: 6px; font-weight: 700; }
.name-row { display: flex; gap: 8px; }
.name-row input { flex: 1; min-width: 0; border: 0; border-radius: 12px; padding: 12px 14px; font: 500 18px var(--body); background: var(--chalk); color: #10231a; }
.saved-note { margin: 0; color: var(--good); font-weight: 700; }
.form-error { margin: 8px 0 0; color: #ffb4b4; font-weight: 700; }
.board-status { margin: 0; color: var(--chalk-dim); }
.btn:disabled { opacity: .6; cursor: default; }

.board ol { list-style: none; margin: 0; padding: 0; }
.board li { display: grid; grid-template-columns: 28px 1fr auto; padding: 7px 4px; border-bottom: 1px solid var(--line); align-items: baseline; }
.board li.me { background: rgba(255, 207, 63, .16); border-radius: 6px; font-weight: 700; }
.board .rank { color: var(--chalk-dim); }
.board .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 10px; }
.board .pts { font-family: var(--display); font-size: 22px; font-weight: 800; color: var(--gold); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 8px; margin: 0; }
.stats div { min-width: 0; display: flex; flex-direction: column-reverse; justify-content: flex-end; }
.stats dd { margin: 0; font-family: var(--display); font-size: 36px; font-weight: 800; line-height: 1; }
.stats dt { font-size: 13px; color: var(--chalk-dim); margin-top: 2px; }

.speed { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.speed div { padding: 8px 2px; border-radius: 10px; text-align: center; background: rgba(0, 0, 0, .28); }
.speed b { display: block; font-family: var(--display); font-size: 32px; line-height: 1; }
.speed span { font-size: 13px; }

.missed { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.missed li { display: flex; align-items: center; gap: 12px; }
.thumb { width: 52px; height: 52px; border-radius: 8px; overflow: hidden; flex: none; background: #1c3a2a; }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.missed .n { font-weight: 700; }
.missed .why { display: block; font-size: 13px; color: var(--chalk-dim); font-weight: 500; }

/* short phones: tighten up so all four cards stay comfortably large */
@media (max-height: 640px) {
  .player-name { font-size: 30px; }
  .clock-read { font-size: 17px; }
  .score-box output { font-size: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  .card.wrong { animation: none; }
  .strike.hit .x { transition: none; }
}
