/* Shell, tokens and shared controls. Room layouts live in rooms.css. */
:root {
  --bg: #FFFDF7;
  --ink: #1F2937;
  --ink-soft: #4B5563;
  --paper: #FFFFFF;
  --line: #E5E7EB;
  --night: #1E293B;
  --red: #EF4444;
  --yellow: #FACC15;
  --blue: #3B82F6;
  --green: #22C55E;
  --orange: #F97316;
  --purple: #A855F7;

  /* Mirrors TUNING.edgeSafePx / targetGapPx / brickMinPx / brickMaxPx. */
  --edge-top: max(24px, env(safe-area-inset-top));
  --edge-right: max(24px, env(safe-area-inset-right));
  --edge-bottom: max(24px, env(safe-area-inset-bottom));
  --edge-left: max(24px, env(safe-area-inset-left));
  --touch-gap: 24px;
  --brick-min: 96px;
  --brick-max: 160px;
  --brick: clamp(var(--brick-min), 13vmin, var(--brick-max));
  --bar: 72px;
  --round: 24px;
  --hold-ms: 3000ms;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Tablet: short side >= TUNING.tabletMinShortSidePx. */
@media (min-width: 600px) and (min-height: 600px) {
  :root { --brick-min: 128px; --bar: 80px; }
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

img, svg { display: block; -webkit-user-drag: none; }

button {
  font: inherit;
  color: inherit;
  margin: 0;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: none;
}

button:focus-visible { outline: 4px solid var(--blue); outline-offset: 4px; }

[hidden] { display: none !important; }

.app { position: fixed; inset: 0; overflow: hidden; }
.stage { position: absolute; inset: 0; }

.room {
  position: absolute;
  inset: 0;
  padding: var(--edge-top) var(--edge-right) var(--edge-bottom) var(--edge-left);
  overflow: hidden;
}

/* Round kid-sized icon button (home, shelf, next). */
.icon-btn {
  display: grid;
  place-items: center;
  width: var(--bar);
  height: var(--bar);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .12);
}
.icon-btn svg { width: 58%; height: 58%; }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, .12); }

/* Adult gate: a quiet lock that needs a 3 s hold, top-right inside the safe band. */
.lock {
  position: absolute;
  top: calc(var(--edge-top) + (var(--bar) - 56px) / 2);
  right: var(--edge-right);
  z-index: 20;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .7);
  color: #9CA3AF;
}
.lock > svg:first-child { width: 26px; height: 26px; }
.lock-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.lock-ring circle {
  fill: none;
  stroke: var(--ink-soft);
  stroke-width: 3;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  stroke-linecap: round;
}
.lock.is-holding .lock-ring circle { stroke-dashoffset: 0; transition: stroke-dashoffset var(--hold-ms) linear; }
.app[data-room="rest"] .lock { background: rgba(255, 255, 255, .12); color: #94A3B8; }

.gate {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: var(--edge-top) var(--edge-right) var(--edge-bottom) var(--edge-left);
  background: rgba(31, 41, 55, .6);
}

/* Adult surfaces (gate card, Parent Panel) share these controls. */
.card {
  width: min(100%, 560px);
  max-height: 100%;
  overflow: auto;
  padding: 24px;
  border-radius: var(--round);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
  touch-action: pan-y;
  -webkit-user-select: text;
  user-select: text;
}

.btn {
  min-height: 52px;
  min-width: 52px;
  padding: 12px 20px;
  border-radius: 16px;
  background: #F3F4F6;
  color: var(--ink);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  touch-action: manipulation;
}
.btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.btn-primary { background: var(--blue); color: var(--paper); }
.btn-danger { background: #FEE2E2; color: #991B1B; }
.btn-danger.is-armed { background: #B91C1C; color: var(--paper); }

/* ?dev=1 → H shows hit areas and snap radii. */
.app.dev-hit [data-hit] { outline: 3px dashed var(--red); outline-offset: 0; }
.app.dev-hit .slot::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--snap-r, 80px) * 2);
  height: calc(var(--snap-r, 80px) * 2);
  border: 2px dashed var(--purple);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.dev-badge {
  position: absolute;
  left: 50%;
  bottom: 4px;
  z-index: 40;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-size: 12px;
  transform: translateX(-50%);
  pointer-events: none;
}

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