/* Escape from Budapest: the global look. Tokens, fonts, the sticker buttons and the base layout.
   A gritty but warm Budapest night: BKV yellow, asphalt greys, receipt-paper white.
   Screens: css/meta.css; inventory grids: css/inv.css; the raid HUD: css/hud.css, css/panels.css, 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 */
  --bkv: #ffd200;              /* BKV / tram yellow: the brand colour */
  --bkv-deep: #e0b400;
  --bkv-ink: #17150f;
  --m2: #e41f18;               /* metro M2 red */
  --bkk: #6a3fb5;              /* BKK purple (tickets) */
  --a950: #0d0f11;             /* asphalt, darkest to lightest */
  --a900: #131619;
  --a850: #181b1f;
  --a800: #1d2125;
  --a700: #262a30;
  --a600: #30353c;
  --a500: #434950;
  --a400: #5e656d;
  --a300: #8b929a;
  --a200: #b9bec4;
  --text: #efebe2;
  --text-dim: #a9a59b;
  --text-faint: #767269;
  --paper: #f4f1e8;            /* receipts, vouchers, the summary */
  --paper-2: #e9e4d6;
  --paper-ink: #26221d;
  --good: #71d36b;
  --good-deep: #2f8a2a;
  --bad: #ff5b4d;
  --bad-deep: #b0261b;
  --warn: #ffb03a;
  --info: #7cc6ff;
  --sodium: #ffb45a;           /* street-lamp glow */
  /* 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: 4px;
  --r: 7px;
  --r-l: 12px;
  --tap: 44px;
  --sticker: 0 3px 0 rgba(0, 0, 0, 0.55), 0 6px 14px rgba(0, 0, 0, 0.35);
  --panel-bg: rgba(19, 22, 25, 0.94);
  --line: rgba(255, 255, 255, 0.09);
  --line-2: rgba(255, 255, 255, 0.16);
  --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);
  /* a subtle asphalt grain, drawn once as an SVG data URI (CSP: img-src data:) */
  --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 1 0 0 0 0 1 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(--a900);
  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(--bkv); }
small { font-size: 0.82em; }
.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(--bkv); color: var(--bkv-ink); }
:focus-visible { outline: 2px solid var(--bkv); outline-offset: 2px; }

/* ---------- the game canvas and the UI root */
#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--a950);
  touch-action: none;
}
#ui {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}
#ui > * { pointer-events: auto; }
#ui > .raid-root { position: absolute; inset: 0; pointer-events: none; }

/* ---------- buttons: stickers slapped on a lamp post */
.btn {
  --b-bg: var(--a600);
  --b-fg: var(--text);
  --b-edge: rgba(0, 0, 0, 0.55);
  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, 255, 255, 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.03em;
  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.12); }
.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: var(--bkv); --b-fg: var(--bkv-ink); --b-edge: #6b5600; border-color: rgba(0, 0, 0, 0.25); }
.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; }
.btn.on { --b-bg: var(--bkv); --b-fg: var(--bkv-ink); --b-edge: #6b5600; }
.btn.sticker { transform: rotate(-1.2deg); }
.btn.sticker:nth-child(2n) { transform: rotate(0.9deg); }
@media (pointer: coarse) { .btn.small { min-height: var(--tap); } }

/* a toggle / segmented control */
.seg { display: inline-flex; border-radius: var(--r); overflow: hidden; border: 2px solid var(--line-2); background: var(--a800); }
.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(--bkv); color: var(--bkv-ink); }
.seg > button:disabled { opacity: 0.4; cursor: not-allowed; }

/* inputs */
.field {
  min-height: var(--tap);
  padding: 0.3em 0.7em;
  border-radius: var(--r);
  border: 2px solid var(--line-2);
  background: var(--a950);
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  width: 100%;
}
.field:focus { border-color: var(--bkv); 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(--bkv); min-height: var(--tap); }

/* ---------- a tiny loading spinner: a rolling bottle cap */
.spin {
  display: inline-block;
  width: 1.1em; height: 1.1em;
  border-radius: 50%;
  border: 3px dashed var(--bkv);
  animation: spin 1s linear infinite;
  vertical-align: -0.2em;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- noscript */
.noscript {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center;
  background: var(--a900); color: var(--text); font-size: 1.2rem; z-index: 100;
}
.noscript b { font-family: var(--font-head); font-weight: 400; color: var(--bkv); 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; }
}

