/* A Nagy Flakon: the global look. Tokens, fonts, buttons, fields, the modal and the toasts.
   Post-apocalyptic dusk: soot, ash and ember orange, with the bottle's clear blue as the second colour.
   Screens: css/meta.css; the run HUD: css/hud.css; touch controls: css/touch.css. */

@font-face { font-family: 'Anton'; src: url('fonts/Anton-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Barlow Condensed'; src: url('fonts/BarlowCondensed-SemiBold.ttf') format('truetype'); font-weight: 400 700; font-display: swap; }
@font-face { font-family: 'Barlow Condensed'; src: url('fonts/BarlowCondensed-ExtraBold.ttf') format('truetype'); font-weight: 800 900; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('fonts/JetBrainsMono.ttf') format('truetype'); font-weight: 100 800; font-display: swap; }

:root {
  /* colour */
  --ember: #ff8a2a;            /* the brand: fire light */
  --ember-deep: #d9581a;
  --ember-ink: #1c0c04;
  --glow: #ffd27a;             /* hot highlights */
  --bottle: #7fd3ff;           /* the PET bottle */
  --cap: #1e6fd9;
  --s950: #0b0807;             /* soot, darkest to lightest */
  --s900: #120d0b;
  --s850: #18120f;
  --s800: #1f1814;
  --s700: #2a211c;
  --s600: #372b24;
  --s500: #4a3c33;
  --s400: #66564b;
  --s300: #8e7d70;
  --s200: #bfae9f;
  --text: #f1e6d8;
  --text-dim: #b9a796;
  --text-faint: #7f6f62;
  --good: #8be35f;
  --good-deep: #3c7a1f;
  --bad: #ff5a3d;
  --bad-deep: #a3220f;
  --warn: #ffb03a;
  --info: #7fd3ff;
  /* type */
  --font-head: 'Anton', Impact, 'Arial Narrow Bold', sans-serif;
  --font-body: 'Barlow Condensed', 'Arial Narrow', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  /* shape */
  --r-s: 3px;
  --r: 6px;
  --r-l: 10px;
  --tap: 44px;
  --panel-bg: rgba(18, 13, 11, 0.9);
  --line: rgba(255, 220, 190, 0.09);
  --line-2: rgba(255, 220, 190, 0.18);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 .9 0 0 0 0 .8 0 0 0 .07 0'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>");
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--s900);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 17px;
  line-height: 1.3;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body { overflow: hidden; overscroll-behavior: none; position: fixed; inset: 0; }

h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 400; letter-spacing: 0.02em; margin: 0; line-height: 1.05; }
p { margin: 0 0 0.6em; }
a { color: var(--ember); }
small { font-size: 0.84em; }
kbd {
  display: inline-block; min-width: 1.5em; padding: 0 0.35em; border-radius: var(--r-s); border: 1px solid var(--line-2);
  border-bottom-width: 2px; background: var(--s800); color: var(--glow); font-family: var(--font-mono); font-size: 0.8em;
  font-weight: 700; text-align: center; line-height: 1.5;
}
.mono, .num { font-family: var(--font-mono); font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--ember); color: var(--ember-ink); }
:focus-visible { outline: 2px solid var(--glow); outline-offset: 2px; }

/* ---------- the canvas and the UI root */
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; background: var(--s950); touch-action: none; }
.nf-stub-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; z-index: 1; }
#ui { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#ui > * { pointer-events: auto; }
#ui > .run-root { position: absolute; inset: 0; pointer-events: none; }
body:not([data-screen='run']) #game { visibility: hidden; }

