/* =====================================================================
   Shaft — fixed "torch-lit mine" theme.
   Like Super Plumber, Tunnel Flyer, Flappy Bird & Breakout, this page
   deliberately ignores the center's light/dark mode and its shared glass
   chrome (no glass.css is loaded); every color is hardcoded, taken from
   the game's own canvas palette: deep earth browns, torch amber, hazard
   red, dirt and bone.
   ===================================================================== */
:root {
  --ns-bg1:    #171320;   /* canvas depths */
  --ns-bg2:    #1d1512;
  --ns-bg3:    #120c0a;
  --ns-amber:  #f0a90a;   /* torch amber */
  --ns-amber2: #ffc84a;
  --ns-hazard: #ff5a4e;   /* the crushing ceiling */
  --ns-dirt:   #8a6c52;   /* slab brown */
  --ns-teal:   #35b39e;   /* bounce-pad teal */
  --ns-bone:   #e9dfd2;   /* text */
  --ns-muted:  #b39a7f;
  --ns-line:   rgba(240, 169, 10, .45);
}

html, body { height: 100%; }
body.ns-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* iOS: touch-action doesn't inherit — every directly-tapped element needs
     its own opt-out of double-tap zoom (see #screen / .ns-overlay below). */
  touch-action: manipulation;
  background: linear-gradient(180deg, var(--ns-bg1) 0%, var(--ns-bg2) 55%, var(--ns-bg3) 100%);
  color: var(--ns-bone);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.ns-page *,
body.ns-page *::before,
body.ns-page *::after { box-sizing: border-box; }

/* ---------- App frame ---------- */
.c-app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.c-bar {
  flex: none;
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px 18px;
  flex-wrap: wrap;
  padding: 12px clamp(12px, 3vw, 28px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(0, 0, 0, .38);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  z-index: 20;
}
/* hazard stripes along the bottom edge — it's coming down, remember */
.c-bar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -5px;
  height: 5px;
  background: repeating-linear-gradient(45deg,
      var(--ns-hazard) 0 10px, #1a1116 10px 20px);
  opacity: .9;
}
.c-bar__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.c-bar__brand svg { filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .45)); }
.c-bar__title {
  margin: 0;
  font-size: clamp(19px, 3.4vw, 26px);
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  white-space: nowrap;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, .6), 0 0 18px rgba(240, 169, 10, .45);
}
.c-bar__stats { display: flex; align-items: center; gap: 8px 18px; margin-left: auto; }
.c-bar__controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stat { font-size: 14px; font-weight: 700; letter-spacing: .03em; white-space: nowrap; color: var(--ns-muted); }
.stat b { color: var(--ns-amber2); font-size: 16px; text-shadow: 0 0 10px rgba(255, 200, 74, .35); }

/* ---------- Buttons (chunky arcade style, mario-like) ---------- */
.c-btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-block;
  padding: 9px 16px;
  border-radius: 12px;
  border: 2px solid rgba(233, 223, 210, .5);
  background: rgba(255, 255, 255, .08);
  color: var(--ns-bone);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .5);
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
}
.c-btn:hover { background: rgba(240, 169, 10, .18); border-color: var(--ns-amber); }
.c-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .5); }
.c-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(240, 169, 10, .55); }
.c-btn--primary {
  background: linear-gradient(140deg, var(--ns-amber2), var(--ns-amber) 55%, #b57a05);
  border-color: #4a2f04;
  color: #3a2400;
}
.c-btn--primary:hover {
  /* Re-declare the gradient: `.c-btn:hover` (higher specificity) otherwise
     replaces it with the translucent amber wash, leaving the dark brown
     label on a near-black see-through background — unreadable. */
  background: linear-gradient(140deg, #ffd76a, var(--ns-amber2) 55%, var(--ns-amber));
  border-color: #4a2f04;
  color: #3a2400;
}

/* ---------- Table / stage ---------- */
.c-table {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 2.4vh, 22px);
}
.ns-stage {
  position: relative;
  /* ~19:31 portrait; capped by viewport height minus the chrome, no fixed
     floor — small screens just get a smaller board (no horizontal scroll). */
  width: min(92vw, calc((100vh - 170px) * 0.6129), 400px);
  aspect-ratio: 380 / 620;
  border-radius: 14px;
  overflow: hidden;
  background: #120c0a;
  border: 3px solid rgba(138, 108, 82, .8);
  box-shadow: 0 10px 0 rgba(0, 0, 0, .4), 0 22px 48px rgba(0, 0, 0, .6),
              0 0 30px rgba(240, 169, 10, .18);
  touch-action: none;               /* left/right halves are the controller */
  user-select: none;
  -webkit-user-select: none;
}
#screen {
  display: block; width: 100%; height: 100%;
  /* The canvas is the real tap target (its halves are the controller) and
     Safari iOS judges double-tap zoom on the directly-hit child, not the
     stage — so it needs the stage's own `none`, not just an ancestor's. */
  touch-action: none;
}

