/* Family Business (Mafia F&F). Palette tokens live in ../assets/colors/tokens.css. System fonts only. */
:root {
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --inset: 28px;
  /* notch / home-indicator safe areas (polish pass): every fixed edge inset is max(its design inset, the device inset).
     env() resolves to 0 on desktops and in headless runs, so the measured layout boxes are unchanged there. */
  --sa-t: env(safe-area-inset-top, 0px); --sa-r: env(safe-area-inset-right, 0px); --sa-b: env(safe-area-inset-bottom, 0px); --sa-l: env(safe-area-inset-left, 0px);
  /* touch pad geometry, shared by the pad and the floor notice that must clear it. The stick is 28vw on phones and caps
     at 132 px (the original's measured cap: 132 px at 500 and 600 wide), so tablets get the largest phone pad, not a
     230 px one. Jump/Dash cap in the same 23/28 and 17/28 proportions. */
  --pad-h: min(28vw, 132px); --pad-bottom: max(16px, var(--sa-b));
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: var(--ink); color: var(--cream); font-family: var(--sans); -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

#arcade { position: fixed; inset: 0; overflow: hidden; background: var(--ink); }
/* resolved per edge on #arcade itself so the .touch / .landscape --inset overrides below take part (a :root definition would freeze 28px) */
#arcade { --inset-t: max(var(--inset), var(--sa-t)); --inset-r: max(var(--inset), var(--sa-r)); --inset-b: max(var(--inset), var(--sa-b)); --inset-l: max(var(--inset), var(--sa-l)); }
#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
#arcade.touch { --inset: 12px; }
#arcade.touch.landscape { --inset: 8px; }

/* ---------- HUD ---------- */
#hud { position: fixed; top: var(--inset-t); left: var(--inset-l); right: var(--inset-r); height: 34px; display: flex; align-items: flex-start; justify-content: space-between; pointer-events: none; z-index: 5; text-shadow: 0 1px 0 rgba(0,0,0,.6); }
/* soft top scrim so the room name and counters stay legible over the level art (does not move any HUD box) */
#hud::before { content: ""; position: absolute; z-index: -1; left: calc(-1 * var(--inset-l)); right: calc(-1 * var(--inset-r)); top: calc(-1 * var(--inset-t)); height: calc(var(--inset-t) + 34px + 46px); background: linear-gradient(180deg, rgba(12,10,18,.78) 0%, rgba(12,10,18,.55) 55%, rgba(12,10,18,0) 100%); pointer-events: none; }
#hud button { pointer-events: auto; }
.hud-left { display: flex; align-items: flex-start; gap: 9px; }
#floor-id { display: flex; align-items: center; gap: 6px; height: 19px; margin-top: 7.4px; font: 700 11px/1 var(--mono); color: var(--accent); letter-spacing: .04em; }
#floor-id .tick { display: block; width: 3px; height: 19px; background: var(--accent); }
.hud-room { display: flex; flex-direction: column; gap: 4px; }
#room { font: 700 clamp(14px, 1.45vw, 20px)/1.05 var(--sans); color: var(--cream); white-space: nowrap; }
#mode-badge { font: 700 9px/1.1 var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--accent); }
.hud-right { display: flex; align-items: center; gap: 22px; height: 34px; }
.stat { display: inline-flex; align-items: center; gap: 5px; font: 700 13px/1.15 var(--mono); color: var(--cream); margin-top: 1px; }
.stat .ico { width: 13px; height: 13px; color: var(--smoke); }
#pause { position: relative; width: 36px; height: 34px; margin-left: -4px; border: 1px solid var(--steel); border-radius: 3px; background: rgba(20,16,26,.78); color: var(--cream); font: 700 13px/1 var(--mono); letter-spacing: -.05em; }
/* the drawn box keeps the original's 36x34 / 32x32; an invisible hit area extends the target to 44x44 CSS px (the
   pseudo-element is positioned against the button's padding box, inside the 1 px border, hence the extra pixel) */
#pause::before { content: ""; position: absolute; inset: -6px -5px; }
#pause:hover { border-color: var(--accent); }
#pause:focus-visible { border-color: var(--accent); outline: 2px solid var(--gold); outline-offset: 2px; }

#arcade.touch #hud { height: 32px; }
#arcade.touch .hud-left { gap: 6px; }
#arcade.touch #floor-id { height: 16px; margin-top: 4.9px; font-size: 9px; }
#arcade.touch #floor-id .tick { height: 16px; }
#arcade.touch .hud-room { gap: 2px; }
#arcade.touch #mode-badge { font-size: 8px; }
#arcade.touch .hud-right { gap: 14px; height: 32px; }
#arcade.touch .stat { font-size: 11px; }
#arcade.touch .stat .ico { width: 11px; height: 11px; }
#arcade.touch #pause { width: 32px; height: 32px; margin-left: 0; font-size: 11px; }
#arcade.touch #pause::before { inset: -7px; }

/* ---------- Start screen ---------- */
#entry { position: fixed; top: 14%; left: 50%; transform: translateX(-50%); width: 530px; max-width: calc(100% - 36px); text-align: center; z-index: 4; }
/* soft card behind the title copy so it never fights the level art (a pseudo-element: no box in #entry moves) */
#entry::before { content: ""; position: absolute; z-index: -1; inset: -20px -16px -18px; border: 1px solid rgba(81,74,92,.55); border-top: 2px solid var(--gold); background: radial-gradient(ellipse at 50% 30%, rgba(14,11,19,.9), rgba(14,11,19,.78)); box-shadow: 0 16px 48px rgba(0,0,0,.45); }
#entry h1 { width: 300px; height: 116.3px; margin: 0 auto; display: flex; flex-direction: column; justify-content: center; font: 900 50px/1.16 var(--sans); letter-spacing: -.02em; text-transform: uppercase; }
#entry h1 .t1 { color: var(--cream); text-shadow: 0 4px 0 #0c0a12, 0 0 24px rgba(0,0,0,.6); }
#entry h1 .t2 { color: var(--gold); text-shadow: 0 4px 0 #0c0a12, 0 0 24px rgba(0,0,0,.6); }
#entry .premise { max-width: 440px; margin: 12.7px auto 0; font: 500 16px/1.42 var(--sans); color: var(--cream); text-shadow: 0 1px 2px rgba(0,0,0,.8); }
#start-choices { display: flex; justify-content: center; gap: 9px; margin-top: 18.3px; }
#start-choices button { display: inline-flex; align-items: center; gap: 12px; height: 54.6px; padding: 0 16px 0 14px; border: 1px solid var(--steel); border-radius: 3px; background: rgba(18,14,24,.86); color: var(--cream); text-align: left; }
#start-choices button:hover { border-color: var(--gold); }
#start-choices button:focus-visible { border-color: var(--gold); outline: 2px solid var(--gold); outline-offset: 2px; }
#start-choices button[data-difficulty="nightmare"]:hover { border-color: var(--velvet); }
#start-choices button[data-difficulty="nightmare"]:focus-visible { border-color: var(--velvet); outline-color: var(--velvet); }
#start-choices .glyph { font-size: 18px; color: var(--gold); width: 20px; text-align: center; }
#start-choices button[data-difficulty="nightmare"] .glyph { color: var(--velvet); }
#start-choices .lbl { display: flex; flex-direction: column; gap: 3px; }
#start-choices .lbl b { font: 700 16px/1.1 var(--sans); }
#start-choices .lbl small { font: 500 11px/1.1 var(--mono); color: var(--smoke); }
#quick-hint { margin: 12.7px 0 0; font: 700 10px/1.1 var(--mono); letter-spacing: .02em; color: var(--smoke); text-shadow: 0 1px 2px rgba(0,0,0,.8); }
/* character choice: sits UNDER the hint so none of the measured landing boxes (title, premise, mode buttons, hint) moves */
#char-pick { display: flex; justify-content: center; margin: 12px 0 0; }
/* a stable min-width (the longest name, "Mafia Wizard") so the box and its arrows do not jump between names */
#char-btn { position: relative; display: inline-flex; align-items: center; justify-content: space-between; gap: 9px; min-width: 214px; height: 32px; padding: 0 12px; border: 1px solid var(--steel); border-radius: 3px; background: rgba(18,14,24,.86); color: var(--smoke); font: 700 10px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; }
#char-btn::before { content: ""; position: absolute; inset: -6px -4px; } /* 44 px tall hit area, like the pause button */
#char-btn .lbl b { color: var(--cream); font: inherit; letter-spacing: .02em; text-transform: none; }
#char-btn .arr { color: var(--gold); font-size: 15px; line-height: 1; }
#char-btn:hover { border-color: var(--gold); }
#char-btn:focus-visible { border-color: var(--gold); outline: 2px solid var(--gold); outline-offset: 2px; }

#arcade.touch #entry { top: 13%; width: calc(100% - 36px); }
#arcade.touch #entry h1 { width: 175px; height: 67.9px; font-size: 29px; line-height: 1.15; }
#arcade.touch #entry .premise { max-width: 280px; margin-top: 9.9px; font-size: 13px; }
#arcade.touch #start-choices { margin-top: 12.1px; }
#arcade.touch #start-choices button { height: 47.4px; gap: 10px; padding: 0 14px 0 12px; }
#arcade.touch #start-choices .glyph { font-size: 16px; }
#arcade.touch #start-choices .lbl b { font-size: 15px; }
#arcade.touch #start-choices .lbl small { font-size: 10px; }
#arcade.touch #quick-hint { margin-top: 12.9px; font-size: 9px; line-height: 1.5; }
#arcade.touch #char-pick { margin-top: 10px; }
#arcade.touch #char-btn { height: 36px; min-width: 198px; font-size: 9px; }
#arcade.touch #char-btn::before { inset: -4px; }
/* phone held sideways: the card has no room for another row (it would cover the ledge and the pad), so the picker sits
   in the card's top-right corner beside the title, out of the flow; the card and every measured box stay as on the base */
#arcade.touch.landscape #char-pick { position: absolute; top: 0; right: 0; height: 51px; margin: 0; align-items: center; }
#arcade.touch.landscape #char-btn { height: 28px; }
#arcade.touch.landscape #char-btn::before { inset: -8px -4px; }
#arcade.touch.landscape #entry h1 { width: 132px; height: 51px; font-size: 22px; }

/* ---------- In-play labels ---------- */
#dash-state { position: fixed; left: var(--inset-l); bottom: var(--inset-b); display: flex; align-items: center; gap: 6px; font: 700 10px/1.1 var(--mono); letter-spacing: .08em; color: var(--teal); z-index: 4; }
#dash-state .dot { width: 6px; height: 6px; background: currentColor; }
#dash-state.spent { color: var(--smoke); opacity: .55; }
#notice { position: fixed; left: 50%; bottom: 12%; transform: translateX(-50%); max-width: min(92vw, 520px); padding: 8px 14px; border: 1px solid var(--steel); background: rgba(14,11,19,.86); color: var(--cream); font: 700 12px/1.3 var(--mono); text-align: center; z-index: 4; pointer-events: none; }
/* on touch layouts the notice rides above the pad (the original keeps a clear gap over its stick/buttons on phones) */
#arcade.touch #notice { bottom: calc(var(--pad-bottom) + var(--pad-h) + 26px); }
#arcade.touch.landscape #notice { bottom: calc(var(--pad-bottom) + 26vh + 18px); }
#roof-action { position: fixed; left: 0; top: 0; transform: translate(-50%, -100%); padding: 4px 8px; border: 1px solid var(--gold); background: rgba(14,11,19,.9); color: var(--gold); font: 700 11px/1.2 var(--mono); white-space: nowrap; z-index: 4; pointer-events: none; }

/* ---------- Touch pad ---------- */
#touch-pad { position: fixed; left: max(3.6vw, var(--sa-l)); right: max(3.6vw, var(--sa-r)); bottom: var(--pad-bottom); height: var(--pad-h); display: flex; justify-content: space-between; align-items: flex-end; z-index: 6; touch-action: none; user-select: none; -webkit-user-select: none; }
#arcade.landscape #touch-pad { height: 26vh; }
#stick { position: relative; width: var(--pad-h); height: var(--pad-h); border-radius: 50%; background: rgba(20,16,26,.72); border: 2px solid rgba(227,182,90,.55); touch-action: none; }
#arcade.landscape #stick { width: 26vh; height: 26vh; }
#stick .ring { position: absolute; inset: 14%; border-radius: 50%; border: 1px solid rgba(244,233,210,.25); }
#stick .arrow { position: absolute; font: 700 18px/1 var(--mono); color: rgba(244,233,210,.55); }
#stick .arrow.l { left: 8%; top: 50%; transform: translateY(-50%); }
#stick .arrow.r { right: 8%; top: 50%; transform: translateY(-50%); }
#stick .arrow.d { left: 50%; bottom: 4%; transform: translateX(-50%); }
#stick .knob { position: absolute; left: 50%; top: 50%; width: calc(45% + 2px); height: calc(45% + 2px); /* ~45% of the stick's OUTER box: % resolves inside the 2 px border, so add it back */ border-radius: 50%; background: radial-gradient(circle at 40% 35%, #6b6378, #2d2735 70%); border: 2px solid var(--gold); transform: translate(-50%, -50%); }
.pad-buttons { display: flex; align-items: flex-end; gap: 2vw; }
.pad-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 50%; border: 2px solid rgba(227,182,90,.55); background: rgba(20,16,26,.78); color: var(--cream); font: 700 11px/1 var(--mono); letter-spacing: .06em; touch-action: none; }
.pad-btn .g { font-size: 22px; line-height: 1; }
.pad-btn.down { background: rgba(227,182,90,.35); }
.pad-btn[data-key="dash"] { width: min(17vw, 80px); height: min(17vw, 80px); margin-bottom: 20.7px; }
.pad-btn[data-key="jump"] { width: min(23vw, 108px); height: min(23vw, 108px); margin-bottom: 2px; font-size: 13px; background: radial-gradient(circle at 40% 30%, #c93d52, #7d1a2b 75%); border-color: #e3b65a; }
.pad-btn[data-key="jump"] .g { font-size: 28px; }
.pad-btn[data-key="jump"].down { background: radial-gradient(circle at 40% 30%, #e3b65a, #b7873b 75%); color: #1a1408; }
#arcade.landscape .pad-btn[data-key="dash"] { width: 16vh; height: 16vh; }
#arcade.landscape .pad-btn[data-key="jump"] { width: 21vh; height: 21vh; }

/* ---------- Dialogs ---------- */
#overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(8,6,12,.72); z-index: 10; }
#dialog { position: relative; width: 408px; max-width: calc(100% - 32px); padding: 30px; border-top: 3px solid var(--accent); background: linear-gradient(180deg, #1b1624, #120e18); color: var(--cream); box-shadow: 0 20px 60px rgba(0,0,0,.6); }
#dialog .dots { position: absolute; right: 12px; top: 6px; font: 700 12px/1 var(--mono); color: var(--smoke); letter-spacing: .1em; }
#dialog-kicker { font: 700 9px/14px var(--mono); letter-spacing: .18em; text-transform: uppercase; color: var(--accent); margin: 0 0 16px; }
#dialog-title { margin: 0 0 10px; font: 900 45px/1 var(--sans); letter-spacing: -.02em; text-transform: uppercase; text-shadow: 0 4px 0 rgba(0,0,0,.5); }
#dialog-text { margin: 0 0 17px; min-height: 30.5px; font: 700 11px/15px var(--mono); color: var(--cream); white-space: pre-line; }
#dialog-text[data-best]::after { content: attr(data-best); display: block; margin-top: 2px; color: var(--smoke); }
#dialog .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#dialog .tools { display: contents; }
#dialog .grid button { display: flex; align-items: center; gap: 10px; height: 45px; padding: 0 14px; border: 1px solid var(--steel); border-radius: 2px; background: rgba(30,24,38,.9); color: var(--cream); font: 700 13px/1 var(--mono); text-align: left; }
#dialog .grid button .g { color: var(--smoke); font-size: 13px; width: 14px; text-align: center; }
#dialog .grid button:hover { border-color: var(--accent); }
#dialog .grid button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
#dialog .grid button.primary { background: linear-gradient(135deg, var(--gold), var(--brass)); color: #1a1408; border-color: var(--gold); }
#dialog .grid button.primary .g { color: #1a1408; }
#dialog .grid button.wide { grid-column: 1 / -1; }
#help-text { font: 500 13px/1.5 var(--sans); color: var(--cream); margin: 0 0 17px; }
#help-text p { margin: 0 0 8px; }
#help-text kbd { font: 700 11px/1 var(--mono); padding: 2px 5px; border: 1px solid var(--steel); border-radius: 3px; background: rgba(0,0,0,.3); }
#choose-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 17px; }
#choose-choices button { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px 12px; border: 1px solid var(--steel); border-radius: 2px; background: rgba(30,24,38,.9); color: var(--cream); }
#choose-choices button b { font: 700 15px/1.1 var(--sans); }
#choose-choices button small { font: 500 11px/1.1 var(--mono); color: var(--smoke); }
#choose-choices button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
#dialog[data-view="won"] #dialog-text { font: 500 14px/1.5 var(--sans); min-height: 0; }

#arcade.touch #dialog { padding: 21px; }
#arcade.touch #dialog-kicker { margin-bottom: 17px; }
#arcade.touch #dialog-title { font-size: 31px; }
#arcade.touch #dialog .grid button { font-size: 11px; padding: 0 10px; }
#arcade.touch #help-text { font-size: 12px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
