/* Hallmark · component: game court · genre: playful · theme: Mooncake Harvest
 * enrichment: tier-A cached canvas court · tone: playful indoor arena
 * states: default · hover · focus · active · disabled · loading · error · success
 * contrast: pass (46–50)
 * Hallmark · pre-emit critique: P5 H5 E5 S5 R5 V5
 */
:root {
  --color-paper: #f8fbf7;
  --color-paper-muted: #edf5ed;
  --color-ink: #18301f;
  --color-muted: #607267;
  --color-line: #cedbce;
  --color-accent: #aa4512;
  --color-accent-pressed: #84340c;
  --color-success: #2f7d43;
  --color-danger: #b7372f;
  --color-shadow: rgba(76, 42, 18, .16);
  --color-backboard: #a9b9aa;
  --color-stand: #718274;
  --color-rim: #d5432f;
  --color-court-wall: oklch(31% 0.045 148);
  --color-court-wall-deep: oklch(22% 0.035 148);
  --color-court-floor: oklch(58% 0.06 67);
  --color-court-floor-light: oklch(64% 0.055 70);
  --color-court-floor-dark: oklch(39% 0.055 58);
  --color-court-paint: oklch(31% 0.075 37);
  --color-court-line: oklch(96% 0.018 82);
  --color-board-glass: oklch(94% 0.018 180 / .72);
  --color-board-shadow: oklch(16% 0.03 145 / .24);
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-emoji: "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: clip;
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
}

body { overscroll-behavior: none; }
button { font: inherit; }

.game {
  display: grid;
  grid-template-rows: auto minmax(430px, 1fr) auto;
  width: 100%;
  min-height: 100svh;
  padding-top: var(--safe-top);
  user-select: none;
  -webkit-user-select: none;
}

.topbar {
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(54px, .75fr) minmax(84px, 1.15fr) minmax(54px, .75fr) 40px;
  gap: 8px;
  align-items: center;
  min-height: 72px;
  padding: 8px 12px;
  background: var(--color-court-wall-deep);
  color: var(--color-court-line);
}

.hud-score,
.timer,
.record {
  display: grid;
  justify-items: center;
  min-width: 0;
  font-size: 10px;
  line-height: 1;
  text-transform: uppercase;
}

.hud-score {
  align-self: stretch;
  place-content: center;
  border-radius: 8px;
  background: var(--color-court-wall);
}

.timer {
  font-size: 10px;
}
.hud-score strong,
.record strong { margin-top: 5px; font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.timer strong { margin-top: 4px; font-size: 30px; font-weight: 500; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.timer.is-urgent strong { color: var(--color-danger); }

.hud-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--color-stand);
  border-radius: 50%;
  background: var(--color-court-wall);
  color: var(--color-court-line);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
.hud-button:focus-visible,
.share-button:focus-visible,
.primary-button:focus-visible,
.close-button:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 3px; }
.hud-button:hover { background: var(--color-stand); }
.hud-button:active { transform: translateY(1px); }

.court { position: relative; min-height: 0; touch-action: none; overflow: hidden; background: var(--color-court-floor); -webkit-user-select: none; }
#gameCanvas { display: block; width: 100%; height: 100%; touch-action: none; }

.hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  margin: 0;
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--color-court-wall-deep);
  color: var(--color-court-line);
  font-size: 14px;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity .25s ease;
  white-space: nowrap;
}
.hint.is-hidden { opacity: 0; }

.status {
  position: absolute;
  top: 69%;
  left: 50%;
  color: var(--color-success);
  font-size: 20px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
}
.status.show { animation: status-pop .7s ease both; }
.status.miss { color: var(--color-danger); }

.actions {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 12px 18px calc(12px + var(--safe-bottom));
  background: var(--color-paper-muted);
}
.actions p { margin: 0; color: var(--color-muted); font-size: 11px; text-align: center; }

.share-button,
.primary-button {
  min-height: 42px;
  padding: 0 22px;
  border: 0;
  border-radius: 8px;
  background: var(--color-accent);
  color: var(--color-paper);
  font-weight: 650;
  cursor: pointer;
  box-shadow: 0 4px 12px var(--color-shadow);
  white-space: nowrap;
}
.share-button:hover,
.primary-button:hover { background: var(--color-accent-pressed); transform: translateY(-1px); }
.share-button:active,
.primary-button:active { transform: translateY(1px); box-shadow: none; }
.share-button:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
.share-button[data-state="loading"] { background: var(--color-muted); color: var(--color-paper); }
.share-button[data-state="error"] { background: var(--color-danger); color: var(--color-paper); }
.share-button[data-state="success"] { background: var(--color-success); color: var(--color-paper); }

dialog {
  position: fixed;
  inset: 0;
  height: fit-content;
  max-height: min(80vh, 40rem);
  margin: auto;
  width: min(390px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: 12px;
  color: var(--color-ink);
  box-shadow: 0 22px 70px var(--color-shadow);
}
dialog::backdrop { background: var(--color-shadow); }
dialog form { position: relative; padding: 30px; }
dialog h1 { margin: 0 32px 14px 0; font-size: 27px; font-style: normal; letter-spacing: -.03em; overflow-wrap: anywhere; }
dialog p {
  color: var(--color-muted);
  line-height: 1.5;
  text-align: justify;
  text-justify: inter-word;
}
dialog .primary-button { width: 100%; margin-top: 8px; }
.close-button { position: absolute; top: 14px; right: 14px; width: 40px; height: 40px; border: 0; background: transparent; color: var(--color-muted); font-size: 28px; cursor: pointer; }

.time-form { text-align: center; }
.time-form .eyebrow { margin: 0 0 6px; color: var(--color-accent); font-size: 13px; font-weight: 700; letter-spacing: .08em; text-align: center; text-transform: uppercase; }
.time-form h1 { margin: 0 0 18px; }
.time-form .final-result { margin: 0 0 18px; text-align: center; }
.final-result strong { display: block; margin-top: 4px; color: var(--color-accent); font-size: 72px; font-weight: 300; line-height: 1; }

@keyframes status-pop {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(.85); }
  20%, 65% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -14px) scale(.96); }
}

@media (min-width: 700px) {
  body { background: var(--color-paper-muted); }
  .game { max-width: 520px; margin: 0 auto; background: var(--color-paper); box-shadow: 0 0 40px var(--color-shadow); }
}

@media (max-height: 640px) {
  .game { grid-template-rows: auto minmax(360px, 1fr) auto; }
  .topbar { min-height: 64px; padding-top: 8px; }
  .actions p { display: none; }
}

@media (max-width: 370px) {
  .topbar { grid-template-columns: minmax(50px, .75fr) minmax(78px, 1fr) minmax(50px, .75fr) 36px; gap: 5px; padding-inline: 8px; }
  .hud-button { width: 36px; height: 36px; }
  .timer strong { font-size: 27px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
