:root {
  --bone: #e6dfcf;
  --bone-dim: #a9a291;
  --ink: #0b0a09;
  --panel: rgba(16, 14, 12, 0.92);
  --panel-edge: #3b342b;
  --blood: #b3261e;
  --blood-bright: #e2402f;
  --toxic: #a5c234;
  --rust: #b0672a;
  --cash: #7fbf4d;
  --energy: #d6b33c;
  --xp: #6b8fb8;
  --font-title: 'Special Elite', 'Courier New', monospace;
  --font-body: 'Barlow Condensed', 'Arial Narrow', sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #070605; color: var(--bone);
  font-family: var(--font-body); font-size: 17px;
  user-select: none; -webkit-user-select: none;
}
#game { position: fixed; inset: 0; }
#game canvas { display: block; width: 100%; height: 100%; }
.hidden { display: none !important; }

/* Film grain + vignette overlays (cheap, CSS only) */
#grain {
  pointer-events: none; position: fixed; inset: -50%; z-index: 40; opacity: 0.09;
  background-image: 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='0.9' numOctaves='3' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain 0.6s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); } 20% { transform: translate(-3%, 2%); } 40% { transform: translate(2%, -4%); }
  60% { transform: translate(-4%, -1%); } 80% { transform: translate(3%, 3%); } 100% { transform: translate(0, 0); }
}
#vignette {
  pointer-events: none; position: fixed; inset: 0; z-index: 41;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(0,0,0,0.55) 100%);
}

/* Loading */
#loading {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #070605;
}
.loading-title { font-family: var(--font-title); font-size: 64px; color: var(--bone); letter-spacing: 2px; text-shadow: 3px 3px 0 var(--blood); }
.loading-sub { margin-top: 8px; color: var(--bone-dim); font-size: 20px; }

/* UI root */
#ui-root { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
#ui-root > * { pointer-events: none; }
#dialog-layer, #dialog-layer * { pointer-events: auto; }