/* ---------- Ready / paused / game-over overlays ---------- */
.ns-overlay {
  touch-action: manipulation;
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(10, 7, 5, .5);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  touch-action: manipulation;    /* ready/paused/over screens are tapped too */
}
.ns-overlay[hidden] { display: none; }   /* don't let flex beat [hidden] */
.ns-card {
  touch-action: manipulation;
  max-width: 300px;
  text-align: center;
  padding: 22px 24px 20px;
  border-radius: 16px;
  background: linear-gradient(160deg, #3a2c20, #241a12);
  border: 2px solid var(--ns-line);
  box-shadow: 0 8px 0 rgba(0, 0, 0, .4), 0 22px 50px rgba(0, 0, 0, .55);
  color: var(--ns-bone);
  animation: nsPop .3s ease;
  touch-action: manipulation;    /* the card body is a tap surface too */
}
@keyframes nsPop { from { transform: scale(.88); opacity: 0; } }
.ns-card__big { font-size: 40px; line-height: 1.1; }
.ns-card h2 {
  margin: 6px 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, .55);
}
.ns-card p { margin: 0 0 14px; color: var(--ns-muted); font-size: 13.5px; line-height: 1.55; }
.ns-card p b { color: var(--ns-amber2); }
.ns-card .c-btn { font-size: 14px; }
.ns-card kbd, .c-modal kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin: 0 1px;
  font: 700 12px/1.5 ui-monospace, "Segoe UI", monospace;
  text-align: center;
  color: #241a12;
  background: #e5dccb;
  border-radius: 6px;
  border-bottom: 2px solid rgba(0, 0, 0, .45);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .4);
}
.c-win__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Rules modal ---------- */
.c-modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.c-modal[hidden] { display: none; }
.c-modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(8, 5, 4, .7);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.c-modal__panel {
  position: relative;
  width: min(92vw, 470px);
  max-height: 86vh;
  overflow: auto;
  background: linear-gradient(160deg, #3a2c20, #1e1510);
  color: var(--ns-bone);
  border-radius: 16px;
  border: 2px solid var(--ns-line);
  box-shadow: 0 8px 0 rgba(0, 0, 0, .45), 0 24px 60px rgba(0, 0, 0, .65);
}
.c-modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(240, 169, 10, .3);
}
.c-modal__head h2 {
  margin: 0; font-size: 18px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .04em;
  color: #fff; text-shadow: 2px 2px 0 rgba(0, 0, 0, .5);
}
.c-modal__x {
  appearance: none; border: 0; background: none;
  color: var(--ns-bone); font-size: 26px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.c-modal__x:hover { color: var(--ns-amber2); }
.c-modal__body { padding: 8px 20px 4px; font-size: 14px; line-height: 1.55; }
.c-modal__body h3 {
  margin: 16px 0 6px; font-size: 13px;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--ns-amber2);
}
.c-modal__body ul { margin: 0; padding-left: 20px; }
.c-modal__body li { margin: 4px 0; }
.c-modal__body b { color: var(--ns-amber2); }
.c-modal__lead { margin: 12px 0; }
.c-modal__note {
  margin: 14px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(240, 169, 10, .1);
  border: 1px solid rgba(240, 169, 10, .35);
  font-size: 13px;
  color: #cdb897;
}
.c-modal__foot { display: flex; justify-content: flex-end; padding: 12px 20px 16px; }

/* ---------- Responsive ---------- */
/* Phones and short windows: tighten the bar's type and padding. The old rule
   pinned it to one row with flex-wrap: nowrap, which starved the control
   group — its buttons then wrapped into a tower taller than the header itself
   while the nowrap title spilled over the score readout. */
@media (max-width: 700px), (max-height: 560px) {
  .c-bar { gap: 5px 12px; padding: 7px clamp(10px, 3vw, 18px); padding-top: max(7px, env(safe-area-inset-top)); }
  .c-bar__brand { gap: 8px; }
  .c-bar__title { font-size: 16px; }
  .c-bar__stats { gap: 4px 12px; margin-left: auto; }
  .stat { font-size: 12px; }
  .stat b { font-size: 13px; }
  .c-btn { padding: 8px 10px; font-size: 12px; }
  .c-bar__controls { gap: 6px; }
  .c-bar__controls .c-btn { padding: 9px 10px; white-space: nowrap; }
}
/* Narrow screens only: the buttons drop to a row of their own and split it
   evenly into full-width thumb targets. A landscape phone still has the width
   for one compact row, so it keeps the shorter header. */
@media (max-width: 700px) {
  .c-bar__controls { flex: 1 1 100%; flex-wrap: nowrap; }
  .c-bar__controls .c-btn { flex: 1 1 auto; min-width: 0; padding: 9px 6px; overflow: hidden; text-overflow: ellipsis; }
}
/* Smallest phones: four buttons no longer fit side by side, and letting them
   wrap would double the header's height again — so the labels scale down with
   the viewport instead of stacking or clipping. */
@media (max-width: 380px) {
  .c-bar { gap: 5px 8px; }
  .c-bar__title { font-size: 15px; }
  .stat { font-size: 11px; }
  .stat b { font-size: 12px; }
  .c-bar__controls { gap: 4px; }
  .c-bar__controls .c-btn { font-size: clamp(10px, 3.2vw, 12px); padding: 9px 4px; letter-spacing: .01em; }
}

@media (prefers-reduced-motion: reduce) {
  .c-btn, .ns-card { transition: none; animation: none; }
}
