/* ymym — base styles (module F1). Tokens, layout of #app/#game, HUD, touch controls, toasts, curtain, orientation hint.
   Light kid-friendly forest palette. Nunito is self-hosted via /assets/fonts/nunito.css (loaded by the shell). */

:root {
  --font: 'Nunito', 'Segoe UI', Roboto, Arial, sans-serif;
  --c-bg: #f6f3e7;
  --c-bg-2: #fff8e1;
  --c-surface: #ffffff;
  --c-text: #23331f;
  --c-muted: #6b7a63;
  --c-primary: #1b5e20;
  --c-primary-2: #2e7d32;
  --c-accent: #ffb300;
  --c-accent-2: #ff8f00;
  --c-ok: #43a047;
  --c-bad: #e53935;
  --c-info: #1e88e5;
  --c-shadow: rgba(35, 51, 31, 0.18);
  --radius: 16px;
  --radius-s: 10px;
  --shadow: 0 6px 18px var(--c-shadow);
  --target: 48px;                /* minimum interactive target, CSS px (ARCHITECTURE §6.4) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --hud-h: 56px;
}

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

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

body { position: fixed; inset: 0; width: 100%; height: 100%; }

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

/* ---------- layout: DOM hub (#app) over the canvas host (#game) ---------- */

#app {
  position: absolute;
  inset: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

#game {
  position: absolute;
  inset: 0;
  background: #000;
  overflow: hidden;
  z-index: 1;
}

#game canvas {
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  outline: none;
}

/* Layer for HUD / controls / curtain over the canvas (created by app.js as #layer, or any element passed to Hud). */
.layer, #layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
}
.layer > *, #layer > * { pointer-events: auto; }
/* Full-size pass-through containers (HUD, touch controls) must not swallow canvas taps: the ID rule above outranks
   `.hud { pointer-events: none }`, so they are re-declared here with the same specificity. Their children stay `auto`. */
#layer > .hud, .layer > .hud, #layer > .controls, .layer > .controls { pointer-events: none; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--target);
  min-width: var(--target);
  padding: 10px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--c-surface);
  color: var(--c-primary);
  font-weight: 800;
  font-size: 18px;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.btn:active { transform: translateY(2px) scale(0.98); box-shadow: 0 2px 6px var(--c-shadow); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--c-accent); color: #3e2a00; }
