:root {
  --ink: #0b1510;
  --field: #0f1d15;
  --field-2: #15281c;
  --chalk: #f3f6ee;
  --chalk-dim: #b9c6b8;
  --line: rgba(243, 246, 238, 0.14);
  --gold: #ffc61a;
  --lime: #c6ff3d;
  --sky: #4fc3ff;
  --red: #ff5a4e;
  --accent: var(--gold);
  --display: 'Archivo', system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}
body[data-game="soccer"] { --accent: var(--lime); }
body[data-game="paper"] { --accent: var(--sky); }

* { box-sizing: border-box; }
html, body { margin: 0; }
html { background: var(--field); }
body {
  min-height: 100vh;
  color: var(--chalk);
  font-family: var(--display);
  font-stretch: 100%;
  background: var(--field);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

/* ---------- start screen ---------- */
#menu {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(28px + var(--safe-top)) 16px calc(28px + var(--safe-bot));
}
.brand { position: relative; padding: 8px 0 22px; }
/* yard lines behind the title only */
.brand::before { content: ''; position: absolute; inset: -40px -16px 0; z-index: -1; pointer-events: none; background: repeating-linear-gradient(180deg, transparent 0 58px, var(--line) 58px 60px); -webkit-mask-image: linear-gradient(180deg, #000 40%, transparent); mask-image: linear-gradient(180deg, #000 40%, transparent); }
#menu { position: relative; z-index: 0; }
.brand .mark { width: 54px; height: 54px; color: var(--gold); display: block; margin-bottom: 14px; }
.brand h1 {
  margin: 0;
  font-weight: 900;
  font-stretch: 125%;
  font-size: clamp(56px, 17vw, 96px);
  line-height: 0.86;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}
.brand h1::after { content: ''; display: block; width: 72px; height: 6px; background: var(--gold); margin-top: 16px; }
.tag { margin: 14px 0 0; font-size: 18px; line-height: 1.4; color: var(--chalk-dim); max-width: 26ch; }

.mode { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 6px; border-radius: 18px; background: rgba(0, 0, 0, 0.28); border: 1px solid var(--line); }
.mode button {
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  padding: 12px 12px; border-radius: 13px; border: 0; background: transparent;
}
.mode button[aria-checked="true"] { background: var(--chalk); color: var(--ink); }
.mode button.off { opacity: 0.45; }
.mode-title { font-weight: 800; font-size: 16px; }
.mode-sub { font-size: 13px; opacity: 0.75; line-height: 1.3; }
.desk-note { margin: 12px 4px 0; font-size: 14px; line-height: 1.5; color: var(--chalk-dim); }
.desk-note b { color: var(--chalk); word-break: break-all; }

.games { list-style: none; padding: 0; margin: 22px 0 0; display: grid; gap: 14px; }
.card {
  width: 100%; display: grid; grid-template-columns: 96px 1fr; align-items: stretch;
  padding: 0; text-align: left; border: 0; border-radius: 22px; overflow: hidden;
  background: var(--field-2); box-shadow: inset 0 0 0 1px var(--line);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card:active { transform: scale(0.98); }
@media (hover: hover) { .card:hover { box-shadow: inset 0 0 0 2px var(--accent); } }
.card .art { display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 18%, #0a120d); }
.card .art svg { width: 64px; height: 64px; }
.card .txt { display: flex; flex-direction: column; gap: 4px; padding: 16px 16px 15px; min-width: 0; }
.card .name { font-weight: 900; font-stretch: 115%; font-size: 24px; text-transform: uppercase; letter-spacing: 0.01em; color: var(--accent); }
.card .desc { font-size: 15px; line-height: 1.4; color: var(--chalk-dim); }
.card .best { margin-top: 4px; align-self: flex-start; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; padding: 4px 9px; border-radius: 99px; background: rgba(255, 255, 255, 0.08); }

.how { margin-top: 34px; padding-top: 22px; border-top: 1px solid var(--line); }
.how h2 { margin: 0 0 12px; font-weight: 900; font-stretch: 115%; font-size: 20px; text-transform: uppercase; letter-spacing: 0.02em; }
.how ol { margin: 0; padding-left: 22px; display: grid; gap: 10px; }
.how li { font-size: 15px; line-height: 1.5; color: var(--chalk-dim); padding-left: 4px; }
.how li b { color: var(--chalk); }
.safety { margin: 14px 0 0; font-size: 14px; line-height: 1.5; color: var(--chalk-dim); }

.foot { margin-top: 30px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: 14px; }
.foot .engine { flex-basis: 100%; font-size: 12px; color: var(--chalk-dim); line-height: 1.5; }

/* ---------- canvases ---------- */
#ar, #pv { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; z-index: 0; touch-action: none; }

/* ---------- in play ---------- */
#play { position: fixed; inset: 0; z-index: 2; pointer-events: none; user-select: none; -webkit-user-select: none; }
#touch { position: absolute; inset: 0; pointer-events: auto; touch-action: none; }
#play button, #play a { pointer-events: auto; }

.top {
  position: absolute; left: 0; right: 0; top: 0;
  display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 10px;
  padding: calc(12px + var(--safe-top)) 14px 22px;
  background: linear-gradient(180deg, rgba(5, 10, 7, 0.62), rgba(5, 10, 7, 0));
}
.icon-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(6px); }
.icon-btn svg { width: 20px; height: 20px; }
.title { display: flex; flex-direction: column; gap: 6px; min-width: 0; padding-top: 2px; }
#gameName { font-weight: 900; font-stretch: 115%; font-size: 19px; text-transform: uppercase; color: var(--accent); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5); white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; padding: 4px 9px; border-radius: 99px; background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(6px); white-space: nowrap; }
.chip svg { width: 14px; height: 14px; transition: transform 0.3s ease; }
.score { text-align: right; line-height: 0.9; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45); }
#scoreNum { display: block; font-weight: 900; font-stretch: 125%; font-size: 44px; }
.score .lbl { font-size: 12px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.85; }

.pips { position: absolute; top: calc(92px + var(--safe-top)); left: 0; right: 0; display: flex; justify-content: center; gap: 6px; }
.pips span { width: 11px; height: 11px; border-radius: 50%; background: rgba(255, 255, 255, 0.28); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); }
.pips .next { background: var(--chalk); transform: scale(1.15); }
.pips .made { background: var(--accent); }
.pips .miss { background: transparent; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55); }