/* ---------- buttons: stencilled crate lids */
.btn {
  --b-bg: var(--s600);
  --b-fg: var(--text);
  --b-edge: rgba(0, 0, 0, 0.6);
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4em;
  min-height: var(--tap); min-width: var(--tap); padding: 0.35em 1em;
  border: 2px solid rgba(255, 220, 190, 0.12); border-radius: var(--r);
  background: var(--b-bg); color: var(--b-fg);
  font-family: var(--font-body); font-weight: 800; font-size: 1rem; letter-spacing: 0.04em; text-transform: uppercase; line-height: 1.05;
  cursor: pointer; box-shadow: 0 3px 0 var(--b-edge);
  transition: transform 0.08s, box-shadow 0.08s, background 0.12s, filter 0.12s;
  user-select: none; -webkit-user-select: none; touch-action: manipulation; text-align: center;
}
.btn:hover:not(:disabled) { filter: brightness(1.15); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--b-edge); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; filter: saturate(0.4); }
.btn.primary { --b-bg: linear-gradient(180deg, #ffa547, var(--ember-deep)); --b-fg: var(--ember-ink); --b-edge: #6b2a08; border-color: rgba(0, 0, 0, 0.3); text-shadow: 0 1px 0 rgba(255, 220, 160, 0.4); }
.btn.danger { --b-bg: var(--bad-deep); --b-fg: #fff; --b-edge: #4d0f0a; }
.btn.good { --b-bg: var(--good-deep); --b-fg: #fff; --b-edge: #173f14; }
.btn.ghost { --b-bg: transparent; box-shadow: none; border-color: var(--line-2); }
.btn.small { min-height: 36px; padding: 0.25em 0.7em; font-size: 0.9rem; }
.btn.big { min-height: 56px; padding: 0.4em 1.4em; font-size: 1.25rem; }
.btn.icon { padding: 0; width: var(--tap); font-size: 1.1rem; }
@media (pointer: coarse) { .btn.small { min-height: var(--tap); } }

/* a segmented control */
.seg { display: inline-flex; border-radius: var(--r); overflow: hidden; border: 2px solid var(--line-2); background: var(--s800); }
.seg > button {
  min-height: var(--tap); padding: 0 0.9em; border: 0; background: transparent; color: var(--text-dim);
  font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em; cursor: pointer; touch-action: manipulation;
}
.seg > button + button { border-left: 2px solid var(--line-2); }
.seg > button[aria-pressed='true'] { background: var(--ember); color: var(--ember-ink); }

/* inputs */
.field {
  min-height: var(--tap); padding: 0.3em 0.7em; border-radius: var(--r); border: 2px solid var(--line-2);
  background: var(--s950); color: var(--text); font-weight: 700; font-size: 1.05rem; width: 100%;
}
.field:focus { border-color: var(--ember); outline: none; }
.field.code { font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.3em; text-align: center; }
input[type='range'] { width: 100%; accent-color: var(--ember); min-height: var(--tap); }

/* ---------- the modal */
.modal-back {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px;
  background: rgba(8, 4, 2, 0.72); backdrop-filter: blur(2px);
}
.modal {
  width: min(440px, 100%); padding: 20px 20px 16px; border-radius: var(--r-l);
  background: var(--s850) var(--grain); border: 1px solid var(--line-2);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 18px 50px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 200, 150, 0.06);
}
.modal-h { font-size: 1.7rem; margin-bottom: 8px; color: var(--glow); }
.modal-b { color: var(--text-dim); margin-bottom: 16px; font-size: 1.08rem; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* ---------- toasts outside the run */
.meta-toasts {
  position: fixed; top: calc(var(--st) + 12px); left: 50%; transform: translateX(-50%); z-index: 70;
  display: grid; gap: 6px; justify-items: center; pointer-events: none; width: min(92vw, 520px);
}
.meta-toast {
  padding: 8px 14px; border-radius: var(--r); background: var(--s700); border: 1px solid var(--line-2);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); font-weight: 700; transition: opacity 0.3s, transform 0.3s; text-align: center;
}
.meta-toast.good { background: var(--good-deep); border-color: var(--good); }
.meta-toast.bad { background: var(--bad-deep); border-color: var(--bad); }
.meta-toast.out { opacity: 0; transform: translateY(-8px); }

/* ---------- noscript */
.noscript { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; background: var(--s900); font-size: 1.2rem; z-index: 100; }
.noscript b { font-family: var(--font-head); font-weight: 400; color: var(--ember); font-size: 2rem; display: block; margin-bottom: 8px; }

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