/* APORIA — in-play HUD, interaction prompt, toasts, dialogue, touch controls. */

/* ── HUD ──────────────────────────────────────────────────────────────── */
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud-top {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 14px 0;
}
.hud-case { padding: 8px 14px 9px; min-width: 170px; max-width: 300px; }
.hud-kicker { font-size: 11px; font-weight: 900; letter-spacing: .24em; color: var(--yellow); }
.hud-title {
  font-size: 15px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-time { display: flex; gap: 6px; align-items: center; font-size: 14px; color: var(--cyan); font-weight: 700; }
.hud-time > span:first-child { font-family: var(--emoji); font-size: 12px; }
.hud-stats { display: flex; align-items: center; gap: 18px; padding: 9px 14px; }
.hud-integrity { width: 150px; }
.hud-int-label { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; font-weight: 900; letter-spacing: .18em; margin-bottom: 5px; color: var(--ink-dim); }
.hud-int-val { color: var(--ink); letter-spacing: .04em; font-size: 13px; }
.hud-counters { display: flex; gap: 14px; }
.stat { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; font-size: 15px; }
.stat-icon { font-size: 16px; }
.hud-buttons { margin-left: auto; display: flex; gap: 12px; pointer-events: auto; }
.btn-hud { position: relative; }
.hud-badge {
  position: absolute;
  top: -9px; right: -9px;
  min-width: 22px; height: 22px;
  display: grid;
  place-items: center;
  padding: 0 4px;
  font-size: 12px;
  font-weight: 900;
  color: var(--yellow-ink);
  background: var(--yellow);
  box-shadow: var(--notch2), 2px 2px 0 rgba(0, 0, 0, .5);
  animation: bob 1s steps(2) infinite;
}
.hud-next {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 12px 14px 0;
  padding: 5px 10px 6px 6px;
  font-size: 13px;
  background: rgba(6, 10, 20, .78);
  box-shadow: inset 0 0 0 1px var(--line);
  text-shadow: 1px 1px 0 var(--outline);
  max-width: calc(100% - 28px);
}
.hud-next-tag {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .14em;
  padding: 2px 5px;
  color: var(--cyan-ink);
  background: var(--cyan);
}
.hud-prompt {
  position: absolute;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px 11px;
  font-size: 16px;
  font-weight: 800;
  white-space: nowrap;
  max-width: calc(100% - 28px);
  box-shadow: inset 0 0 0 2px var(--cyan), var(--notch), var(--drop);
}
.hud-prompt .keycap { font-size: 14px; padding: 4px 8px 6px; background: var(--cyan); color: var(--cyan-ink); box-shadow: inset 0 -3px 0 var(--cyan-2), 0 0 0 2px var(--outline); animation: bob .9s steps(2) infinite; }
.hud-prompt.pop { animation: prompt-pop .2s steps(3); }
.prompt-verb { color: var(--ink-dim); text-transform: uppercase; letter-spacing: .1em; font-size: 13px; }
.prompt-verb.dim { color: var(--ink-faint); }
.prompt-name { color: var(--yellow); overflow: hidden; text-overflow: ellipsis; }
.prompt-check { color: var(--green); font-size: 18px; }
.hud-prompt.is-collected { box-shadow: inset 0 0 0 2px var(--green), var(--notch), var(--drop); }
.hud-prompt.is-collected .prompt-name { color: var(--green); }
.hud-prompt.is-collected .keycap { background: var(--bg3); color: var(--ink); box-shadow: inset 0 -3px 0 #000, 0 0 0 2px var(--outline); animation: none; }
.hud.is-blocked .hud-prompt, .hud.is-blocked .hud-next { visibility: hidden; }
@keyframes prompt-pop { from { transform: translateX(-50%) translateY(8px); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }

/* ── toasts ───────────────────────────────────────────────────────────── */
.toasts {
  position: absolute;
  right: 14px;
  top: 86px;
  z-index: 40;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100% - 28px));
  pointer-events: none;
}
html[data-phase="title"] .toasts, html[data-phase="cases"] .toasts, html[data-phase="debrief"] .toasts, html[data-phase="briefing"] .toasts { top: 14px; }
.toast {
  --tc: var(--cyan);
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 14px 11px 12px;
  background: var(--bg1);
  background-image: var(--scan);
  box-shadow: inset 4px 0 0 var(--tc), inset 0 0 0 2px var(--line), var(--notch2), 4px 5px 0 rgba(0, 0, 0, .5);
  pointer-events: auto;
  cursor: pointer;
  animation: toast-in .24s steps(4);
}
.toast.is-leaving { animation: toast-out .24s steps(3) forwards; }
.toast-icon { font-size: 22px; flex: none; margin-top: 1px; }
.toast-title { font-weight: 900; font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--tc); }
.toast-text { font-size: 14px; color: var(--ink); overflow-wrap: anywhere; }
.toast-good { --tc: var(--green); }
.toast-bad { --tc: var(--red); }
.toast-clue, .toast-evidence { --tc: var(--yellow); }
.toast-concept { --tc: var(--purple); }
/* While a modal is open, toasts shrink into the bottom-left corner and never block clicks. */
html.has-modal #ui .toasts { top: auto; right: auto; left: 12px; bottom: 12px; width: min(300px, calc(100% - 24px)); gap: 6px; }
html.has-modal #ui .toast { pointer-events: none; padding: 7px 10px 8px 10px; gap: 9px; opacity: .96; }
html.has-modal #ui .toast:nth-last-child(n+3) { display: none; }
html.has-modal .toast-icon { font-size: 17px; }
html.has-modal .toast-title { font-size: 12px; }
html.has-modal .toast-text { font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
@keyframes toast-in { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-out { to { transform: translateX(40px); opacity: 0; } }

/* ── dialogue ─────────────────────────────────────────────────────────── */
.dialogue-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 16px 16px max(22px, env(safe-area-inset-bottom));
  pointer-events: auto;
  cursor: pointer;
  background: linear-gradient(180deg, transparent 45%, rgba(4, 7, 15, .78) 100%);
}
.dlg-kicker {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 16px 8px;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .24em;
  white-space: nowrap;
  max-width: calc(100% - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--yellow-ink);
  background: var(--yellow);
  box-shadow: inset 0 -3px 0 var(--yellow-2), var(--notch), var(--drop);
  /* hazard-stripe edges */
  background-image: linear-gradient(90deg, var(--outline) 0 6px, transparent 6px calc(100% - 6px), var(--outline) calc(100% - 6px));
}
.dialogue {
  display: flex;
  gap: 18px;
  align-items: stretch;
  width: min(920px, 100%);
  padding: 18px 20px 14px;
  margin-top: 22px;
  cursor: pointer;
  box-shadow: inset 0 0 0 2px var(--line-hi), inset 0 4px 0 rgba(255, 255, 255, .03), var(--notch), var(--drop);
}
.dialogue:focus { outline: none; }
.dialogue.pop { animation: pop-in .18s steps(3); }
.dlg-portrait {
  flex: none;
  width: 104px;
  height: 104px;
  display: grid;
  place-items: center;
  font-size: 62px;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .04) 0 2px, transparent 2px 4px),
    linear-gradient(180deg, #23417a, #10213f);
  box-shadow: inset 0 0 0 2px var(--cyan-2), inset 0 -10px 0 rgba(0, 0, 0, .25), var(--notch2);
  align-self: flex-start;
}
.dlg-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dlg-nameplate { display: flex; align-items: baseline; gap: 10px; margin: -32px 0 10px; }
.dlg-name, .report-intro .dlg-name {
  display: inline-block;
  padding: 5px 12px 6px;
  font-size: 15px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--cyan-ink);
  background: var(--cyan);
  box-shadow: inset 0 -3px 0 var(--cyan-2), var(--notch2), 3px 4px 0 rgba(0, 0, 0, .5);
}
.dlg-role { font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .12em; padding: 3px 7px; background: var(--bg1); box-shadow: inset 0 0 0 1px var(--line-hi); }
.dlg-text {
  margin: 0;
  min-height: 3.4em;
  font-size: 18px;
  line-height: 1.55;
  text-shadow: 1px 1px 0 var(--outline);
  overflow-wrap: anywhere;
}
.dlg-caret { display: inline-block; width: .55em; height: 1em; margin-left: 2px; vertical-align: -2px; background: var(--cyan); animation: blink .7s steps(2) infinite; }
.dialogue.is-done .dlg-caret { display: none; }
.dlg-foot { display: flex; align-items: center; gap: 14px; margin-top: 10px; font-size: 13px; color: var(--ink-faint); }
.dlg-count { color: var(--ink-dim); font-weight: 800; }
.dlg-hint { flex: 1; }
.dlg-next { position: absolute; right: 18px; bottom: -12px; font-size: 18px; color: var(--yellow); text-shadow: 2px 2px 0 var(--outline); opacity: 0; }
.dialogue.is-done .dlg-next { opacity: 1; animation: bob .6s steps(2) infinite; }