/* ---------- overlays shared by every screen (ui/invgrid.js): context menu, tooltip card, modal, toasts.
   They live in <body>, above #ui (z 10) and the raid panels. */
.ctx-menu {
  position: fixed;
  z-index: 1500;
  min-width: 180px;
  max-width: min(300px, calc(100vw - 12px));
  padding: 4px;
  border-radius: var(--r);
  background: var(--a800);
  border: 1px solid var(--line-2);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
}
.ctx-title {
  padding: 4px 10px 6px;
  font-size: 0.8rem;
  color: var(--text-dim);
  border-bottom: 1px solid var(--line);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ctx-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  padding: 4px 10px;
  border: 0;
  border-radius: var(--r-s);
  background: transparent;
  color: var(--text);
  font-weight: 700;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
.ctx-item small { color: var(--text-faint); font-weight: 600; font-size: 0.8rem; }
.ctx-item:hover:not(:disabled), .ctx-item:focus-visible { background: var(--bkv); color: var(--bkv-ink); outline: none; }
.ctx-item:hover:not(:disabled) small, .ctx-item:focus-visible small { color: rgba(0, 0, 0, 0.6); }
.ctx-item.danger { color: var(--bad); }
.ctx-item.danger:hover:not(:disabled) { background: var(--bad-deep); color: #fff; }
.ctx-item:disabled { opacity: 0.45; cursor: not-allowed; }
@media (pointer: coarse) { .ctx-item { min-height: var(--tap); } }

.inv-tip {
  position: fixed;
  z-index: 1400;
  max-width: min(290px, calc(100vw - 12px));
  pointer-events: none;
}
.card {
  padding: 8px 10px 9px;
  border-radius: var(--r);
  background: var(--paper);
  color: var(--paper-ink);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.55);
  font-size: 0.95rem;
  line-height: 1.25;
}
.card-h { display: flex; align-items: center; gap: 8px; font-size: 1.1rem; }
.card-h b { font-weight: 800; }
.card-g {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-size: 18px;
  font-family: 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', var(--font-body);
}
.card-cond { display: inline-block; margin-top: 4px; padding: 0 6px; border-radius: 3px; background: var(--warn); color: #221400; font-size: 0.8rem; font-weight: 800; text-transform: uppercase; }
.card-d { margin: 6px 0 4px; color: #4b453c; font-weight: 600; }
.card-rows { display: grid; grid-template-columns: auto 1fr; gap: 1px 10px; margin: 6px 0 0; padding-top: 5px; border-top: 1px dashed rgba(0, 0, 0, 0.25); font-size: 0.88rem; }
.card-rows dt { color: #7b7266; }
.card-rows dd { margin: 0; font-weight: 700; }

.modal-back {
  position: fixed;
  inset: 0;
  z-index: 1600;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 6, 8, 0.66);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.modal {
  width: min(430px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 16px 18px;
  border-radius: var(--r-l);
  background: var(--a800);
  border: 1px solid var(--line-2);
  border-top: 4px solid var(--bkv);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}
.modal-h { font-size: 1.6rem; margin-bottom: 8px; }
.modal-b { color: var(--text-dim); margin-bottom: 14px; font-size: 1.05rem; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal.info { background: transparent; border: 0; box-shadow: none; padding: 0; width: min(340px, 100%); }
.modal.info .modal-b { margin-bottom: 10px; }
.modal.info .card { font-size: 1rem; }

.meta-toasts {
  position: fixed;
  top: calc(10px + var(--st));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(420px, calc(100vw - 24px));
  pointer-events: none;
}
.meta-toast {
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--a700);
  border: 1px solid var(--line-2);
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  text-align: center;
  animation: toast-in 0.18s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}
.meta-toast.good { background: var(--good-deep); border-color: var(--good); }
.meta-toast.bad { background: var(--bad-deep); border-color: var(--bad); }
.meta-toast.info { background: var(--a700); }
.meta-toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } }
