/* Layout: one column — top bar, title, racket picker, the court where the racket spins, who serves, the up/down explainer and the history */
:root {
  --bg: #17110e;
  --surface: #241a15;
  --surface-2: #2f231c;
  --line: #4a3a30;
  --accent: #ff6b2c;
  --accent-text: #ff8a55;
  --accent-deep: #b8461c;
  --on-accent: #17110e;
  --focus: #ffbd4a;
  --text: #f7ede1;
  --muted: #b5a191;
  --bust: #c0392b;
  --on-bust: #ffffff;
  --danger-text: #ff9a8f;
  --glow: rgba(255, 107, 44, .16);
  --scrim: rgba(8, 5, 4, .6);
  --shadow: rgba(0, 0, 0, .5);
  --toast-bg: #f3e7cf;
  --toast-ink: #2b1d14;
  --switch-off: #4a3a30;
  --switch-knob: #f7ede1;
  --court: #8a3f22;
  --court-2: #3f1c11;
  --court-line: rgba(255, 238, 220, .72);
  --cap-scrim: rgba(12, 6, 4, .55);
  --cap-glow: rgba(255, 138, 85, .38);
  --display: 'Bagel Fat One', 'Arial Black', system-ui, sans-serif;
  --body: 'Rethink Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { overflow-x: hidden; }
body {
  margin: 0; min-height: 100vh; overflow-x: hidden; overscroll-behavior: none;
  background: radial-gradient(130% 55% at 50% 105%, var(--glow), transparent 62%), var(--bg);
  color: var(--text); font-family: var(--body); font-size: 16px; line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
button:focus-visible, textarea:focus-visible, input:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
#app {
  max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 12px;
}

/* ---------- buttons and controls ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer; width: 100%; min-height: 52px; padding: 0 18px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; font-size: 17px;
}
.btn:active { transform: translateY(2px); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 3px 0 var(--accent-deep); }
.btn.ghost { background: var(--surface); color: var(--text); border: 1.5px solid var(--line); }
.btn.bust { background: var(--bust); color: var(--on-bust); }
.btn.text { background: transparent; color: var(--accent-text); min-height: 44px; }
.btn.big { min-height: 58px; font-family: var(--display); font-weight: 400; font-size: 22px; }
.btn.small { width: auto; min-height: 44px; padding: 0 10px; font-size: 15px; border-radius: 12px; }
.icon-btn { appearance: none; flex: none; width: 46px; height: 46px; border-radius: 14px; cursor: pointer; border: 1.5px solid var(--line); background: var(--surface); color: var(--text); display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; }
.segmented { display: inline-flex; flex: none; gap: 2px; padding: 3px; border-radius: 13px; background: var(--bg); }
.segmented button { appearance: none; border: 0; cursor: pointer; min-height: 44px; padding: 0 12px; border-radius: 10px; background: none; color: var(--muted); font-weight: 700; font-size: 15px; }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--on-accent); }
.segmented.wide { display: flex; width: 100%; }
.segmented.wide button { flex: 1 1 0; min-width: 0; padding: 0 6px; }
.mode-switch { background: var(--surface); }
.switch { appearance: none; position: relative; flex: none; width: 60px; height: 44px; padding: 0; border: 0; background: none; cursor: pointer; }
.switch::before { content: ''; position: absolute; left: 4px; right: 4px; top: 7px; bottom: 7px; border-radius: 999px; background: var(--switch-off); transition: background-color .2s ease; }
.switch[aria-checked="true"]::before { background: var(--accent); }
.switch-knob { position: absolute; left: 7px; top: 10px; width: 24px; height: 24px; border-radius: 50%; background: var(--switch-knob); box-shadow: 0 2px 4px var(--shadow); transition: translate .2s ease; }
.switch[aria-checked="true"] .switch-knob { translate: 22px 0; }

/* ---------- top ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; }
.back-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; color: var(--muted); font-weight: 700; text-decoration: none; }
.title { font-family: var(--display); font-weight: 400; font-size: clamp(38px, 11vw, 52px); line-height: 1; }
.box { background: var(--surface); border-radius: 18px; padding: 14px; display: grid; gap: 12px; min-width: 0; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.box-title { font-weight: 800; font-size: 17px; padding-left: 4px; }
.hint { color: var(--muted); font-size: 14.5px; }

/* ---------- picker ---------- */
.picker { gap: 10px; }
.picked { color: var(--muted); font-weight: 700; font-size: 15px; text-align: right; min-width: 0; overflow-wrap: anywhere; }
.brands button { font-size: 15px; }
.rackets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.racket-card {
  appearance: none; cursor: pointer; min-width: 0; min-height: 152px; padding: 8px 4px 10px; border-radius: 14px;
  border: 2px solid transparent; background: var(--surface-2); color: var(--text);
  display: grid; grid-template-rows: 1fr auto; justify-items: center; align-items: end; gap: 6px;
  transition: border-color .15s ease, background-color .15s ease;
}
.racket-card svg { width: 46px; height: auto; transition: translate .2s cubic-bezier(.2, .9, .3, 1.3); }
.racket-card[aria-checked="true"] { border-color: var(--accent); background: var(--bg); }
.racket-card[aria-checked="true"] svg { translate: 0 -4px; }
.racket-card:disabled { cursor: default; opacity: .6; }
.racket-line { font-weight: 800; font-size: 13px; line-height: 1.15; text-align: center; overflow-wrap: anywhere; }

/* ---------- court ---------- */
.stage {
  position: relative; height: clamp(360px, 58vh, 480px); border-radius: 26px; overflow: hidden;
  background: var(--court-2); touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.court { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-hint {
  position: absolute; left: 50%; bottom: 14px; translate: -50% 0; max-width: calc(100% - 24px);
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px;
  background: var(--surface); color: var(--text); font-weight: 700; font-size: 15px; white-space: nowrap; pointer-events: none;
  box-shadow: 0 6px 18px var(--shadow);
}
.stage-hint svg { width: 22px; height: 22px; flex: none; animation: nudge 2.2s ease-in-out infinite; }
.verdict {
  position: absolute; left: 50%; top: 14px; translate: -50% 0; max-width: calc(100% - 24px); pointer-events: none;
  display: grid; justify-items: center; padding: 8px 26px 10px; border-radius: 22px;
  background: var(--surface); color: var(--text); box-shadow: 0 10px 30px var(--shadow);
}
.verdict:empty { display: none; }
.verdict-big { font-family: var(--display); font-size: 52px; line-height: 1; animation: slam .5s cubic-bezier(.2, .9, .3, 1.4) both; }
.verdict-sub { color: var(--muted); font-weight: 700; font-size: 14.5px; white-space: nowrap; }
.spin-btn { margin-top: -2px; }

/* ---------- who serves ---------- */
.players { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.player { display: grid; gap: 4px; min-width: 0; }
.player-tag { color: var(--muted); font-weight: 700; font-size: 14px; padding-left: 4px; }
.player input {
  width: 100%; min-width: 0; min-height: 48px; padding: 0 12px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: 17px;
}
.player input::placeholder { color: var(--muted); }
.call-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.call-q { font-weight: 800; padding-left: 4px; min-width: 0; overflow-wrap: anywhere; }
.call button { min-width: 72px; }
.outcome { display: grid; gap: 8px; padding: 12px; border-radius: 14px; background: var(--surface-2); animation: deal .36s cubic-bezier(.2, .9, .3, 1) both; }
.outcome-head { font-family: var(--display); font-size: 26px; line-height: 1.1; overflow-wrap: anywhere; }
.outcome-head:focus { outline: none; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  appearance: none; cursor: pointer; flex: 1 1 auto; min-height: 48px; padding: 0 14px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--text); font-weight: 800; font-size: 15px;
}
.choice[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.outcome-line { font-weight: 700; }

/* ---------- explainer ---------- */
.caps { display: flex; justify-content: center; gap: 28px; }
.cap-fig { margin: 0; display: grid; justify-items: center; gap: 6px; }
.cap-fig figcaption { display: grid; justify-items: center; line-height: 1.2; }
.cap-fig strong { font-family: var(--display); font-weight: 400; font-size: 24px; }
.cap-fig span { color: var(--muted); font-size: 14px; font-weight: 600; }

/* ---------- history ---------- */
.hist-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.hist { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 12px 6px 6px; border-radius: 14px; background: var(--surface-2); }
.hist-res { flex: none; min-width: 64px; height: 40px; padding: 0 10px; border-radius: 10px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); font-family: var(--display); font-size: 20px; }
.hist-res[data-result="down"] { background: var(--bg); color: var(--text); box-shadow: inset 0 0 0 1.5px var(--line); }
.hist-main { flex: 1; min-width: 0; display: grid; }
.hist-racket { font-weight: 700; overflow-wrap: anywhere; }
.hist-who { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.hist-time { flex: none; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.hist:first-child { animation: deal .36s cubic-bezier(.2, .9, .3, 1) both; }
@media (min-width: 640px) {
  #app { max-width: 760px; }
  .stage { height: 520px; }
}

/* ---------- sheets, modal, toast ---------- */
.backdrop { position: fixed; inset: 0; z-index: 20; background: var(--scrim); animation: fade .2s ease; }
.sheet {
  position: fixed; z-index: 21; bottom: 0; left: 50%; translate: -50% 0; width: min(100%, 560px); max-height: 86%; overflow-y: auto;
  border-radius: 22px 22px 0 0; background: var(--surface); display: grid; gap: 14px;
  padding-top: 10px; padding-left: max(18px, env(safe-area-inset-left, 0px)); padding-right: max(18px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -10px 40px var(--shadow); animation: rise .25s cubic-bezier(.2, .9, .3, 1);
}
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); justify-self: center; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h3 { font-family: var(--display); font-weight: 400; font-size: 24px; }
.close-btn { appearance: none; border: 0; width: 44px; height: 44px; border-radius: 12px; background: var(--surface-2); color: var(--text); cursor: pointer; display: grid; place-items: center; }
.close-btn svg { width: 18px; height: 18px; }
.menu-list { display: grid; gap: 6px; }
.menu-item {
  appearance: none; border: 0; cursor: pointer; width: 100%; min-height: 54px; padding: 0 14px; border-radius: 14px;
  background: var(--surface-2); color: var(--text); text-align: left; font-weight: 700; font-size: 16.5px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.menu-item.static { cursor: default; padding-block: 8px; }
.menu-item.home { color: var(--accent-text); }
.menu-item.danger { color: var(--danger-text); }
.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: var(--scrim); animation: fade .2s ease; }
.modal {
  position: fixed; z-index: 41; left: 50%; top: 50%; translate: -50% -50%; width: min(calc(100% - 48px), 360px);
  padding: 20px; border-radius: 20px; background: var(--surface); box-shadow: 0 20px 60px var(--shadow);
  display: grid; gap: 10px; animation: pop .2s ease;
}
.modal h3 { font-family: var(--display); font-weight: 400; font-size: 24px; line-height: 1.1; }
.modal p { color: var(--muted); }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.modal-actions .btn { min-height: 48px; font-size: 16px; padding: 0 10px; }
.toast {
  position: fixed; z-index: 30; left: 50%; translate: -50% 0; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: min(calc(100% - 32px), 528px); display: flex; align-items: center; gap: 12px;
  padding: 10px 10px 10px 16px; border-radius: 16px; background: var(--toast-bg); color: var(--toast-ink);
  box-shadow: 0 12px 30px var(--shadow); font-weight: 600; font-size: 15px; min-height: 52px;
}
.toast span { flex: 1; min-width: 0; }
.toast button { appearance: none; border: 0; cursor: pointer; flex: none; min-height: 44px; padding: 0 14px; border-radius: 10px; background: var(--toast-ink); color: var(--toast-bg); font-weight: 800; }

@keyframes nudge { 50% { translate: 6px 0; } }
@keyframes slam { from { scale: 1.6; opacity: 0; } }
@keyframes deal { from { opacity: 0; translate: 0 10px; scale: .97; } }
@keyframes rise { from { translate: -50% 30px; opacity: 0; } to { translate: -50% 0; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; scale: .95; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