/* ── touch controls ───────────────────────────────────────────────────── */
.touch-controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  pointer-events: none;
  z-index: 5;
}
.joy-base {
  position: relative;
  width: 136px;
  height: 136px;
  display: grid;
  place-items: center;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.joy-ring {
  position: absolute;
  inset: 12px;
  background: rgba(6, 10, 20, .55);
  box-shadow: inset 0 0 0 3px rgba(62, 230, 255, .45), var(--notch);
  clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%);
}
.joy-knob {
  position: relative;
  width: 52px;
  height: 52px;
  background: var(--cyan);
  box-shadow: inset 0 -5px 0 var(--cyan-2), inset 0 3px 0 rgba(255, 255, 255, .5), var(--notch2);
  opacity: .85;
}
.joy-base.is-active .joy-knob { opacity: 1; }
.touch-right { display: grid; gap: 12px; justify-items: end; pointer-events: none; }
.touch-row { display: flex; gap: 12px; }
.touch-btn {
  pointer-events: auto;
  border: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  color: var(--ink);
  background: rgba(20, 29, 54, .88);
  box-shadow: inset 0 0 0 2px var(--line-hi), inset 0 -4px 0 rgba(0, 0, 0, .4), var(--notch2), 3px 4px 0 rgba(0, 0, 0, .5);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.touch-btn:active { transform: translate(2px, 2px); }
.touch-small { width: 56px; height: 56px; }
.touch-small .touch-glyph { font-size: 22px; }
.touch-interact { width: 92px; height: 92px; }
.touch-interact .touch-glyph { font-size: 32px; }
.touch-interact.is-ready {
  background: var(--cyan);
  color: var(--cyan-ink);
  box-shadow: inset 0 -5px 0 var(--cyan-2), inset 0 3px 0 rgba(255, 255, 255, .45), var(--notch2), 3px 4px 0 rgba(0, 0, 0, .5);
  animation: bob .9s steps(2) infinite;
}
.touch-label { font-size: 11px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }

/* ── responsive ───────────────────────────────────────────────────────── */
html.is-touch .hud-buttons .keycap, html.is-touch .dlg-hint .keycap { display: none; }
@media (max-width: 1000px) {
  .hud-buttons .btn-label { display: none; }
  .hud-buttons .btn { padding-left: 12px; padding-right: 12px; }
}
@media (max-width: 760px), (max-height: 500px) {
  .hud-top { gap: 10px; padding: 10px 10px 0; }
  .hud-case { min-width: 0; max-width: 220px; padding: 6px 10px 7px; }
  .hud-kicker { display: none; }
  .hud-title { font-size: 13px; }
  .hud-stats { gap: 12px; padding: 7px 10px; }
  .hud-integrity { width: 110px; }
  .hud-counters { gap: 10px; }
  .stat { font-size: 14px; }
  .hud-buttons { gap: 10px; }
  .hud-buttons .keycap { display: none; }
  .btn-hud { min-height: 38px; padding: 6px 10px 9px; }
  .hud-next { margin: 8px 10px 0; font-size: 12px; }
  .toasts { top: 66px; right: 10px; width: min(320px, calc(100% - 20px)); }
  .toast-text { font-size: 13px; }
  .hud-prompt { bottom: 20px; font-size: 14px; padding: 8px 14px 9px; }
  .dialogue { gap: 12px; padding: 14px 14px 10px; }
  .dlg-portrait { width: 64px; height: 64px; font-size: 38px; }
  .dlg-text { font-size: 15px; min-height: 3em; }
  .dlg-nameplate { margin-top: -28px; }
  .dlg-kicker { top: 10px; font-size: 11px; }
}
/* touch: keep the prompt clear of the joystick / buttons */
html.is-touch .hud-prompt { bottom: 200px; }
@media (max-height: 500px) {
  .hud-next { display: none; }
  html.is-touch .hud-prompt { bottom: 22px; max-width: calc(100% - 420px); }
  .dialogue-layer { padding-bottom: 10px; }
}
@media (max-width: 560px) {
  .hud-top { flex-wrap: wrap; }
  .hud-case { order: 1; flex: 1 1 auto; max-width: none; }
  .hud-buttons { order: 2; margin-left: 0; }
  .hud-stats { order: 3; flex: 1 1 100%; justify-content: space-between; }
  .hud-integrity { flex: 1; max-width: 160px; }
  .toasts { top: auto; bottom: 250px; }
  html:not(.is-touch) .toasts { bottom: 80px; }
}

@media (max-width: 700px), (max-height: 520px) {
  html.has-modal #ui .toasts { width: min(270px, calc(100% - 24px)); left: 8px; bottom: 8px; }
  html.has-modal #ui .toast:nth-last-child(n+3) { display: none; }
  html.has-modal .toast-text { -webkit-line-clamp: 1; }
}

/* ── story dialogues: beats, prologue, intro, epilogue (js/ui/story.js) ─── */
.dlg-nameplate { min-width: 0; }
.dlg-role { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialogue-layer[data-tone] { --tone: var(--yellow); --tone-2: var(--yellow-2); --tone-ink: var(--yellow-ink); }
.dialogue-layer.tone-call { --tone: var(--green); --tone-2: var(--green-2); --tone-ink: #021a0c; }
.dialogue-layer.tone-radio { --tone: var(--orange); --tone-2: #9a4f0c; --tone-ink: #1f0e00; }
.dialogue-layer.tone-text { --tone: var(--purple); --tone-2: #6c4bb3; --tone-ink: #12072a; }
.dialogue-layer.tone-scene { --tone: #dfe7f6; --tone-2: var(--ink-dim); --tone-ink: var(--outline); }
.dialogue-layer.tone-solved { --tone: var(--green); --tone-2: var(--green-2); --tone-ink: #021a0c; }
.dialogue-layer.tone-unsolved { --tone: var(--red); --tone-2: var(--red-2); --tone-ink: #1b0306; }
.dialogue-layer[data-tone] .dlg-kicker {
  color: var(--tone-ink);
  background-color: var(--tone);
  box-shadow: inset 0 -3px 0 var(--tone-2), var(--notch), var(--drop);
}
/* In play the HUD owns the top of the screen: a beat's kicker sits on top of its dialogue box. */
.dialogue-layer[data-tone]:not(.is-cinematic) .dlg-kicker {
  position: relative;
  top: auto; left: auto;
  transform: none;
  margin-bottom: 4px;
  font-size: 12px;
}
.dialogue-layer[data-tone] .dialogue {
  box-shadow: inset 0 0 0 2px var(--tone-2), inset 0 5px 0 var(--tone), var(--notch), var(--drop);
}
.dialogue-layer[data-tone] .dlg-portrait {
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .04) 0 2px, transparent 2px 4px),
    linear-gradient(180deg, color-mix(in srgb, var(--tone) 34%, #10213f), #0b1730);
  box-shadow: inset 0 0 0 2px var(--tone), inset 0 -10px 0 rgba(0, 0, 0, .25), var(--notch2);
}
.dialogue-layer[data-tone] .dlg-caret { background: var(--tone); }
/* status tab on the box (LIVE CALL / CH 3 / WORK PHONE / ON SCENE) */
.dlg-tag {
  position: absolute;
  top: -15px;
  right: 22px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 5px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .18em;
  white-space: nowrap;
  color: var(--tone-ink, var(--yellow-ink));
  background: var(--tone, var(--yellow));
  box-shadow: inset 0 -2px 0 var(--tone-2, var(--yellow-2)), var(--notch2), 3px 4px 0 rgba(0, 0, 0, .5);
  pointer-events: none;
}
.dlg-tag-dot { width: 8px; height: 8px; background: currentColor; flex: none; animation: blink 1s steps(2) infinite; }
/* call: the phone buzzes in */
.tone-call .dlg-kicker { animation: buzz .32s steps(4) 3; }
.tone-call .dlg-portrait { animation: ring .5s steps(4) 2 .1s; }
/* radio: signal bars + a faint static texture */
.tone-radio .dlg-tag-dot {
  width: 13px; height: 10px;
  background:
    linear-gradient(currentColor, currentColor) 0 100% / 3px 40% no-repeat,
    linear-gradient(currentColor, currentColor) 5px 100% / 3px 70% no-repeat,
    linear-gradient(currentColor, currentColor) 10px 100% / 3px 100% no-repeat;
  animation: blink 1.4s steps(2) infinite;
}
.tone-radio .dialogue {
  background-image: var(--scan), repeating-linear-gradient(90deg, rgba(255, 154, 60, .05) 0 2px, transparent 2px 7px, rgba(255, 154, 60, .03) 7px 8px, transparent 8px 13px);
  animation: static-in .3s steps(3);
}
/* text message: the line sits in a chat bubble */
.tone-text .dlg-text {
  position: relative;
  align-self: flex-start;
  max-width: 100%;
  padding: 8px 14px 9px;
  margin-left: 10px;
  background: rgba(180, 140, 255, .13);
  box-shadow: inset 0 0 0 2px rgba(180, 140, 255, .45), 3px 3px 0 rgba(0, 0, 0, .35);
}
.tone-text .dlg-text::before { /* bubble tail */
  content: "";
  position: absolute;
  left: -10px; top: 10px;
  width: 10px; height: 10px;
  background: rgba(180, 140, 255, .45);
  clip-path: polygon(100% 0, 0 0, 100% 100%);
}
.tone-text .dlg-tag-dot { width: 10px; height: 8px; clip-path: polygon(0 0, 100% 0, 100% 75%, 35% 75%, 0 100%); }
/* scene: someone walks up in person */
.tone-scene .dlg-tag-dot { width: 6px; height: 9px; box-shadow: 5px -3px 0 currentColor; margin-right: 5px; animation: bob .8s steps(2) infinite; }
/* cinematic: letterbox bars for the campaign intro, prologues and epilogues */
.dialogue-layer.is-cinematic { background: linear-gradient(180deg, rgba(4, 7, 15, .45) 0%, transparent 28%, transparent 42%, rgba(4, 7, 15, .84) 100%); }
.dialogue-layer.is-cinematic::before,
.dialogue-layer.is-cinematic::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  z-index: -1;
  height: clamp(22px, 8vh, 70px);
  background: var(--outline);
  animation: letterbox .36s steps(4) both;
}
.dialogue-layer.is-cinematic::before { top: 0; transform-origin: top; box-shadow: 0 3px 0 rgba(255, 210, 63, .25); }
.dialogue-layer.is-cinematic::after { bottom: 0; transform-origin: bottom; }
.tone-solved.is-cinematic::before { box-shadow: 0 3px 0 rgba(69, 224, 138, .35); }
.tone-unsolved.is-cinematic::before { box-shadow: 0 3px 0 rgba(255, 77, 94, .35); }
@keyframes letterbox { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes buzz {
  0%, 100% { transform: none; }
  25% { transform: translateX(-3px) rotate(-1deg); }
  75% { transform: translateX(3px) rotate(1deg); }
}
@keyframes ring { 0%, 100% { transform: none; } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }
@keyframes static-in { 0% { filter: brightness(1.8) contrast(1.4); } 50% { filter: brightness(.7); } 100% { filter: none; } }
/* the sound dock never covers a story dialogue */
html[data-phase="intro"] .sound-dock, html[data-phase="epilogue"] .sound-dock { display: none; }
@media (max-width: 760px), (max-height: 500px) {
  .dialogue-layer[data-tone] .dlg-kicker, .dialogue-layer.is-cinematic .dlg-kicker { letter-spacing: .14em; padding: 6px 12px 7px; }
  .dlg-tag { top: -13px; right: 14px; padding: 3px 8px 4px; font-size: 10px; letter-spacing: .14em; }
  .tone-text .dlg-text { padding: 6px 10px 7px; }
}
@media (max-width: 560px) {
  .dlg-tag-text { display: none; }
  .dlg-tag { padding: 5px 7px; }
}