#toast { position: absolute; left: 16px; right: 16px; top: 30%; text-align: center; opacity: 0; transform: translateY(10px) scale(0.92); transition: opacity 0.18s ease, transform 0.25s cubic-bezier(.2, 1.4, .4, 1); }
#toast.show { opacity: 1; transform: none; }
#toast .big { display: block; font-weight: 900; font-stretch: 125%; font-size: clamp(38px, 12vw, 64px); line-height: 1; text-transform: uppercase; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), 0 6px 24px rgba(0, 0, 0, 0.45); }
#toast.good .big { color: var(--accent); }
#toast.bad .big { color: var(--chalk); font-size: clamp(30px, 9vw, 46px); }
#toast .small { display: block; margin-top: 8px; font-weight: 800; font-size: 17px; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6); }

#coach { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); width: min(300px, calc(100% - 32px)); text-align: center; padding: 18px 16px; border-radius: 20px; background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(8px); }
#coach svg { width: 110px; height: 72px; color: var(--chalk); }
#coach svg rect { animation: sway 1.8s ease-in-out infinite; transform-origin: 60px 40px; }
#coach p { margin: 8px 0 0; font-size: 16px; line-height: 1.4; font-weight: 600; }
@keyframes sway { 0%, 100% { transform: translateX(-22px) rotate(-6deg); } 50% { transform: translateX(22px) rotate(6deg); } }

.bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 30px 14px calc(10px + var(--safe-bot));
  background: linear-gradient(0deg, rgba(5, 10, 7, 0.62), rgba(5, 10, 7, 0));
}
.hint { position: absolute; top: calc(112px + var(--safe-top)); left: 0; right: 0; width: fit-content; max-width: min(34ch, calc(100% - 32px)); margin: 0 auto; padding: 6px 14px; border-radius: 16px; background: rgba(5, 10, 7, 0.5); backdrop-filter: blur(6px); font-size: 15px; font-weight: 700; line-height: 1.35; text-align: center; }
.hint:empty { display: none; }
.flick-cue { position: relative; width: 28px; height: 46px; }
.flick-cue span { position: absolute; left: 7px; bottom: 0; width: 14px; height: 14px; border-radius: 50%; background: var(--chalk); box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.25); animation: flickup 1.4s cubic-bezier(.3, .6, .2, 1) infinite; }
@keyframes flickup { 0% { transform: translateY(0); opacity: 0; } 15% { opacity: 1; } 70% { transform: translateY(-34px); opacity: 0; } 100% { opacity: 0; } }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
/* keep the middle clear: the ball waits there */
#actions { width: 100%; justify-content: space-between; align-items: flex-end; }
#actions .group { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
#actions .group:last-child { align-items: flex-end; }
.place-bar { width: min(420px, 100%); display: grid; gap: 10px; padding: 14px; border-radius: 20px; background: rgba(5, 10, 7, 0.62); backdrop-filter: blur(10px); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14); text-align: center; pointer-events: auto; }
.place-bar p { margin: 0; font-weight: 700; font-size: 16px; }
.place-bar .btn:disabled { opacity: 0.45; }
body.placing .pips, body.placing #flickCue { visibility: hidden; }
#debug { position: fixed; left: 8px; top: calc(140px + var(--safe-top)); z-index: 6; margin: 0; padding: 8px 10px; border-radius: 10px; background: rgba(0, 0, 0, 0.72); color: #c6ff3d; font: 11px/1.45 ui-monospace, Menlo, monospace; pointer-events: none; white-space: pre; }
.pill { border: 0; padding: 10px 16px; border-radius: 99px; font-weight: 800; font-size: 14px; background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(6px); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2); }
.pill.go, .btn.go { background: var(--accent); color: var(--ink); box-shadow: none; }
.play-foot { margin: 2px 0 0; display: flex; gap: 16px; font-size: 12px; font-weight: 600; opacity: 0.9; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7); }