/* HUD */
#hud { position: absolute; inset: 0; }
.hud-tl {
  position: absolute; top: 12px; left: 12px; width: 270px; padding: 10px 12px;
  background: linear-gradient(180deg, rgba(14,12,10,0.85), rgba(14,12,10,0.6));
  border: 1px solid var(--panel-edge); border-radius: 3px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.5);
}
.hud-name { font-family: var(--font-title); font-size: 20px; display: flex; justify-content: space-between; align-items: baseline; }
.hud-name .lvl { font-family: var(--font-body); font-size: 15px; color: var(--bone-dim); }
.hud-name .lvl b { color: var(--bone); }
.bar { position: relative; height: 14px; margin-top: 6px; background: #1d1915; border: 1px solid #000; overflow: hidden; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; transition: width 0.25s; }
.bar span { position: absolute; inset: 0; font-size: 12px; line-height: 13px; text-align: center; color: #fff; text-shadow: 1px 1px 0 #000; font-weight: 600; }
.bar.hp i { background: linear-gradient(90deg, #6d1510, var(--blood-bright)); }
.bar.en i { background: linear-gradient(90deg, #6b5512, var(--energy)); }
.bar.xp { height: 5px; }
.bar.xp i { background: var(--xp); }
.hud-money { margin-top: 7px; font-size: 24px; font-weight: 800; color: var(--cash); text-shadow: 1px 1px 0 #000; }
.hud-money small { font-size: 14px; color: var(--bone-dim); font-weight: 400; margin-left: 6px; }
.hud-money.flash-up { animation: flashUp 0.6s; }
.hud-money.flash-down { animation: flashDown 0.6s; }
@keyframes flashUp { 0% { transform: scale(1.15); color: #c9ff8a; } 100% { transform: scale(1); } }
@keyframes flashDown { 0% { transform: scale(1.15); color: var(--blood-bright); } 100% { transform: scale(1); } }
.hud-stats { margin-top: 5px; display: flex; gap: 10px; font-size: 14px; color: var(--bone-dim); flex-wrap: wrap; }
.hud-stats b { color: var(--bone); }

.hud-tr { position: absolute; top: 12px; right: 12px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
#hud-clock { font-family: var(--font-title); font-size: 20px; padding: 4px 10px; background: rgba(14,12,10,0.75); border: 1px solid var(--panel-edge); }
#hud-district { font-size: 16px; color: var(--toxic); text-transform: uppercase; letter-spacing: 1px; text-shadow: 1px 1px 0 #000; }
#hud-heat { color: var(--blood-bright); font-size: 20px; letter-spacing: 2px; text-shadow: 1px 1px 0 #000; }
#minimap { width: 200px; height: 200px; border: 2px solid var(--panel-edge); border-radius: 50%; background: rgba(10,9,8,0.7); box-shadow: 0 4px 18px rgba(0,0,0,0.6); }

.hud-br { position: absolute; right: 16px; bottom: 14px; text-align: right; text-shadow: 1px 1px 0 #000; }
#hud-weapon { font-size: 22px; font-weight: 800; text-transform: uppercase; }
#hud-vehicle { font-size: 18px; color: var(--bone-dim); }
.hud-bl { position: absolute; left: 14px; bottom: 14px; max-width: 360px; text-shadow: 1px 1px 0 #000; }

#prompt {
  position: absolute; left: 50%; bottom: 22%; transform: translateX(-50%);
  padding: 6px 16px; background: rgba(10,9,8,0.85); border: 1px solid var(--panel-edge);
  font-size: 20px; letter-spacing: 0.5px;
}
#prompt kbd, .ui-opt .k, kbd {
  display: inline-block; min-width: 22px; padding: 0 5px; margin-right: 6px; text-align: center;
  background: var(--bone); color: var(--ink); font-family: var(--font-body); font-weight: 800; border-radius: 2px;
}

/* Toasts */
#toasts { position: absolute; top: 40%; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.toast {
  padding: 6px 14px; background: rgba(10,9,8,0.9); border-left: 4px solid var(--bone-dim);
  font-size: 19px; animation: toastIn 0.2s ease-out; max-width: 520px; text-align: center;
}
.toast.good { border-color: var(--cash); }
.toast.bad { border-color: var(--blood-bright); }
.toast.money { border-color: var(--cash); color: var(--cash); font-weight: 800; }
.toast.stat { border-color: var(--xp); }
.toast.out { opacity: 0; transition: opacity 0.4s; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

#bigtext {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(60,0,0,0.25), rgba(0,0,0,0.6));
}
#bigtext .big { font-family: var(--font-title); font-size: 72px; color: var(--blood-bright); text-shadow: 4px 4px 0 #000; text-align: center; }
#bigtext .sub { font-size: 24px; color: var(--bone); margin-top: 8px; text-align: center; }

/* Modals / dialogs */
.ui-modal {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.35); padding: 16px;
}
.ui-modal + .ui-modal { background: rgba(0,0,0,0.2); }
.ui-panel {
  position: relative; width: 100%; max-height: 90vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--panel-edge);
  box-shadow: 0 10px 40px rgba(0,0,0,0.7), inset 0 0 60px rgba(0,0,0,0.6);
  padding: 18px 20px 16px;
  background-image:
    linear-gradient(rgba(16,14,12,0.94), rgba(16,14,12,0.94)),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.03) 0 2px, transparent 2px 6px);
}
.ui-title {
  font-family: var(--font-title); font-size: 28px; color: var(--bone); margin-bottom: 10px; padding-right: 30px;
  border-bottom: 2px solid var(--blood); padding-bottom: 6px;
}
.ui-x {
  position: absolute; top: 10px; right: 10px; width: 30px; height: 30px;
  background: transparent; border: 1px solid var(--panel-edge); color: var(--bone-dim); cursor: pointer; font-size: 16px;
}
.ui-x:hover { color: var(--bone); border-color: var(--bone-dim); }
.ui-speaker { font-weight: 800; color: var(--toxic); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; }
.ui-text { font-size: 19px; line-height: 1.35; margin-bottom: 14px; white-space: normal; }
.ui-text em { color: var(--bone-dim); }
.ui-opts { display: flex; flex-direction: column; gap: 6px; }
.ui-opt, .ui-btn {
  display: flex; align-items: center; gap: 4px; width: 100%; text-align: left;
  padding: 8px 10px; background: #1b1814; color: var(--bone); border: 1px solid #2e2821;
  font-family: var(--font-body); font-size: 18px; cursor: pointer;
}
.ui-opt small { margin-left: auto; color: var(--bone-dim); font-size: 15px; padding-left: 10px; }
.ui-opt:hover:not(.disabled), .ui-btn:hover:not(:disabled) { background: #2a231b; border-color: var(--rust); }
.ui-opt.disabled, .ui-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ui-btn { display: inline-flex; width: auto; justify-content: center; }
.ui-btn.primary { background: var(--blood); border-color: #7a1913; }
.ui-btn.primary:hover:not(:disabled) { background: var(--blood-bright); }
.ui-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ui-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.ui-card { background: #1b1814; border: 1px solid #2e2821; padding: 8px 10px; }
.ui-card h4 { margin: 0 0 4px; font-size: 18px; }
.ui-muted { color: var(--bone-dim); }
.ui-good { color: var(--cash); }
.ui-bad { color: var(--blood-bright); }
.ui-section { margin: 12px 0 6px; font-family: var(--font-title); font-size: 19px; color: var(--rust); }
.ui-table { width: 100%; border-collapse: collapse; font-size: 17px; }
.ui-table td, .ui-table th { padding: 4px 6px; border-bottom: 1px solid #2a241d; text-align: left; }
.ui-table th { color: var(--bone-dim); font-weight: 600; }
input.ui-input {
  width: 100%; padding: 8px 10px; background: #0f0d0b; color: var(--bone); border: 1px solid var(--panel-edge);
  font-family: var(--font-body); font-size: 19px; user-select: text;
}

/* Title screen */
#title-layer { position: fixed; inset: 0; z-index: 60; }
#title-layer:empty { display: none; }
.title-screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at center, rgba(20,10,8,0.15) 0%, rgba(10,6,4,0.45) 55%, rgba(0,0,0,0.88) 100%),
    linear-gradient(180deg, rgba(0,0,0,0.5), rgba(0,0,0,0) 30%, rgba(0,0,0,0) 70%, rgba(0,0,0,0.6));
  animation: titleIn 2.5s ease-out;
}
@keyframes titleIn { from { background-color: #000; } to { background-color: transparent; } }
.title-logo { animation: logoFlicker 7s infinite; }
@keyframes logoFlicker { 0%, 92%, 100% { opacity: 1; } 93% { opacity: 0.35; } 94% { opacity: 1; } 96% { opacity: 0.6; } 97% { opacity: 1; } }
.title-box { padding: 14px; background: rgba(10,9,8,0.55); border: 1px solid rgba(59,52,43,0.7); backdrop-filter: blur(2px); }
.title-logo { font-family: var(--font-title); font-size: 96px; line-height: 1; color: var(--bone); text-shadow: 5px 5px 0 var(--blood), 10px 10px 30px #000; transform: rotate(-2deg); }
.title-tag { margin: 10px 0 30px; font-size: 22px; color: var(--bone-dim); }
.title-box { width: 340px; display: flex; flex-direction: column; gap: 8px; }
.title-foot { position: absolute; bottom: 14px; color: var(--bone-dim); font-size: 14px; }
@media (max-width: 700px) {
  .title-logo { font-size: 56px; }
  .hud-tl { width: 210px; }
  #minimap { width: 120px; height: 120px; }
}


/* ======================= Round 2: progression / phone / radio / polish ======================= */
:root { --hud-user-scale: 1; --hud-auto-scale: 1; }
.hud-tl { transform: scale(calc(var(--hud-user-scale) * var(--hud-auto-scale))); transform-origin: top left; }
.hud-tr { transform: scale(calc(var(--hud-user-scale) * var(--hud-auto-scale))); transform-origin: top right; }
.hud-br { transform: scale(calc(var(--hud-user-scale) * var(--hud-auto-scale))); transform-origin: bottom right; }
.hud-bl { transform: scale(calc(var(--hud-user-scale) * var(--hud-auto-scale))); transform-origin: bottom left; }

/* "!" notification bubbles */
.hud-bubbles {
  position: absolute; left: 12px; top: calc(12px + 192px * var(--hud-user-scale) * var(--hud-auto-scale));
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
}
.hud-bubble {
  pointer-events: auto; cursor: pointer; display: flex; align-items: center; gap: 8px;
  padding: 3px 10px 3px 3px; background: rgba(14,12,10,0.88); border: 1px solid var(--panel-edge); border-radius: 18px;
  font-size: 15px; box-shadow: 0 3px 12px rgba(0,0,0,0.5); animation: bubbleIn 0.3s ease-out;
}
.hud-bubble:hover { border-color: var(--rust); }
.hud-bubble .bang {
  display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--blood); color: #fff; font-weight: 800; font-size: 15px;
}
.hud-bubble.pulse .bang { animation: bang 1.6s infinite; }
.hud-bubble kbd { margin: 0 0 0 2px; font-size: 13px; }
@keyframes bang { 0%, 100% { box-shadow: 0 0 0 0 rgba(226,64,47,0.7); } 60% { box-shadow: 0 0 0 9px rgba(226,64,47,0); } }
@keyframes bubbleIn { from { transform: translateX(-20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Radio */
.hud-radio {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); text-align: center;
  padding: 4px 14px; background: rgba(10,9,8,0.72); border: 1px solid var(--panel-edge); border-radius: 3px;
  font-size: 16px; text-shadow: 1px 1px 0 #000; max-width: min(620px, 70vw);
}
.hud-radio .rad-note { color: var(--toxic); }
.hud-radio .rad-keys kbd { font-size: 12px; margin: 0 0 0 3px; min-width: 16px; }
.hud-radio .rad-tag { color: var(--bone-dim); font-size: 14px; font-style: italic; }
.hud-radio .rad-sub { margin-top: 3px; font-size: 15px; color: var(--bone); max-width: 600px; }
.hud-radio .rad-sub b { color: var(--energy); }
.hud-radio.flash { animation: radFlash 0.5s ease-out; }
@keyframes radFlash { from { transform: translateX(-50%) scale(1.15); border-color: var(--toxic); } to { transform: translateX(-50%) scale(1); } }

/* Photo mode */
body.photo-mode #hud, body.photo-mode #prompt, body.photo-mode #net-chat, body.photo-mode #npc-crosshair,
body.photo-mode #q-tracker, body.photo-mode #sys-hud { display: none !important; }

/* Big text variants (death / busted / win) */
#bigtext.bt-death { background: radial-gradient(ellipse at center, rgba(90,0,0,0.35), rgba(10,0,0,0.85)); animation: deathIn 0.6s ease-out; }
#bigtext.bt-death .big { font-size: 96px; letter-spacing: 6px; color: #e2402f; text-shadow: 0 0 30px rgba(226,64,47,0.6), 5px 5px 0 #000; animation: deathSlam 0.5s cubic-bezier(.2,1.6,.4,1); }
#bigtext.bt-death .sub { font-family: var(--font-title); font-size: 26px; }
@keyframes deathIn { from { background-color: rgba(255,255,255,0.4); } to { background-color: transparent; } }
@keyframes deathSlam { from { transform: scale(2.4) rotate(-6deg); opacity: 0; } to { transform: none; opacity: 1; } }
#bigtext.bt-busted { animation: copLights 0.5s steps(1) infinite; }
#bigtext.bt-busted .big { font-size: 104px; color: #e6dfcf; letter-spacing: 8px; transform: rotate(-4deg);
  border: 6px solid #e6dfcf; padding: 0 24px; text-shadow: 4px 4px 0 #000; box-shadow: 6px 6px 0 #000; animation: stamp 0.35s ease-out; }
@keyframes copLights {
  0% { background: radial-gradient(ellipse at 15% 50%, rgba(220,30,30,0.45), rgba(0,0,0,0.6) 60%); }
  50% { background: radial-gradient(ellipse at 85% 50%, rgba(30,70,230,0.45), rgba(0,0,0,0.6) 60%); }
}
@keyframes stamp { from { transform: rotate(-4deg) scale(2.2); opacity: 0; } to { transform: rotate(-4deg) scale(1); opacity: 1; } }
#bigtext.bt-win { background: radial-gradient(ellipse at center, rgba(60,50,0,0.25), rgba(0,0,0,0.5)); }
#bigtext.bt-win .big { color: #e0b23a; animation: deathSlam 0.45s ease-out; }

/* Title in-page dialog */
.title-modal { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.6); padding: 16px; }

/* Character creator */
.creator {
  position: absolute; inset: 0; display: flex; flex-direction: column; padding: 18px 24px; gap: 10px;
  background: linear-gradient(90deg, rgba(0,0,0,0.55), rgba(5,4,3,0.92) 45%); overflow: hidden;
}
.creator-title { font-family: var(--font-title); font-size: 42px; color: var(--bone); text-shadow: 3px 3px 0 var(--blood); }
.creator-main { display: flex; gap: 24px; flex: 1; min-height: 0; align-items: flex-start; flex-wrap: wrap; overflow: auto; padding-bottom: 8px; }
.creator-preview { flex: 0 0 300px; display: flex; flex-direction: column; gap: 8px; align-items: center; position: sticky; top: 0; }
.creator-preview canvas {
  width: 300px; height: 380px; cursor: grab;
  background: radial-gradient(ellipse at 50% 70%, rgba(179,38,30,0.25), rgba(0,0,0,0.6) 70%);
  border: 1px solid var(--panel-edge);
}
.creator-preview-name { font-family: var(--font-title); font-size: 24px; }
.creator-form { flex: 1; min-width: 300px; display: flex; flex-direction: column; gap: 6px; }
.creator-form label { margin-top: 6px; font-family: var(--font-title); color: var(--rust); font-size: 17px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.swatches.dim { opacity: 0.35; }
.sw { width: 30px; height: 30px; border: 2px solid #2e2821; cursor: pointer; border-radius: 3px; padding: 0; }
.sw.none { background: repeating-linear-gradient(45deg, #333 0 4px, #1b1814 4px 8px); }
.sw.sel { border-color: var(--bone); box-shadow: 0 0 0 2px var(--blood); }
.swatches input[type=color] { width: 36px; height: 30px; border: 1px solid #2e2821; background: none; padding: 0; cursor: pointer; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 10px; background: #1b1814; color: var(--bone); border: 1px solid #2e2821; font-family: var(--font-body); font-size: 16px; cursor: pointer; }
.chip:hover { border-color: var(--rust); }
.chip.sel { background: var(--blood); border-color: #7a1913; }
.bgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.bg-card {
  text-align: left; padding: 8px 10px; background: #1b1814; color: var(--bone); border: 1px solid #2e2821; cursor: pointer;
  font-family: var(--font-body); font-size: 15px; display: flex; flex-direction: column; gap: 3px;
}
.bg-card b { font-size: 18px; }
.bg-card span { color: var(--bone-dim); }
.bg-card ul { margin: 2px 0 0; padding-left: 16px; color: var(--toxic); }
.bg-card:hover { border-color: var(--rust); }
.bg-card.sel { border-color: var(--blood-bright); background: #2a1512; box-shadow: inset 0 0 0 1px var(--blood); }
.creator-foot { display: flex; gap: 8px; padding-top: 6px; border-top: 1px solid var(--panel-edge); }
.creator-foot .ui-btn { font-size: 20px; padding: 10px 18px; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 10px; border-bottom: 1px solid var(--panel-edge); }
.tab { padding: 6px 16px; background: transparent; color: var(--bone-dim); border: 1px solid transparent; border-bottom: none; font-family: var(--font-title); font-size: 18px; cursor: pointer; }
.tab.sel { color: var(--bone); background: #1b1814; border-color: var(--panel-edge); }

/* Perks */
.perk-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; font-size: 19px; }
.perk-pts { font-size: 30px; color: var(--toxic); }
.perk-trees { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 12px; }
.perk-tree { border-top: 3px solid var(--tree); padding-top: 6px; display: flex; flex-direction: column; gap: 6px; }
.perk-tree-name { font-family: var(--font-title); font-size: 24px; color: var(--tree); }
.perk-tree-blurb { font-size: 15px; margin-bottom: 4px; }
.perk {
  text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 7px 10px; cursor: pointer;
  background: #1b1814; color: var(--bone); border: 1px solid #2e2821; border-left: 4px solid #2e2821; font-family: var(--font-body);
}
.perk-name { font-weight: 800; font-size: 17px; }
.perk-desc { font-size: 15px; color: var(--bone-dim); }
.perk-req { font-size: 13px; color: var(--rust); }
.perk-tag { font-size: 12px; font-weight: 800; color: var(--tree); letter-spacing: 1px; }
.perk.available { border-left-color: var(--tree); }
.perk.available:hover { background: #2a231b; box-shadow: 0 0 0 1px var(--tree); }
.perk.owned { border-color: var(--tree); background: linear-gradient(90deg, rgba(255,255,255,0.06), #1b1814); cursor: default; }
.perk.locked { opacity: 0.45; cursor: not-allowed; }
.perk.nopoints { opacity: 0.75; cursor: not-allowed; }

/* Achievements */
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.ach { display: flex; flex-direction: column; gap: 2px; padding: 7px 10px; background: #15130f; border: 1px solid #2a241d; opacity: 0.55; }
.ach span { color: var(--bone-dim); font-size: 15px; }
.ach small { color: var(--energy); }
.ach.got { opacity: 1; border-color: #6b5512; background: linear-gradient(90deg, rgba(214,179,60,0.12), #1b1814); }
.ach-chip { padding: 2px 8px; background: #1b1814; border: 1px solid #6b5512; font-size: 15px; }
.ach-toast {
  position: absolute; top: 90px; left: 50%; transform: translateX(-50%); display: flex; gap: 12px; align-items: center;
  padding: 10px 18px 10px 12px; background: rgba(16,14,12,0.96); border: 1px solid #6b5512; border-left: 5px solid var(--energy);
  box-shadow: 0 8px 30px rgba(0,0,0,0.7), 0 0 30px rgba(214,179,60,0.15); animation: achIn 0.45s cubic-bezier(.2,1.4,.4,1); min-width: 320px;
}
.ach-toast.out { opacity: 0; transform: translateX(-50%) translateY(-20px); transition: all 0.45s; }
.ach-icon { font-size: 34px; }
.ach-k { font-size: 12px; letter-spacing: 2px; color: var(--energy); font-weight: 800; }
.ach-n { font-family: var(--font-title); font-size: 22px; }
.ach-d { font-size: 15px; color: var(--bone-dim); }
@keyframes achIn { from { transform: translateX(-50%) translateY(-30px) scale(0.8); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }

/* Phone */
.ui-modal.phone-modal { justify-content: flex-end; align-items: flex-end; padding: 0 40px 0 16px; background: rgba(0,0,0,0.2); }
.phone-modal .ui-panel { padding: 0; background: none; border: none; box-shadow: none; overflow: visible; max-height: none; width: auto; }
.phone-modal .ui-x { display: none; }
.phone {
  width: 340px; height: min(640px, 92vh); display: flex; flex-direction: column;
  background: #0d0c0b; border: 10px solid #1a1817; border-bottom-width: 0; border-radius: 34px 34px 0 0;
  box-shadow: 0 0 0 2px #3b342b, 0 20px 60px rgba(0,0,0,0.85); overflow: hidden; animation: phoneUp 0.28s cubic-bezier(.2,1.2,.4,1);
  background-image: linear-gradient(160deg, #241d18, #0d0c0b 60%);
}
@keyframes phoneUp { from { transform: translateY(80%); } to { transform: none; } }
.ph-status { display: flex; justify-content: space-between; padding: 8px 18px 2px; font-size: 13px; color: var(--bone-dim); }
.ph-bar { display: flex; align-items: center; gap: 8px; padding: 4px 14px 8px; font-family: var(--font-title); font-size: 20px; border-bottom: 1px solid #2a241d; min-height: 40px; }
.ph-back { background: none; border: none; color: var(--bone); font-size: 28px; line-height: 1; cursor: pointer; padding: 0 6px 0 0; }
.ph-screen { flex: 1; overflow: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.ph-foot { display: flex; justify-content: center; padding: 8px 0 12px; }
.ph-home { width: 110px; height: 6px; border-radius: 3px; background: #6a645a; border: none; cursor: pointer; }
.ph-wall { font-family: var(--font-title); font-size: 30px; text-align: center; margin: 14px 0 8px; color: var(--bone); text-shadow: 2px 2px 0 var(--blood); }
.ph-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 6px; }
.ph-app { display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: none; color: var(--bone); font-family: var(--font-body); font-size: 14px; cursor: pointer; }
.ph-ico { position: relative; width: 54px; height: 54px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 26px; box-shadow: inset 0 -3px 0 rgba(0,0,0,0.35), 0 3px 8px rgba(0,0,0,0.5); color: #f0e8d6; }
.ph-app:hover .ph-ico { filter: brightness(1.3); }
.ph-badge { position: absolute; top: -5px; right: -5px; min-width: 20px; height: 20px; border-radius: 10px; background: var(--blood-bright); color: #fff; font-style: normal; font-size: 13px; font-weight: 800; display: flex; align-items: center; justify-content: center; padding: 0 5px; }
.ph-tip { margin-top: auto; font-size: 14px; color: var(--bone-dim); text-align: center; }
.ph-tip kbd { font-size: 12px; }
.ph-card { background: #1b1814; border: 1px solid #2e2821; padding: 10px 12px; border-radius: 6px; }
.ph-big { font-size: 30px; font-weight: 800; }
.ph-wide { width: 100%; justify-content: space-between; }
.ph-wide small { color: var(--bone-dim); }
.ph-list { display: flex; flex-direction: column; gap: 6px; }
.ph-row { text-align: left; display: flex; flex-direction: column; gap: 1px; padding: 8px 10px; background: #1b1814; color: var(--bone); border: 1px solid #2e2821; border-radius: 6px; cursor: pointer; font-family: var(--font-body); font-size: 17px; }
.ph-row span { color: var(--bone-dim); font-size: 14px; }
.ph-row:hover { border-color: var(--rust); }
.ph-row.sel { border-color: var(--toxic); box-shadow: inset 3px 0 0 var(--toxic); }
.ph-msg { background: #1b1814; border-radius: 10px 10px 10px 2px; padding: 7px 10px; font-size: 16px; border: 1px solid #2a241d; }
.ph-msg.new { border-color: var(--blood); }
.ph-msg-h { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.ph-msg-h span { color: var(--bone-dim); font-size: 12px; }
.ph-empty { text-align: center; margin-top: 40px; }
.ph-table { font-size: 15px; }
.ph-slider { display: flex; flex-direction: column; gap: 2px; font-size: 16px; }
.ph-slider b { color: var(--toxic); font-size: 14px; }
.ph-slider input { width: 100%; accent-color: var(--blood-bright); }
.ph-check { display: flex; gap: 8px; align-items: center; font-size: 16px; cursor: pointer; }
.ph-check input { accent-color: var(--blood-bright); width: 18px; height: 18px; }
.ph-seg { display: flex; gap: 6px; align-items: center; font-size: 16px; }
.ph-seg span { flex: 1; }
.ph-seg .ui-btn { min-width: 40px; padding: 4px 10px; }
#phone-fade { position: fixed; inset: 0; background: #000; opacity: 0; transition: opacity 0.5s; pointer-events: none; z-index: 90; }
#phone-fade.on { opacity: 1; }
.dealer-table td, .dealer-table th { font-size: 15px; white-space: nowrap; }
.dealer-table .here { background: rgba(165,194,52,0.1); }

/* Help */
.help-table td.keys { white-space: nowrap; width: 1%; padding-right: 16px; }
.help-table kbd { margin-right: 3px; }

/* Mobile-friendly HUD */
@media (max-width: 900px), (max-height: 560px) {
  :root { --hud-auto-scale: 0.8; }
  .hud-radio { font-size: 14px; }
}
@media (max-width: 600px) {
  :root { --hud-auto-scale: 0.66; }
  #toasts { top: 30%; width: 92vw; }
  .toast { font-size: 16px; }
  #bigtext .big, #bigtext.bt-death .big, #bigtext.bt-busted .big { font-size: 52px; }
  .ui-modal.phone-modal { justify-content: center; padding: 0; }
  .phone { width: 100vw; height: 88vh; border-radius: 20px 20px 0 0; }
  .creator { padding: 12px; }
  .creator-preview { flex-basis: 100%; position: static; }
  .creator-preview canvas { width: 220px; height: 280px; }
  .creator-title { font-size: 30px; }
  .ach-toast { min-width: 0; width: 92vw; }
  .ui-panel { padding: 14px 12px; }
}

/* ======================= Round 4: HUD layout & polish ======================= */
/* Columns stack without overlaps: ui.js (_layoutHud) measures the real, scaled
   panel heights and publishes them as --hud-* variables. The ids below are owned
   by other modules; we only position them. */
#hud .hud-bubbles { top: var(--hud-l2, 204px); }
#ui-root #heist-hud { top: var(--hud-l1, 176px); left: 12px; }
#hud #q-tracker { top: var(--hud-r1, 300px); bottom: auto; right: 12px; width: min(260px, 42vw); }
#hud #q-tracker .qt-obj { font-size: 16px; line-height: 1.2; }
#ui-root #net-chat { bottom: var(--hud-b0, 44px); }
#hud #sys-hud { bottom: var(--hud-b1, 54px); }

/* Toasts live in the right column under the quest tracker: never over the player. */
#ui-root #toasts {
  top: var(--hud-r2, 400px); left: auto; right: 12px; transform: none;
  width: min(340px, 42vw); align-items: flex-end; gap: 5px;
}
#toasts .toast {
  font-size: 17px; line-height: 1.25; padding: 6px 12px; max-width: 100%; text-align: right;
  border-left: none; border-right: 4px solid var(--bone-dim);
  background: linear-gradient(270deg, rgba(14,12,10,0.94), rgba(14,12,10,0.82));
  box-shadow: 0 3px 12px rgba(0,0,0,0.45); animation: toastSlide 0.22s ease-out;
}
#toasts .toast.good, #toasts .toast.money { border-right-color: var(--cash); }
#toasts .toast.bad { border-right-color: var(--blood-bright); }
#toasts .toast.stat { border-right-color: var(--xp); }
@keyframes toastSlide { from { transform: translateX(14px); opacity: 0; } to { transform: none; opacity: 1; } }

/* HUD type rhythm */
.hud-tl { padding: 10px 12px 9px; }
.hud-money { margin-top: 6px; line-height: 1.05; }
.hud-stats { margin-top: 4px; }
#hud-clock { line-height: 1.2; }
#hud-district { line-height: 1.2; }
#hud-heat:empty { display: none; }
.hud-br { line-height: 1.1; }

/* Prompt: compact, readable, never wider than the screen */
#prompt { max-width: min(640px, 92vw); text-align: center; box-shadow: 0 4px 16px rgba(0,0,0,0.5); border-radius: 2px; }

/* Panels never exceed the viewport */
.ui-modal { padding: 16px; }
.ui-panel { max-width: calc(100vw - 32px); max-height: calc(100vh - 32px); overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #4a4034 transparent; }
.ui-panel::-webkit-scrollbar { width: 8px; }
.ui-panel::-webkit-scrollbar-thumb { background: #4a4034; border-radius: 4px; }
.ui-opt { min-height: 40px; }
.ui-opt .k { flex: 0 0 auto; }

@media (max-width: 700px) {
  #ui-root #toasts { top: var(--hud-r2, 260px); right: auto; left: 50%; transform: translateX(-50%); width: 92vw; align-items: center; }
  #toasts .toast { font-size: 15px; padding: 4px 10px; }
  #hud .hud-bubbles { transform: scale(var(--hud-auto-scale)); transform-origin: top left; max-width: 46vw; }
  #hud #q-tracker { width: 44vw; }
  #hud #q-tracker .qt-title { font-size: 14px; }
  #hud #q-tracker .qt-obj { font-size: 13px; }
  #district-card { top: auto !important; bottom: 27%; max-width: 90vw !important; }
  #toasts .toast { text-align: center; border-right: none; border-left: 4px solid var(--bone-dim); }
  #toasts .toast.good, #toasts .toast.money { border-left-color: var(--cash); }
  #toasts .toast.bad { border-left-color: var(--blood-bright); }
  .ui-title { font-size: 22px; }
  .ui-text { font-size: 17px; }
  .ui-opt { font-size: 16px; padding: 7px 8px; }
  #prompt { font-size: 17px; bottom: 18%; }
}
@media (max-height: 560px) {
  .ui-modal { padding: 8px; }
  .ui-panel { max-height: calc(100vh - 16px); padding: 12px 14px; }
  .ui-title { font-size: 22px; margin-bottom: 6px; }
}

/* Title screen polish: a dark, legible centre column over the moving city */
.title-screen {
  background:
    radial-gradient(ellipse 46% 62% at 50% 50%, rgba(6,5,4,0.62) 0%, rgba(6,5,4,0.35) 55%, rgba(0,0,0,0) 100%),
    radial-gradient(ellipse at center, rgba(20,10,8,0.1) 0%, rgba(10,6,4,0.4) 60%, rgba(0,0,0,0.85) 100%),
    linear-gradient(180deg, rgba(0,0,0,0.55), rgba(0,0,0,0) 28%, rgba(0,0,0,0) 72%, rgba(0,0,0,0.65));
  padding: 24px 16px 56px;
}
.title-head { display: flex; flex-direction: column; align-items: center; }
.title-logo { font-size: clamp(56px, 9vw, 104px); }
.title-tag { margin: 14px 0 26px; font-size: 21px; color: #cfc6b2; text-align: center; text-shadow: 0 2px 8px #000, 1px 1px 0 #000; }
.title-box {
  width: min(340px, 92vw); padding: 16px 16px 14px; gap: 8px;
  background: rgba(12,10,9,0.84); border: 1px solid #3b342b; border-top: 2px solid var(--blood);
  box-shadow: 0 14px 40px rgba(0,0,0,0.6); backdrop-filter: blur(3px);
}
.title-label { font-family: var(--font-title); font-size: 15px; color: var(--rust); margin-bottom: -2px; }
.title-buttons { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.title-buttons .ui-btn { font-size: 19px; padding: 10px 12px; letter-spacing: 0.3px; }
.title-foot {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; max-width: 92vw;
  padding: 6px 14px; background: rgba(10,9,8,0.55); border: 1px solid rgba(59,52,43,0.6); border-radius: 3px; font-size: 14px;
}
.title-foot kbd { font-size: 12px; min-width: 18px; margin-right: 4px; padding: 0 4px; }

/* Character creator polish */
.creator { gap: 12px; }
.creator-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; border-bottom: 1px solid var(--panel-edge); padding-bottom: 8px; }
.creator-preview canvas { box-shadow: 0 10px 30px rgba(0,0,0,0.55); border-radius: 2px; }
.creator-form { background: rgba(10,9,8,0.5); border: 1px solid rgba(59,52,43,0.6); padding: 10px 14px 14px; }
.creator-form label:first-child { margin-top: 0; }
.chip.sel, .sw.sel { position: relative; }
.bg-card { transition: border-color 0.12s, background 0.12s; }
@media (min-height: 900px) { .creator-preview canvas { width: 340px; height: 430px; } .creator-preview { flex-basis: 340px; } }

/* Large screens: scale the HUD up a touch so it doesn't shrink to postage stamps */
@media (min-width: 1800px) and (min-height: 1000px) {
  :root { --hud-auto-scale: 1.15; }
  #hud #q-tracker { width: 300px; }
  #hud #q-tracker .qt-title { font-size: 19px; }
  #hud #q-tracker .qt-obj { font-size: 18px; }
  #ui-root #toasts { width: 380px; }
  #toasts .toast { font-size: 19px; }
  #prompt { font-size: 22px; }
}

/* Character creator: drawbacks read as drawbacks */
.cr-minus { color: var(--blood-bright) !important; }

/* ======================= Touch & gamepad controls (src/touch) ======================= */
#touch-ui {
  position: fixed; inset: 0; z-index: 45; pointer-events: none;
  touch-action: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  --tc-r: env(safe-area-inset-right, 0px); --tc-l: env(safe-area-inset-left, 0px); --tc-b: env(safe-area-inset-bottom, 0px); --tc-t: env(safe-area-inset-top, 0px);
}
#touch-ui > * { pointer-events: auto; }
#touch-ui .tc-zone { position: absolute; top: 0; bottom: 0; touch-action: none; }
#touch-ui .tc-move { left: 0; width: 45%; }
#touch-ui .tc-look { right: 0; width: 55%; }
#touch-ui .tc-stick {
  position: absolute; width: calc(var(--tc-stick, 116px)); height: calc(var(--tc-stick, 116px)); transform: translate(-50%, -50%);
  border-radius: 50%; border: 2px solid rgba(230,223,207,0.35); background: radial-gradient(circle, rgba(20,17,14,0.35), rgba(20,17,14,0.55));
  pointer-events: none; box-shadow: 0 0 0 1px rgba(0,0,0,0.4);
}
#touch-ui .tc-stick.idle { left: calc(24px + var(--tc-l) + var(--tc-stick, 116px) / 2); top: auto; bottom: calc(24px + var(--tc-b) - var(--tc-stick, 116px) / 2); opacity: 0.45; }
#touch-ui .tc-stick.run { border-color: var(--blood-bright); }
#touch-ui .tc-knob {
  position: absolute; left: 50%; top: 50%; width: 48%; height: 48%; border-radius: 50%; transform: translate(-50%, -50%);
  background: rgba(230,223,207,0.75); box-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
#touch-ui .tc-stick.run .tc-knob { background: var(--blood-bright); }

#touch-ui .tc-btn {
  position: absolute; display: flex; align-items: center; justify-content: center; padding: 0;
  width: 58px; height: 58px; border-radius: 50%; touch-action: none; cursor: pointer;
  background: rgba(16,14,12,0.62); color: var(--bone); border: 2px solid rgba(230,223,207,0.38);
  font-family: var(--font-body); font-weight: 800; font-size: 14px; letter-spacing: 0.5px; text-transform: uppercase;
  text-shadow: 1px 1px 0 #000; box-shadow: 0 3px 10px rgba(0,0,0,0.5); -webkit-user-select: none; user-select: none;
}
#touch-ui .tc-btn.on { background: rgba(179,38,30,0.75); border-color: var(--blood-bright); transform: scale(0.94); }
#touch-ui .tc-btn.hot { border-color: var(--toxic); box-shadow: 0 0 0 3px rgba(165,194,52,0.35), 0 3px 10px rgba(0,0,0,0.5); }
#touch-ui .tc-cluster { position: absolute; right: calc(10px + var(--tc-r)); bottom: calc(10px + var(--tc-b)); width: 200px; height: 190px; pointer-events: none; }
#touch-ui .tc-cluster > * { pointer-events: auto; }
#touch-ui .tc-attack { right: 6px; bottom: 6px; width: 84px; height: 84px; font-size: 16px; background: rgba(110,22,16,0.62); border-color: rgba(226,64,47,0.7); }
#touch-ui .tc-jump { right: 100px; bottom: 4px; }
#touch-ui .tc-use { right: 18px; bottom: 102px; }
#touch-ui .tc-car { right: 88px; bottom: 76px; width: 52px; height: 52px; }
body.tc-prompt-tagged #prompt { display: none; }
#touch-ui .tc-cluster .tc-usetag.car { right: 70px; }
#touch-ui .tc-usetag {
  position: absolute; right: 0; bottom: 166px; max-width: min(56vw, 250px); padding: 4px 10px;
  background: rgba(10,9,8,0.85); border: 1px solid var(--toxic); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
#touch-ui .tc-sys { position: absolute; right: calc(12px + var(--tc-r)); bottom: calc(206px + var(--tc-b)); display: flex; gap: 10px; pointer-events: none; }
#touch-ui .tc-sys > * { pointer-events: auto; }
#touch-ui .tc-small { position: static; width: 44px; height: 44px; font-size: 13px; }
#touch-ui .tc-small.sel { border-color: var(--toxic); color: var(--toxic); }
#touch-ui .tc-tray {
  position: absolute; right: calc(12px + var(--tc-r)); bottom: calc(260px + var(--tc-b));
  display: grid; grid-template-columns: repeat(6, 52px); gap: 8px; padding: 8px;
  background: rgba(12,10,9,0.8); border: 1px solid var(--panel-edge); box-shadow: 0 6px 24px rgba(0,0,0,0.6);
}
#touch-ui .tc-tray .tc-btn { position: static; width: 52px; height: 52px; border-radius: 10px; font-size: 12px; line-height: 1.05; text-align: center; }
#touch-ui.photo .tc-cluster, #touch-ui.photo .tc-tray, #touch-ui.photo .tc-stick, #touch-ui.photo [data-id="more"] { display: none; }

/* make room for the controls: HUD corners move up, the prompt clears the buttons */
body.touch-ui .hud-br { bottom: calc(250px + env(safe-area-inset-bottom, 0px)); }
body.touch-ui .hud-bl { bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }
body.touch-ui #prompt { bottom: calc(150px + env(safe-area-inset-bottom, 0px)); max-width: 60vw; font-size: 17px; }

/* landscape phones: tray beside the buttons, smaller HUD */
@media (max-height: 520px) {
  body.touch-ui { --hud-auto-scale: 0.72; }
  body.touch-ui #minimap { width: 120px; height: 120px; }
  #touch-ui .tc-sys { bottom: calc(10px + var(--tc-b)); right: calc(220px + var(--tc-r)); flex-direction: column-reverse; }
  #touch-ui .tc-tray { bottom: calc(10px + var(--tc-b)); right: calc(276px + var(--tc-r)); grid-template-columns: repeat(6, 48px); gap: 6px; }
  #touch-ui .tc-tray .tc-btn { width: 48px; height: 48px; }
  body.touch-ui .hud-br { bottom: calc(112px + env(safe-area-inset-bottom, 0px)); right: calc(214px + env(safe-area-inset-right, 0px)); }
  body.touch-ui .hud-bl { bottom: calc(140px + env(safe-area-inset-bottom, 0px)); }
  body.touch-ui #prompt { bottom: calc(14px + env(safe-area-inset-bottom, 0px)); max-width: 36vw; font-size: 15px; }
  body.tc-prompt-tagged #prompt { display: block; }
  #touch-ui .tc-usetag { display: none; }
  body.touch-ui #hud #q-tracker { top: calc(8px + env(safe-area-inset-top, 0px)); right: calc(150px + env(safe-area-inset-right, 0px)); width: min(240px, 32vw); }
}
/* narrow portrait phones */
@media (max-width: 520px) {
  #touch-ui .tc-tray { grid-template-columns: repeat(5, 52px); }
}

/* dialogs / panels: finger-sized targets on touch screens */
@media (pointer: coarse) {
  .ui-opt, .ui-btn, .ph-row, .tab, .chip { min-height: 44px; }
  .ui-x { width: 44px; height: 44px; top: 6px; right: 6px; font-size: 20px; }
  .ui-title { padding-right: 46px; }
  .sw { width: 40px; height: 40px; }
  .hud-bubble { min-height: 40px; }
  .ph-back { min-width: 44px; min-height: 44px; }
}
body.touch-ui .ui-opt, body.touch-ui .ui-btn, body.touch-ui .ph-row, body.touch-ui .tab, body.touch-ui .chip { min-height: 44px; }
body.touch-ui .ui-x { width: 44px; height: 44px; top: 6px; right: 6px; font-size: 20px; }
body.touch-ui .ui-title { padding-right: 46px; }
@media (max-width: 700px), (max-height: 520px) {
  .ui-modal { padding: max(8px, env(safe-area-inset-top, 0px)) max(8px, env(safe-area-inset-right, 0px)) max(8px, env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px)); }
  .ui-panel { max-height: 100%; padding: 14px 14px 12px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; }
  .ui-title { font-size: 23px; }
  .ui-body canvas { max-width: 100%; height: auto !important; }
}

/* gamepad focus ring (menus / dialogs) */
.pad-focus { outline: 3px solid var(--toxic) !important; outline-offset: 2px; box-shadow: 0 0 0 6px rgba(165,194,52,0.25) !important; }
.ui-opt.pad-focus, .ui-btn.pad-focus { background: #2a231b; border-color: var(--rust); }

/* ======================= Presentation (src/present): portraits, typewriter, moments, cards ======================= */
/* Panel transitions: fresh panels fade/rise in, chained pages cross-fade, closing panels fade out. */
.ui-modal.ui-enter { animation: prBackIn 0.16s ease-out; }
.ui-modal.ui-enter > .ui-panel { animation: prPanelIn 0.2s cubic-bezier(.2,.9,.3,1); }
.ui-modal.ui-chain > .ui-panel { animation: prPanelChain 0.12s ease-out; }
.ui-modal.ui-closing { pointer-events: none !important; opacity: 0; transition: opacity 0.14s ease-in; }
.ui-modal.ui-closing * { pointer-events: none !important; }
@keyframes prBackIn { from { background-color: rgba(0,0,0,0); } }
@keyframes prPanelIn { from { opacity: 0; transform: translateY(8px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes prPanelChain { from { opacity: 0.55; } to { opacity: 1; } }

/* Dialog layout: portrait to the left of speaker + text, options full width below */
.ui-dlg-head { display: flex; gap: 14px; align-items: flex-start; }
.ui-dlg-main { flex: 1; min-width: 0; }
.ui-dlg.has-portrait .ui-dlg-main { min-height: 100px; }
.pr-portrait {
  position: relative; flex: 0 0 84px; width: 84px; height: 100px; overflow: hidden;
  background: #0b0a09; border: 1px solid var(--panel-edge);
  box-shadow: 0 4px 14px rgba(0,0,0,0.55), inset 0 0 0 1px rgba(0,0,0,0.6);
  animation: prPortraitIn 0.25s ease-out;
}
.pr-portrait::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 -18px 18px -14px rgba(0,0,0,0.7);
  border-bottom: 2px solid rgba(179,38,30,0.55);
}
.pr-portrait canvas { display: block; width: 100%; height: 100%; }
@keyframes prPortraitIn { from { opacity: 0; transform: translateX(-4px); } to { opacity: 1; transform: none; } }
.ui-dlg .ui-speaker { line-height: 1.15; }

/* Typewriter: the untyped remainder keeps its space so nothing reflows */
.tw-rest { color: transparent !important; text-shadow: none !important; }
.ui-dlg .ui-opts { transition: opacity 0.2s ease-out; }
.ui-dlg.tw-on .ui-opts { opacity: 0.55; }
.ui-dlg.tw-on .ui-dlg-head { cursor: pointer; }

/* Interaction prompt: [E] + type icon + verb + name */
#prompt { display: flex; align-items: center; justify-content: center; gap: 0; }
#prompt.hidden { display: none !important; }
#prompt kbd { flex: 0 0 auto; }
.pr-pi { display: inline-flex; color: var(--rust); margin: 0 6px 0 2px; }
.pr-pv { color: var(--bone-dim); white-space: pre; }
.pr-pn { color: var(--bone); }
.pr-ico { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.pr-pi .pr-ico { width: 18px; height: 18px; }

/* Notification stack: repeats count up, leavers collapse instead of jumping */
#toasts .toast { overflow: hidden; }
#toasts .toast.out { opacity: 0; max-height: 0 !important; padding-top: 0; padding-bottom: 0; margin-top: -5px;
  transition: opacity 0.25s ease-in, max-height 0.3s ease-in 0.1s, padding 0.3s ease-in 0.1s, margin 0.3s ease-in 0.1s; }
#toasts .toast.out.fast { transition: opacity 0.15s, max-height 0.2s, padding 0.2s, margin 0.2s; }
.toast .toast-n { display: inline-block; margin-left: 8px; padding: 0 5px; font-size: 13px; font-weight: 800; color: var(--ink); background: var(--bone-dim); border-radius: 2px; vertical-align: 1px; }
#toasts .toast.bump { animation: prBump 0.25s ease-out; }
@keyframes prBump { 0% { transform: scale(1.04); } 100% { transform: none; } }

/* Story moments: letterbox + caption; the HUD steps aside */
#pr-cine { position: absolute; inset: 0; pointer-events: none; }
#pr-cine .pr-bar { position: absolute; left: 0; right: 0; height: 11vh; background: #000; transition: transform 0.6s cubic-bezier(.2,.8,.2,1); }
#pr-cine .pr-bar.top { top: 0; transform: translateY(-101%); }
#pr-cine .pr-bar.bot { bottom: 0; transform: translateY(101%); display: flex; align-items: center; justify-content: center; }
#pr-cine.on .pr-bar { transform: none; }
.pr-cap { text-align: center; max-width: min(760px, 86vw); opacity: 0; transition: opacity 0.5s 0.35s; }
#pr-cine.on.has-cap .pr-cap { opacity: 1; }
#pr-cine:not(.on) .pr-cap { transition-delay: 0s; transition-duration: 0.2s; }
.pr-cap-who { font-size: 13px; letter-spacing: 4px; text-transform: uppercase; color: var(--toxic); }
.pr-cap-who:empty { display: none; }
.pr-cap-line { font-family: var(--font-title); font-size: 21px; color: var(--bone); margin-top: 2px; }
.pr-skip { position: absolute; right: 18px; bottom: 12px; font-size: 13px; color: #6d675c; opacity: 0; transition: opacity 0.4s 1s; }
.pr-skip kbd { font-size: 11px; min-width: 0; padding: 0 4px; margin-right: 5px; background: #3a352d; color: #b9b2a2; }
#pr-cine.on .pr-skip { opacity: 1; }
body.touch-ui .pr-skip { display: none; }
#hud, #prompt { transition: opacity 0.35s; }
body.pr-cine-on #hud, body.pr-cine-on #prompt { opacity: 0; }

/* Chapter title card */
#pr-card {
  position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%); width: min(720px, 92vw);
  text-align: center; pointer-events: none; padding: 26px 20px 22px;
  background: radial-gradient(ellipse 60% 55% at 50% 50%, rgba(5,4,3,0.62), rgba(5,4,3,0) 100%);
}
#pr-card .pr-card-k { font-size: 15px; letter-spacing: 7px; text-transform: uppercase; color: var(--bone-dim); text-shadow: 0 2px 6px #000; }
#pr-card .pr-card-t { font-family: var(--font-title); font-size: clamp(38px, 6.4vw, 66px); line-height: 1.05; color: var(--bone); margin-top: 6px;
  letter-spacing: 2px; text-shadow: 3px 3px 0 #000, 0 0 28px rgba(0,0,0,0.8); }
#pr-card .pr-card-u { display: block; width: min(440px, 80%); height: 18px; margin: 4px auto 8px; color: var(--blood); overflow: visible; }
#pr-card .pr-card-u path { stroke-dasharray: 420; stroke-dashoffset: 420; }
#pr-card .pr-card-s { font-size: 19px; color: #cfc6b2; text-shadow: 0 2px 6px #000, 1px 1px 0 #000; max-width: 560px; margin: 0 auto; }
#pr-card.in .pr-card-k { animation: prFade 0.7s ease-out both; }
#pr-card.in .pr-card-t { animation: prTitle 0.9s cubic-bezier(.2,.8,.2,1) 0.1s both; }
#pr-card.in .pr-card-u path { animation: prStroke 0.7s ease-out 0.55s forwards; }
#pr-card.in .pr-card-s { animation: prFade 0.8s ease-out 0.75s both; }
#pr-card.out { opacity: 0; transition: opacity 0.6s ease-in; }
@keyframes prFade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes prTitle { from { opacity: 0; letter-spacing: 12px; filter: blur(3px); } to { opacity: 1; letter-spacing: 2px; filter: none; } }
@keyframes prStroke { to { stroke-dashoffset: 0; } }

@media (max-width: 600px) {
  .pr-portrait { flex-basis: 60px; width: 60px; height: 72px; }
  .ui-dlg.has-portrait .ui-dlg-main { min-height: 72px; }
  .ui-dlg-head { gap: 10px; }
  .pr-cap-line { font-size: 17px; }
  #pr-cine .pr-bar { height: 8vh; }
}
@media (prefers-reduced-motion: reduce) {
  .ui-modal.ui-enter, .ui-modal.ui-enter > .ui-panel, .ui-modal.ui-chain > .ui-panel, .pr-portrait { animation: none; }
}
.npc-bubble { transition: opacity 0.3s; }
body.pr-card-on .npc-bubble { opacity: 0 !important; }