.btn-secondary { background: var(--c-primary-2); color: #fff; }

/* ---------- HUD (core/hud.js) ---------- */

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-weight: 800;
}
.hud-top {
  position: absolute;
  top: calc(8px + var(--safe-top));
  left: calc(10px + var(--safe-left));
  right: calc(10px + var(--safe-right));
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--hud-h);
}
.hud-box {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 2px 8px var(--c-shadow);
  font-size: 20px;
  color: var(--c-text);
  white-space: nowrap;
}
.hud-score .hud-icon { color: var(--c-accent-2); }
.hud-score-value.bump { animation: hud-bump 0.35s ease; }
@keyframes hud-bump { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
.hud-progress { flex: 1 1 auto; max-width: 320px; gap: 10px; }
.hud-progress-text { font-size: 15px; color: var(--c-muted); }
.hud-progress-track { flex: 1 1 auto; height: 12px; border-radius: 999px; background: #e3e8dc; overflow: hidden; min-width: 60px; }
.hud-progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--c-ok), var(--c-accent)); border-radius: 999px; transition: width 0.3s ease; }
.hud-lives { margin-left: auto; }
.hud-heart { color: var(--c-bad); font-size: 22px; line-height: 1; }
.hud-heart.empty { color: #d7d7d7; }

.hud-hint {
  position: absolute;
  right: calc(12px + var(--safe-right));
  bottom: calc(14px + var(--safe-bottom));
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  min-width: 56px;
  padding: 8px 18px 8px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--c-accent);
  color: #3e2a00;
  font-weight: 900;
  font-size: 18px;
  box-shadow: var(--shadow);
  animation: hud-hint-in 0.3s ease;
}
.hud-hint:disabled { opacity: 0.6; }
.hud-hint-icon { display: inline-flex; align-items: center; font-size: 24px; line-height: 1; }
@keyframes hud-hint-in { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- toasts ---------- */

.hud-toasts {
  position: absolute;
  left: 50%;
  top: calc(var(--hud-h) + 14px + var(--safe-top));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: min(92vw, 640px);
  pointer-events: none;
}
.hud-toast {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius);
  background: rgba(35, 51, 31, 0.92);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
}
.hud-toast.ok { background: var(--c-ok); }
.hud-toast.bad { background: var(--c-bad); }
.hud-toast.out { animation: toast-out 0.3s ease forwards; }
.hud-toast-icon { display: inline-flex; align-items: center; color: var(--c-accent); }
@keyframes toast-in { from { transform: translateY(-12px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-out { to { transform: translateY(-8px); opacity: 0; } }

/* ---------- touch controls (core/input) ---------- */

.controls { position: absolute; inset: 0; pointer-events: none; }
.controls > * { pointer-events: auto; }

.vjoy {
  position: absolute;
  bottom: calc(24px + var(--safe-bottom));
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  border: 3px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 2px 10px var(--c-shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.vjoy-left { left: calc(24px + var(--safe-left)); }
.vjoy-right { right: calc(24px + var(--safe-right)); }
.vjoy.active { background: rgba(255, 255, 255, 0.4); }
.vjoy-thumb {
  border-radius: 50%;
  background: rgba(255, 179, 0, 0.92);
  box-shadow: 0 2px 6px var(--c-shadow);
  transition: transform 0.05s linear;
  pointer-events: none;
}

.btns {
  position: absolute;
  bottom: calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: row-reverse;
  flex-wrap: wrap-reverse;
  gap: 14px;
  max-width: 45vw;
}
.btns-right { right: calc(24px + var(--safe-right)); justify-content: flex-start; }
.btns-left { left: calc(24px + var(--safe-left)); flex-direction: row; justify-content: flex-start; }
.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 3px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  background: rgba(30, 136, 229, 0.85);
  color: #fff;
  font-size: 26px;
  font-weight: 900;
  box-shadow: 0 2px 10px var(--c-shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  padding: 0;
}
.btn-action.down { transform: scale(0.92); background: rgba(21, 101, 192, 0.95); }
.btn-action:disabled { opacity: 0.45; }
/* Keep the engine hint button clear of the right-hand action cluster */
.btns-right ~ .hud-hint, .hud .hud-hint { bottom: calc(14px + var(--safe-bottom)); }
.controls .btns-right { bottom: calc(84px + var(--safe-bottom)); }

/* ---------- engine curtain & orientation hint ---------- */

.engine-curtain {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(35, 51, 31, 0.72);
  backdrop-filter: blur(2px);
  animation: toast-in 0.2s ease;
}
.engine-curtain-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 28px 36px;
  border-radius: var(--radius);
  background: var(--c-bg-2);
  box-shadow: var(--shadow);
  max-width: min(90vw, 480px);
  text-align: center;
}
.engine-curtain-text { margin: 0; font-size: 24px; font-weight: 800; color: var(--c-text); }
.engine-curtain.wait .engine-curtain-text::after { content: ''; display: block; margin: 16px auto 0; width: 36px; height: 36px; border-radius: 50%; border: 4px solid #e3e8dc; border-top-color: var(--c-accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.orient-hint {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--c-primary);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  padding: 24px;
}
.orient-hint p { margin: 0; }
.orient-hint-icon { font-size: 64px; line-height: 1; animation: rotate-hint 1.6s ease-in-out infinite; }
@keyframes rotate-hint { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(90deg); } }

/* ---------- misc ---------- */

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

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

@media (max-height: 420px) {
  :root { --hud-h: 44px; }
  .hud-box { min-height: 34px; padding: 4px 10px; font-size: 17px; }
  .hud-hint { min-height: 48px; font-size: 16px; }
  .hud-toast { font-size: 16px; padding: 8px 14px; }
}
