/* `hidden` is only a UA stylesheet rule, so any author rule that sets `display`
   silently outranks it. One !important here keeps the attribute authoritative
   for every panel in the game. */
[hidden] { display: none !important; }

*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #0b120f;
  --bg-2: #121c17;
  --ink: #e9f0ea;
  --muted: #93a89b;
  --line: rgba(255, 255, 255, 0.10);
  --accent: #7ee081;
  --warn: #f0cc5c;
  --radius: 14px;
  color-scheme: dark;
}

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 700px at 50% -12%, #1b2c22 0%, transparent 62%),
    var(--bg);
  color: var(--ink);
  font: 500 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.shell {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: clamp(8px, 1.6vmin, 18px);
  padding-bottom: max(clamp(8px, 1.6vmin, 18px), env(safe-area-inset-bottom));
}

/* ---- header ------------------------------------------------------------- */

.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px 20px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.055), rgba(255,255,255,0.02));
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.brand {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.mark { font-size: 19px; }

.stats {
  margin: 0;
  display: flex;
  gap: 6px;
  flex: 1 1 auto;
  justify-content: center;
  flex-wrap: wrap;
}
.stat {
  min-width: 68px;
  padding: 4px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  text-align: center;
}
.stat dt {
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat dd {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
#stat-total { color: var(--accent); }

.tools { display: flex; gap: 8px; }

button {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 13px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
button:hover { background: rgba(255, 255, 255, 0.13); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary {
  background: var(--accent);
  border-color: transparent;
  color: #0a1a0f;
  padding: 10px 22px;
  font-size: 15px;
}
button.primary:hover { background: #96eda1; }

/* ---- stage -------------------------------------------------------------- */

/* The wrap is the measuring box; the stage takes the largest 4:3 rectangle
   that fits inside it. Sizing both axes explicitly (rather than leaning on
   aspect-ratio plus a max-*) keeps the ratio exact under every constraint. */
.stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage {
  position: relative;
  width: min(100cqw, calc(100cqh * 16 / 10));
  height: min(100cqh, calc(100cqw * 10 / 16));
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--line);
  /* The stage is its own container, so overlay chrome scales with the *board*
     rather than with the viewport. On a phone in portrait the board is a small
     strip of a tall screen, and vw/vh units would size the HUD for the screen
     and swallow the course. */
  container-type: size;
  background: #9fc3dd;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* the board owns drags; the page must not pan or zoom */
  cursor: crosshair;
}

/* Power meter. It lives inside the stage, so it is sized in container units
   and stays proportional to the board on any screen shape. */
.power {
  position: absolute;
  left: 50%;
  bottom: 14cqh;
  transform: translateX(-50%);
  width: min(46cqw, 260px);
  height: clamp(6px, 1.8cqh, 11px);
  padding: 2px;
  border-radius: 999px;
  background: rgba(6, 14, 10, 0.55);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
  pointer-events: none;
}
.power-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 60ms linear;
}
.power-fill[data-level="mid"] { background: var(--warn); }
.power-fill[data-level="high"] { background: #f07a63; }
#board:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.hint, .toast {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  max-width: 88cqw;
  text-align: center;
  pointer-events: none;
  font-size: clamp(10px, 3.1cqh, 14px);
}

.hint {
  bottom: 2.4cqh;
  color: rgba(255, 255, 255, 0.78);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.75);
}

.toast {
  top: 3cqh;
  padding: 0.9cqh 2.4cqw;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: #0d1a11;
  background: rgba(240, 248, 240, 0.94);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 4cqh 4cqw;
  background: rgba(6, 12, 9, 0.72);
  backdrop-filter: blur(3px);
  animation: fade 180ms ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.card {
  width: min(88cqw, 340px);
  max-height: 92cqh;
  overflow: auto;
  text-align: center;
  padding: clamp(14px, 4cqh, 26px) clamp(14px, 4cqw, 26px);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #17241d, #101a15);
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}
.card.wide { width: min(94cqw, 430px); }
.card h2 {
  margin: 0 0 4px;
  font-size: clamp(17px, 5.4cqh, 26px);
  color: var(--accent);
}
.card p { margin: 0 0 10px; color: var(--muted); font-size: clamp(12px, 3.4cqh, 15px); }
.card p.muted { margin: 10px 0 12px; }

.tablewrap { overflow-x: auto; margin: 2px -4px 0; padding: 0 4px 4px; }
.scorecard {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(11px, 3.1cqh, 14px);
  font-variant-numeric: tabular-nums;
}
.scorecard th, .scorecard td {
  padding: 5px 3px;
  text-align: center;
  font-weight: 700;
}
.scorecard .nm { text-align: left; padding-right: 8px; color: var(--muted); font-weight: 600; }
.scorecard thead th { color: var(--muted); font-weight: 600; }
.scorecard thead th.nm, .scorecard thead th.tot { font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.06em; }
.scorecard tbody tr { border-top: 1px solid var(--line); }
.scorecard tbody tr.you td { font-size: 1.1em; }
.scorecard .tot { border-left: 1px solid var(--line); padding-left: 8px; }
.scorecard td.under { color: var(--accent); }
.scorecard td.over { color: var(--warn); }

/* ---- footer ------------------------------------------------------------- */

.legend {
  flex: 0 0 auto;
  display: flex;
  gap: 6px 18px;
  flex-wrap: wrap;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
}
kbd {
  font: inherit;
  font-size: 11px;
  padding: 1px 6px;
  margin-right: 3px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
}
.rotate-note { display: none; color: var(--warn); }

/* Media queries read the viewport, which is the right question for "what kind
   of device is this?" — as opposed to "how big is the board?" above. */
@media (max-width: 720px) {
  .brand { font-size: 15px; }
  .stat { min-width: 58px; padding: 3px 8px; }
  .stat dd { font-size: 16px; }
  .only-wide { display: none; }
}
@media (max-width: 480px) {
  .bar { gap: 8px 10px; padding: 8px 10px; }
  .tools button { padding: 6px 10px; font-size: 12px; }
  .legend { font-size: 11px; gap: 4px 12px; }
}
@media (orientation: portrait) and (pointer: coarse) {
  .rotate-note { display: inline; }
}
/* A 16:10 board is a thin strip on a portrait phone. Squaring it up roughly
   doubles the playing area; the camera reframes itself from the new aspect. */
@media (orientation: portrait) and (max-width: 760px) {
  .stage {
    width: min(100cqw, 100cqh);
    height: min(100cqh, 100cqw);
  }
}
/* Keyboard shortcuts are noise on a device without a keyboard. */
@media (pointer: coarse) and (hover: none) {
  .legend .key-only { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .overlay { animation: none; }
  button { transition: none; }
}