.sheet { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(4, 8, 6, 0.55); backdrop-filter: blur(4px); pointer-events: auto; }
.sheet-card { width: min(380px, 100%); padding: 24px 20px 20px; border-radius: 26px; background: var(--field); box-shadow: inset 0 0 0 1px var(--line), 0 20px 60px rgba(0, 0, 0, 0.5); text-align: center; }
.kicker { margin: 0; font-weight: 800; font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); }
.end-score { margin: 6px 0 4px; font-weight: 900; font-stretch: 125%; font-size: 30px; }
.end-score span { font-size: 72px; line-height: 1; }
.end-line { margin: 0 0 18px; font-size: 16px; line-height: 1.45; color: var(--chalk-dim); }
.sheet-actions { display: grid; gap: 8px; }
.btn { border: 0; padding: 14px 16px; border-radius: 16px; font-weight: 800; font-size: 16px; background: rgba(255, 255, 255, 0.08); }

#loading { position: fixed; inset: 0; z-index: 5; display: grid; place-content: center; justify-items: center; gap: 14px; background: var(--field); font-weight: 700; }
.spin { width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, 0.2); border-top-color: var(--gold); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .flick-cue span, #coach svg rect, .spin { animation-duration: 3s; }
  #toast { transition: opacity 0.2s; transform: none; }
}

@media (min-width: 900px) {
  #menu { max-width: 980px; padding-top: 56px; }
  .games { grid-template-columns: repeat(3, 1fr); }
  .card { grid-template-columns: 1fr; grid-template-rows: 150px 1fr; }
  .card .art svg { width: 96px; height: 96px; }
  .how ol { grid-template-columns: repeat(3, 1fr); gap: 24px; padding-left: 18px; }
  .mode { max-width: 520px; }
}

/* ---------- arcade (no camera) vs AR ---------- */
body.arcade .ar-only, body.ar .arcade-only { display: none !important; }
body.arcade .pips { display: none; }
@media (min-width: 900px) {
  .arcade-games { grid-template-columns: repeat(4, 1fr); }
  .arcade-games .card { grid-template-rows: 130px 1fr; }
  .arcade-games .card .name { font-size: 20px; font-stretch: 105%; }
}
.timer {
  align-self: start; min-width: 64px; padding: 4px 10px 2px; border-radius: 14px; text-align: center;
  font-weight: 900; font-stretch: 125%; font-size: 34px; line-height: 1.05; font-variant-numeric: tabular-nums;
  background: rgba(5, 10, 7, 0.55); backdrop-filter: blur(6px); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}
.timer.urgent { color: var(--red); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
body.arcade .top { grid-template-columns: auto minmax(0, 1fr) auto auto; }
body.arcade #gameName { overflow: hidden; text-overflow: ellipsis; font-size: 17px; }
body.arcade .hint { top: calc(96px + var(--safe-top)); }
#countdown {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-weight: 900; font-stretch: 125%; font-size: clamp(90px, 30vw, 180px); color: var(--chalk);
  text-shadow: 0 6px 30px rgba(0, 0, 0, 0.5); background: rgba(5, 10, 7, 0.25);
}
#countdown span { animation: pop 0.9s ease-out both; }
#countdown span.go { color: var(--accent); }
@keyframes pop { 0% { transform: scale(1.6); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
.end-stats { display: flex; justify-content: center; gap: 18px; margin: 0 0 16px; font-size: 14px; color: var(--chalk-dim); }
.end-stats b { display: block; font-size: 22px; color: var(--chalk); font-stretch: 115%; }
@media (prefers-reduced-motion: reduce) { .timer.urgent { animation: none; } #countdown span { animation-duration: 0.01s; } }
