/* Device safe-area insets, in CSS pixels. Consume these -- never env() directly.
   Defined at :root so the launcher's device frames can override them to
   simulate a Dynamic Island on desktop, where env() always resolves to 0.

   These defaults assume a cutout and the query below takes it back for screens
   that demonstrably have none, rather than the other way round. A media query a
   browser cannot parse is dropped whole, and a minifier will happily rewrite
   this one into Level 4 range syntax that WebKit below 16.4 rejects -- so the
   failure has to leave a screen with clearance it may not need, never without
   clearance it does. env() cannot be the backstop: a WKWebView embedded as a
   Flutter platform view reports 0 on every edge, so in the app this floor is
   the only thing holding the cutout off.

   59px clears the deepest cutout in the band -- the Island on a 402- and
   440-wide body ends 50.7px down. The ear is the strip beside the cutout, for a
   control that wants the corner rather than a place in the band: put it at
   `top: 8px; left: var(--vo-ear-side)` (or `right:`) and hold it to
   `var(--vo-ear)` wide. Both are worst case across the band: the widest cutout
   is the 171.3px notch on a 390-wide body, and --vo-ear-side clears a 53px
   screen-corner radius at 8px down. Measured off Apple's own framebuffer masks
   and the OS's drawn Island, not a spec sheet. */
:root {
  --vo-safe-top: max(env(safe-area-inset-top, 0px), 59px);
  --vo-safe-right: env(safe-area-inset-right, 0px);
  --vo-safe-bottom: env(safe-area-inset-bottom, 0px);
  --vo-safe-left: env(safe-area-inset-left, 0px);
  --vo-cutout-bottom: 51px;
  --vo-ear-side: 22px;
  --vo-ear: max(0px, calc(50vw - 116px));
}
/* Wider than 1:2 has no cutout to clear: an SE, a tablet, a desktop window.
   501/1000 rather than 1/2 so an 18:9 Android -- exactly 1:2, and routinely
   notched -- keeps the clearance rather than losing it on the boundary. */
@media (min-aspect-ratio: 501 / 1000) {
  :root {
    --vo-safe-top: env(safe-area-inset-top, 0px);
    --vo-cutout-bottom: 0px;
    --vo-ear-side: 0px;
    --vo-ear: 50vw;
  }
}

:root {
  --paper: #f5f2ec;
  --paper-deep: #e9e4d9;
  --ink: #171410;
  --ink-soft: #4a443b;
  --accent: #ff4f8b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: ui-rounded, "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

.game-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.quit-button {
  position: absolute;
  z-index: 5;
  right: calc(var(--vo-safe-right, 0px) + 14px);
  bottom: calc(var(--vo-safe-bottom, 0px) + 14px);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  background: rgba(245, 242, 236, 0.88);
  color: var(--ink);
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.quit-button[hidden] { display: none; }

/* --- overlays ----------------------------------------------------------- */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding:
    calc(var(--vo-safe-top, 0px) + 20px)
    calc(var(--vo-safe-right, 0px) + 20px)
    calc(var(--vo-safe-bottom, 0px) + 20px)
    calc(var(--vo-safe-left, 0px) + 20px);
  background: rgba(245, 242, 236, 0.62);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  z-index: 10;
  touch-action: auto;
}

.overlay[hidden] { display: none; }

.sheet {
  width: min(100%, 380px);
  max-height: 100%;
  overflow-y: auto;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 10px 0 rgba(23, 20, 16, 0.16);
  padding: 26px 24px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.sheet-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.start-sheet h2 {
  font-size: clamp(44px, 14vw, 64px);
  font-weight: 900;
  line-height: 0.92;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  transform: rotate(-2.5deg);
  text-shadow: 4px 4px 0 rgba(23, 20, 16, 0.12);
}

.info-sheet h2, .result-sheet h2 {
  font-size: 30px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: -0.01em;
}

/* --- buttons ------------------------------------------------------------ */

.primary-button, .secondary-button, .text-button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--ink);
}

.primary-button {
  width: 100%;
  padding: 15px 18px;
  font-size: 17px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--paper);
  background: var(--ink);
  border-radius: 999px;
  box-shadow: 0 5px 0 rgba(23, 20, 16, 0.25);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.primary-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(23, 20, 16, 0.25);
}

.secondary-button {
  width: 100%;
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 800;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
}

.secondary-button:active { background: var(--paper-deep); }

.text-button {
  font-size: 13px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  color: var(--ink-soft);
  padding: 6px 8px;
}

.start-footer {
  display: flex;
  gap: 18px;
  justify-content: center;
}

.start-footer [data-originals-quit] { min-height: 44px; }

.difficulty-row,
.level-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: -4px;
}

.difficulty-row > span,
.level-row > span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.difficulty-row .text-button,
.level-row .text-button {
  padding: 4px 8px;
}

.start-best {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  min-height: 1em;
}

.close-button {
  align-self: flex-end;
  width: 34px;
  height: 34px;
  margin: -8px -8px -10px 0;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  color: var(--ink-soft);
  background: none;
  border: none;
  cursor: pointer;
}

/* --- help & results ----------------------------------------------------- */

.rule-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.rule-list div {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.rule-list b {
  flex: 0 0 26px;
  height: 26px;
  display: grid;
  place-items: center;
  font-size: 14px;
  color: var(--paper);
  background: var(--ink);
  border-radius: 50%;
}

.rule-list p { font-size: 14px; line-height: 1.4; color: var(--ink-soft); }
.rule-list em { font-style: normal; font-weight: 800; color: var(--ink); }

.result-stats {
  display: flex;
  gap: 10px;
  width: 100%;
}

.result-stats div {
  flex: 1;
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.result-stats span {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.result-stats strong { font-size: 22px; font-weight: 900; }
