/* ==========================================================================
   TRIAGE QUEST+ (Gen Z Edition) — Cozy Pop Tactile + Floating Command HUD
   ========================================================================== */

:root {
  --bg-cream: #f4f7f1;
  --bg-mint: #dff4ea;
  --ink: #17323b;
  --ink-soft: #4e6b75;
  --ink-muted: #728c96;
  --surface: #ffffff;
  --surface-warm: #fffdf6;
  --teal: #10b981;
  --teal-dark: #0b8a64;
  --cyan: #06b6d4;
  --gold: #f59e0b;
  --gold-soft: #fef3c7;
  --coral: #ff5a6e;
  --purple: #8b5cf6;

  /* Triage Tag Colors */
  --p1-ink: #b91c34;
  --p1-bg: #ffe5e9;
  --p1-accent: #f43f5e;
  --p2-ink: #8a5600;
  --p2-bg: #fff5cc;
  --p2-accent: #f59e0b;
  --p3-ink: #0f6b4a;
  --p3-bg: #ddf9ec;
  --p3-accent: #10b981;
  --dead-ink: #2a3342;
  --dead-bg: #e5e9f0;
  --dead-accent: #475569;

  /* Cozy Neo-Brutalist Tactile Tokens */
  --border-w: 2.5px;
  --shadow-sm: 0 3px 0 var(--ink);
  --shadow-md: 0 5px 0 var(--ink);
  --shadow-lg: 0 8px 0 var(--ink);
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 24px;
  --radius-pill: 999px;

  --font-ui: 'IBM Plex Sans Thai', 'Leelawadee UI', 'Segoe UI', sans-serif;
  --font-num: 'Fredoka', 'IBM Plex Sans Thai', sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  background-color: var(--bg-cream);
  background-image:
    radial-gradient(circle at 12% 15%, rgba(16, 185, 129, 0.14) 0%, transparent 40%),
    radial-gradient(circle at 88% 82%, rgba(245, 158, 11, 0.14) 0%, transparent 42%),
    radial-gradient(#cbd8d4 1.2px, transparent 1.2px);
  background-size: 100% 100%, 100% 100%, 24px 24px;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3, h4, p { margin: 0; }
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  user-select: none;
}
button:disabled {
  cursor: default;
}
.btn-pop:disabled,
.triage-tag-btn:disabled,
.roster-chip:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}
button:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 3px;
}

/* ---------- Tactile 3D Push Buttons ---------- */
.btn-pop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  font-weight: 700;
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s cubic-bezier(.34,1.56,.64,1), box-shadow 0.1s ease, background 0.15s ease;
}
.btn-pop:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 0 var(--ink);
}
.btn-pop:not(:disabled):active {
  transform: translateY(3px);
  box-shadow: 0 0 0 var(--ink);
}
.btn-pop.primary {
  background: var(--teal);
  color: #ffffff;
}
.btn-pop.primary:not(:disabled):hover {
  background: #14c98d;
}
.btn-pop.gold {
  background: #fbbf24;
  color: var(--ink);
}
.btn-pop.coral {
  background: var(--coral);
  color: #ffffff;
}
.btn-pop.purple {
  background: var(--purple);
  color: #ffffff;
}
.btn-pop.sm {
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 10px;
}
.btn-pop.icon-only {
  padding: 9px;
  width: 40px;
  height: 40px;
}
.btn-pop.active-pill {
  background: #d1fae5;
  border-color: var(--ink);
}

/* ---------- App Shell ---------- */
.app-shell {
  width: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- Top Brand Bar (Menu / Results) ---------- */
.menu-topbar {
  max-width: 1220px;
  width: 100%;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  cursor: pointer;
}
.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, #10b981, #06b6d4);
  border: var(--border-w) solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  color: #fff;
  display: grid;
  place-items: center;
}
.brand-text strong {
  font-family: var(--font-num);
  font-size: 22px;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.brand-text strong .plus-pill {
  font-size: 11px;
  background: #fbbf24;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 99px;
  padding: 1px 7px;
  font-weight: 700;
}
.brand-text small {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
}
.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- LEVEL SELECT (Sticker Book Deck) ---------- */
.level-select-wrap {
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 6px 20px 28px;
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 28px;
  align-items: center;
  flex: 1;
}

.hero-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.hero-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  background: #fef3c7;
  border: 2px solid var(--ink);
  box-shadow: 0 2px 0 var(--ink);
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
}
.hero-panel h1 {
  font-size: clamp(26px, 3.2vw, 36px);
  line-height: 1.22;
  font-weight: 700;
}
.hero-panel h1 span {
  color: var(--teal-dark);
  text-decoration: underline wavy #fbbf24;
  text-underline-offset: 5px;
}
.hero-panel p {
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.7;
}

/* Hardcore Mode Switch Card */
.hardcore-box {
  background: var(--surface-warm);
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.hardcore-box.is-on {
  background: #fff1f2;
  border-color: #be123c;
  box-shadow: 0 3px 0 #be123c;
}
.hardcore-info b {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}
.hardcore-info small {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.toggle-pill {
  position: relative;
  width: 52px;
  height: 28px;
  border-radius: 99px;
  border: 2.5px solid var(--ink);
  background: #cbd5e1;
  flex-shrink: 0;
  transition: background 0.18s;
  padding: 0;
}
.toggle-pill::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--ink);
  transition: transform 0.18s cubic-bezier(.34,1.56,.64,1);
}
.toggle-pill.on {
  background: var(--coral);
}
.toggle-pill.on::after {
  transform: translateX(24px);
}

/* Quick Level Mini Strip */
.level-mini-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.mini-lvl-btn {
  padding: 8px 4px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 2px 0 var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  transition: transform 0.12s;
}
.mini-lvl-btn.active {
  background: #d1fae5;
  transform: translateY(-2px);
  box-shadow: 0 4px 0 var(--ink);
}
.mini-lvl-btn .mini-stars {
  font-size: 11px;
  letter-spacing: -1px;
  color: #f59e0b;
}

/* Swipeable Card Deck */
.deck-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.deck-stage {
  position: relative;
  width: 100%;
  max-width: 560px;
  display: grid;
  padding: 8px 8px 32px;
  touch-action: pan-y;
}
.level-card-pop {
  grid-area: 1 / 1;
  background: var(--surface);
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform-origin: 50% 95%;
  transition: transform 0.28s cubic-bezier(.34,1.36,.64,1), opacity 0.25s ease;
  pointer-events: none;
}
.level-card-pop.front {
  pointer-events: auto;
  cursor: grab;
}
.level-card-pop.front:active {
  cursor: grabbing;
}
.level-card-pop.dragging {
  transition: none;
}
.level-cover-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #b9d7c5;
  overflow: hidden;
  border-bottom: 3px solid var(--ink);
}
.level-cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.level-num-pill {
  position: absolute;
  top: 12px;
  left: 12px;
  background: #fffdf6;
  border: 2.5px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-weight: 700;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.level-diff-pill {
  position: absolute;
  top: 12px;
  right: 12px;
  background: #fef3c7;
  border: 2.5px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  border-radius: var(--radius-pill);
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 700;
}
/* Sticker Stamp when level cleared */
.cleared-sticker {
  position: absolute;
  bottom: 12px;
  right: 14px;
  background: #10b981;
  color: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 5px 12px;
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: 700;
  transform: rotate(-6deg);
  box-shadow: 0 3px 0 var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.level-body-pop {
  padding: 18px 20px 20px;
}
.level-body-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.level-body-pop h2 {
  font-size: 22px;
  font-weight: 700;
}
.gimmick-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #ede9fe;
  color: #5b21b6;
  border: 2px solid var(--ink);
  border-radius: 99px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.level-gimmick-box {
  margin: 10px 0 14px;
  background: #f0fdf4;
  border: 2px dashed #0d9488;
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 13px;
  color: #134e4a;
  font-weight: 500;
}
.level-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.level-best-info {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
}
.level-best-info strong {
  color: var(--ink);
  font-family: var(--font-num);
  font-size: 14px;
}
.deck-nav {
  display: flex;
  align-items: center;
  gap: 14px;
}
.deck-dots {
  display: flex;
  gap: 7px;
}
.deck-dots button {
  width: 10px;
  height: 10px;
  border-radius: 99px;
  border: 2px solid var(--ink);
  background: #fff;
  padding: 0;
  transition: width 0.2s, background 0.2s;
}
.deck-dots button.active {
  width: 28px;
  background: var(--teal);
}

/* ==========================================================================
   FULL-VIEWPORT IMMERSIVE GAMEPLAY STAGE + FLOATING COMMAND HUD
   ========================================================================== */
.play-stage-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #17323b;
  display: flex;
  flex-direction: column;
}

.scene-viewport {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #92b889;
  isolation: isolate;
  --character-size: clamp(66px, 7.6vw, 114px);
}

/* Fever Mode Golden Aura */
.scene-viewport.fever-mode::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1900;
  box-shadow: inset 0 0 0 5px #fbbf24, inset 0 0 42px rgba(251, 191, 36, 0.55);
  animation: fever-pulse 1.1s ease-in-out infinite alternate;
}
@keyframes fever-pulse {
  from { box-shadow: inset 0 0 0 4px #fbbf24, inset 0 0 28px rgba(251, 191, 36, 0.35); }
  to { box-shadow: inset 0 0 0 7px #f59e0b, inset 0 0 54px rgba(245, 158, 11, 0.65); }
}

/* Aftershock Quake Shake */
.scene-viewport.shaking {
  animation: quake-shake 0.7s cubic-bezier(.36,.07,.19,.97) both;
}
@keyframes quake-shake {
  0%, 100% { transform: translate(0, 0); }
  12% { transform: translate(-9px, 5px) rotate(-0.5deg); }
  25% { transform: translate(8px, -6px) rotate(0.5deg); }
  38% { transform: translate(-7px, -4px); }
  52% { transform: translate(7px, 5px); }
  66% { transform: translate(-5px, 3px); }
  80% { transform: translate(4px, -2px); }
}

.scene-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

/* ---------- Floating HUD Top Bar ---------- */
.hud-top {
  position: absolute;
  top: 12px;
  left: 14px;
  right: 14px;
  z-index: 2050;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}
.hud-top > * {
  pointer-events: auto;
}

.hud-pill {
  background: rgba(255, 253, 246, 0.94);
  backdrop-filter: blur(10px);
  border: var(--border-w) solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: 8px 13px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

/* Left HUD: Stage + Roster quick jump */
.hud-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.stage-chip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.stage-badge {
  background: var(--teal);
  color: #fff;
  border: 2px solid var(--ink);
  border-radius: 99px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 700;
}
.stage-badge.sort-stage {
  background: var(--purple);
}
.level-title-mini {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}
.hc-mini-tag {
  background: var(--coral);
  color: #fff;
  border: 2px solid var(--ink);
  border-radius: 99px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
}

/* Quick Roster Bar */
.hud-roster {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  background: rgba(255, 253, 246, 0.9);
  backdrop-filter: blur(8px);
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 5px 7px;
  box-shadow: 0 3px 0 var(--ink);
}
.roster-chip {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  border: 2px solid var(--ink);
  background: #fff;
  font-family: var(--font-num);
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform 0.12s;
}
.roster-chip:hover:not(:disabled) {
  transform: translateY(-2px);
}
.roster-chip.selected {
  outline: 2.5px solid var(--cyan);
  outline-offset: 1px;
}
.roster-chip.tag-red { background: var(--p1-accent); color: #fff; }
.roster-chip.tag-yellow { background: var(--p2-accent); color: var(--ink); }
.roster-chip.tag-green { background: var(--p3-accent); color: #fff; }
.roster-chip.tag-black { background: var(--dead-accent); color: #fff; }

/* Center HUD: Timer + Combo Pill */
.hud-center {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.timer-hud {
  min-width: 148px;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  padding: 7px 14px;
}
.timer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.timer-val {
  font-family: var(--font-num);
  font-size: 22px;
  line-height: 1;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.timer-hud.warn .timer-val { color: #d97706; }
.timer-hud.danger {
  background: #fff1f2;
  border-color: #be123c;
  animation: timer-blink 0.9s ease-in-out infinite alternate;
}
.timer-hud.danger .timer-val { color: #be123c; }
@keyframes timer-blink {
  from { transform: scale(1); }
  to { transform: scale(1.03); }
}
.timer-bar-track {
  height: 6px;
  background: #e2e8f0;
  border-radius: 99px;
  border: 1.5px solid var(--ink);
  overflow: hidden;
}
.timer-bar-fill {
  height: 100%;
  background: var(--teal);
  transition: width 0.25s linear, background 0.3s;
}
.timer-hud.warn .timer-bar-fill { background: #f59e0b; }
.timer-hud.danger .timer-bar-fill { background: #f43f5e; }

.score-hud {
  gap: 8px;
}
.score-hud .score-num {
  font-family: var(--font-num);
  font-size: 22px;
  line-height: 1;
  font-weight: 700;
  color: var(--teal-dark);
}
.score-hud small {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: 600;
}

.combo-pill {
  background: linear-gradient(135deg, #fde047, #fb923c);
  color: var(--ink);
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  padding: 6px 14px;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  animation: pop-bounce 0.35s cubic-bezier(.34,1.56,.64,1);
}
.combo-pill.fever {
  background: linear-gradient(135deg, #f43f5e, #f59e0b, #fde047);
  color: #fff;
  text-shadow: 0 1.5px 0 var(--ink);
}
@keyframes pop-bounce {
  0% { transform: scale(0.6); }
  70% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

/* Right HUD: Quick Actions */
.hud-right {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ---------- Nurse Radio Comms Bubble (Bottom-Left) ---------- */
.comms-bubble {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 2040;
  max-width: min(410px, calc(100vw - 28px));
  background: rgba(255, 253, 246, 0.96);
  backdrop-filter: blur(8px);
  border: var(--border-w) solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  padding: 8px 14px 8px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  transition: transform 0.2s ease, background 0.2s;
}
.comms-bubble.good { background: #ecfdf5; border-color: #065f46; }
.comms-bubble.wrong { background: #fff1f2; border-color: #9f1239; }
.comms-bubble.alert { background: #fef3c7; border-color: #92400e; animation: pop-bounce 0.35s ease; }

.comms-avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #d1fae5;
  border: 2px solid var(--ink);
  overflow: hidden;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}
.nurse-comms-avatar-svg {
  width: 100%;
  height: 100%;
  display: block;
}
.comms-text b {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--teal-dark);
}
.comms-bubble.wrong .comms-text b { color: #be123c; }
.comms-bubble.alert .comms-text b { color: #b45309; }
.comms-text p {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
}

/* ---------- Floating Score Popups above Patients ---------- */
.float-score {
  position: absolute;
  z-index: 2060;
  pointer-events: none;
  transform: translate(-50%, -100%);
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 18px;
  padding: 4px 12px;
  border-radius: 99px;
  border: 2.5px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  white-space: nowrap;
  animation: float-up 1.35s cubic-bezier(.2,.8,.2,1) forwards;
}
.float-score.good {
  background: #34d399;
  color: var(--ink);
}
.float-score.bonus {
  background: #fde047;
  color: var(--ink);
}
.float-score.wrong {
  background: #fda4af;
  color: #881337;
}
@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.7); }
  18% { opacity: 1; transform: translate(-50%, -115%) scale(1.1); }
  75% { opacity: 1; transform: translate(-50%, -155%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(0.95); }
}

/* ---------- Sprites, Nurse & Gathering Zone ---------- */
.gather-zone {
  position: absolute;
  left: 71%;
  top: 15%;
  width: 26%;
  min-height: 22%;
  border: 3px dashed #fef08a;
  border-radius: 20px;
  background: rgba(254, 249, 195, 0.16);
  z-index: 2;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 6px;
}
.gather-zone span {
  display: inline-block;
  background: rgba(255, 253, 246, 0.94);
  border: 2px solid var(--ink);
  border-radius: 99px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 700;
}

.patient-btn {
  position: absolute;
  width: var(--character-size);
  aspect-ratio: 1;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  opacity: 1;
  transition: filter 0.15s;
}
.patient-btn:disabled {
  opacity: 1;
  cursor: default;
}
.patient-btn:hover:not(:disabled) {
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.95));
}
.patient-btn.wave-spawn {
  animation: wave-pop 0.55s cubic-bezier(.34,1.56,.64,1);
}
@keyframes wave-pop {
  0% { opacity: 0; transform: translate(-50%, -130%) scale(0.4); }
  100% { opacity: 1; transform: translate(-50%, -90%) scale(1); }
}

.patient-cutout {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  aspect-ratio: 1;
  display: block;
  z-index: 2;
}
.patient-art {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.patient-tag-badge {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -55%);
  z-index: 5;
  background: #fffdf6;
  border: 2px solid var(--ink);
  box-shadow: 0 2px 0 var(--ink);
  border-radius: 9px;
  padding: 2px 7px;
  font-family: var(--font-num);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}
.patient-tag-badge.tag-red { background: var(--p1-accent); color: #fff; }
.patient-tag-badge.tag-yellow { background: var(--p2-accent); color: var(--ink); }
.patient-tag-badge.tag-green { background: var(--p3-accent); color: #fff; }
.patient-tag-badge.tag-black { background: var(--dead-accent); color: #fff; }

.patient-ring {
  position: absolute;
  left: 12%;
  bottom: -2%;
  width: 76%;
  height: 24%;
  border-radius: 50%;
  z-index: 1;
  transition: all 0.2s;
}
.patient-btn.selected .patient-ring {
  border: 3px solid #22d3ee;
  background: rgba(34, 211, 238, 0.28);
  box-shadow: 0 0 16px rgba(34, 211, 238, 0.9);
}
.patient-btn.untreated:not(:disabled) .patient-ring {
  border: 2px dashed rgba(255, 255, 255, 0.8);
}

/* Nurse Sprite */
.nurse-actor {
  position: absolute;
  width: calc(var(--character-size) * 1.12);
  transform: translate(-50%, -90%);
  pointer-events: none;
  z-index: 5;
}
.nurse-facing {
  display: block;
  width: 100%;
  transform-origin: 50% 90%;
}
.nurse-facing.face-left {
  transform: scaleX(-1);
}
.nurse-rig {
  display: block;
  width: 100%;
  aspect-ratio: 384 / 341;
  height: auto;
  overflow: hidden;
}
.nurse-frames {
  display: block;
  width: 100%;
  aspect-ratio: 384 / 341;
  background-image: url('../assets/nurse-actions-matched.png');
  background-size: 400% 200%;
  background-repeat: no-repeat;
  animation: four-frame 2.2s steps(1, end) infinite;
}
.nurse-frames.nurse-idle {
  background-position-y: 0%;
  animation-duration: 2.4s;
}
.nurse-frames.nurse-exam {
  background-position-y: 100%;
  animation-duration: 1.5s;
}
.animation-paused .nurse-frames {
  animation-play-state: paused !important;
}
@keyframes four-frame {
  0%, 100% { background-position-x: 0%; }
  25% { background-position-x: 33.333333%; }
  50% { background-position-x: 66.666667%; }
  75% { background-position-x: 100%; }
}

/* ---------- Center Scene Overlays (Ready / Gather / Pause / Stage Clear / Aftershock Banner) ---------- */
.scene-overlay {
  position: absolute;
  inset: 0;
  z-index: 2100;
  display: grid;
  place-items: center;
  background: rgba(23, 50, 59, 0.48);
  backdrop-filter: blur(4px);
  padding: 20px;
}
.pop-modal-card {
  width: min(440px, 100%);
  background: var(--surface-warm);
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 26px 24px;
  text-align: center;
  animation: modal-pop 0.25s cubic-bezier(.34,1.56,.64,1);
}
@keyframes modal-pop {
  from { opacity: 0; transform: scale(0.88) translateY(14px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.pop-modal-card .eyebrow-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #d1fae5;
  border: 2px solid var(--ink);
  border-radius: 99px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 10px;
}
.pop-modal-card h2 {
  font-size: 25px;
  margin-bottom: 8px;
}
.pop-modal-card p {
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.75;
  margin-bottom: 18px;
}
.modal-btn-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-btn-stack .btn-pop {
  width: 100%;
  padding: 13px 18px;
  font-size: 16px;
}

/* Announcement Banner during gather */
.announce-banner {
  position: absolute;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2070;
  width: min(490px, calc(100% - 28px));
  background: #fef9c3;
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  padding: 12px 18px;
  text-align: center;
  animation: pop-bounce 0.3s ease;
}
.announce-banner b {
  font-size: 13px;
  color: #b45309;
  display: block;
}
.announce-banner p {
  font-size: 15px;
  font-weight: 700;
  margin-top: 3px;
}
.announce-banner small {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 4px;
}

/* ==========================================================================
   MEDICAL TABLET / CLIPBOARD ASSESSMENT MODAL (Interactive Quick-Check + Triage Tags)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(15, 36, 44, 0.56);
  backdrop-filter: blur(5px);
  display: grid;
  place-items: center;
  padding: 14px;
  overflow-y: auto;
}

.tablet-card {
  position: relative;
  width: min(650px, 100%);
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface-warm);
  border: 3px solid var(--ink);
  border-radius: 26px;
  box-shadow: 0 10px 0 var(--ink);
  animation: modal-pop 0.22s cubic-bezier(.34,1.45,.64,1);
}

/* Clipboard Top Clip Bar */
.tablet-header {
  background: #17323b;
  color: #fff;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.tablet-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.case-pill {
  background: #fbbf24;
  color: var(--ink);
  border: 2px solid #fff;
  border-radius: 10px;
  padding: 2px 10px;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 15px;
}
.tablet-header h3 {
  font-size: 16px;
  font-weight: 700;
}
.tablet-header-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}
.tablet-header-actions .btn-pop {
  padding: 6px 11px;
  font-size: 12px;
  border-color: #0b1c22;
}

.tablet-body {
  padding: 18px 20px 22px;
}

/* Patient Profile Strip */
.patient-hero-strip {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #f0f9f6;
  border: 2px solid var(--ink);
  border-radius: 18px;
  padding: 12px;
  margin-bottom: 14px;
}
.patient-avatar-frame {
  position: relative;
  width: 82px;
  height: 82px;
  border-radius: 16px;
  background: #fff;
  border: 2.5px solid var(--ink);
  overflow: hidden;
  flex-shrink: 0;
}
.patient-avatar-frame .patient-avatar {
  position: relative;
  width: 100%;
  height: 100%;
}
.patient-meta h2 {
  font-size: 20px;
  line-height: 1.25;
}
.patient-meta-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 4px 0 6px;
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 600;
}
.symptom-quote {
  font-size: 13.5px;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  padding: 6px 10px;
  line-height: 1.5;
}

/* Live ECG Mini Monitor Header */
.monitor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.monitor-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
}
.ecg-strip {
  display: inline-flex;
  align-items: center;
  background: #0f292e;
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 3px 10px;
  height: 28px;
  overflow: hidden;
}
.ecg-svg {
  width: 82px;
  height: 20px;
}
.ecg-path {
  fill: none;
  stroke: #34d399;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 140;
  stroke-dashoffset: 140;
  animation: ecg-sweep 1.8s linear infinite;
}
.ecg-path.flatline {
  stroke: #f43f5e;
  animation: none;
  stroke-dashoffset: 0;
}
@keyframes ecg-sweep {
  0% { stroke-dashoffset: 140; }
  100% { stroke-dashoffset: 0; }
}

/* Interactive Vital Check Grid */
.vitals-monitor-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.vital-tile {
  background: #102a31;
  color: #e2f7f1;
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 106px;
  position: relative;
  overflow: hidden;
  transition: transform 0.14s cubic-bezier(.34,1.56,.64,1), background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.vital-tile.unchecked {
  background: #eef6f4;
  color: var(--ink);
  border-style: dashed;
  cursor: pointer;
}
.vital-tile.unchecked:hover {
  background: #d1fae5;
  transform: translateY(-2px);
  box-shadow: 0 3px 0 var(--ink);
}
.vital-tile.unchecked:active {
  transform: translateY(1px);
  box-shadow: none;
}

/* Phase 1: Per-tile Laser Scan Sweep (ONLY affects the clicked tile!) */
.vital-tile.is-scanning {
  background: #133942;
  color: #d1fae5;
  border-style: solid;
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.28);
  transform: scale(0.98);
  pointer-events: none;
}
.laser-scan-beam {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -35%;
  width: 38%;
  background: linear-gradient(90deg, transparent, rgba(52, 211, 153, 0.65), rgba(34, 211, 238, 0.9), transparent);
  box-shadow: 0 0 14px rgba(52, 211, 153, 0.75);
  animation: laser-sweep 0.34s cubic-bezier(.4,0,.2,1) forwards;
  pointer-events: none;
}
@keyframes laser-sweep {
  from { left: -40%; }
  to { left: 108%; }
}
.scan-loader-row {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.scan-loader-text {
  font-size: 12px;
  font-weight: 700;
  color: #6ee7b7;
  letter-spacing: 0.3px;
}
.scan-progress-track {
  height: 5px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}
.scan-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, #34d399, #22d3ee);
  animation: scan-bar-fill 0.32s ease-out forwards;
}
@keyframes scan-bar-fill {
  from { width: 8%; }
  to { width: 100%; }
}

/* Phase 2: Per-tile Reveal Spring Pop */
.vital-tile.just-revealed {
  animation: tile-reveal-pop 0.36s cubic-bezier(.34,1.56,.64,1);
}
@keyframes tile-reveal-pop {
  0% { transform: scale(0.92) rotateX(18deg); box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.45); }
  60% { transform: scale(1.03) rotateX(-3deg); box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.2); }
  100% { transform: scale(1) rotateX(0deg); box-shadow: none; }
}
.vital-tile.tile-alert-shake {
  border-color: #f43f5e;
  animation: tile-micro-shake 0.42s ease;
}
@keyframes tile-micro-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

.vital-label {
  font-size: 11.5px;
  opacity: 0.88;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.vital-value-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}
.vital-value {
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: 700;
  color: #5eead4;
  line-height: 1.2;
}
.vital-value.warn { color: #fde047; }
.vital-value.crit { color: #fda4af; }
.vital-sub {
  font-size: 11px;
  opacity: 0.82;
  margin-top: 4px;
}
.check-cta {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--teal-dark);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* --- Per-Vital Micro-Animations --- */
/* 1. Ambulation status pill + subtle bobbing walker */
.walk-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  margin-top: 5px;
  width: fit-content;
  border: 1.5px solid rgba(255, 255, 255, 0.25);
}
.walk-status-pill.can-walk {
  background: rgba(16, 185, 129, 0.25);
  color: #6ee7b7;
}
.walk-status-pill.no-walk {
  background: rgba(245, 158, 11, 0.24);
  color: #fde68a;
}
.walk-bob-icon {
  display: inline-block;
  animation: walk-bob 0.8s ease-in-out infinite;
}
@keyframes walk-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2.5px); }
}

/* 2. Breathing Wave Bars (speed synced to RR!) */
.breath-wave {
  display: inline-flex;
  align-items: flex-end;
  gap: 2.5px;
  height: 18px;
  flex-shrink: 0;
}
.breath-wave i {
  display: block;
  width: 3.5px;
  height: 100%;
  border-radius: 99px;
  background: #34d399;
  transform-origin: bottom;
  animation: breath-bar var(--breath-dur, 1.4s) ease-in-out infinite;
}
.breath-wave i:nth-child(2) { animation-delay: 0.16s; }
.breath-wave i:nth-child(3) { animation-delay: 0.32s; }
.breath-wave i:nth-child(4) { animation-delay: 0.48s; }
.breath-wave.crit i { background: #fb7185; }
.breath-wave.flat i {
  background: #f43f5e;
  animation: none;
  transform: scaleY(0.18);
}
@keyframes breath-bar {
  0%, 100% { transform: scaleY(0.28); opacity: 0.65; }
  50% { transform: scaleY(1); opacity: 1; }
}

/* 3. Beating Heart (speed synced to Pulse!) */
.heart-beat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  animation: heart-thump var(--pulse-dur, 0.75s) ease-in-out infinite;
}
@keyframes heart-thump {
  0%, 100% { transform: scale(1); }
  18% { transform: scale(1.3); }
  34% { transform: scale(1); }
  52% { transform: scale(1.18); }
  70% { transform: scale(1); }
}

/* 4. CRT Refill Bar & SBP/GCS Mini Gauge Bars */
.mini-gauge-track {
  margin-top: 6px;
  height: 7px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.mini-gauge-fill {
  height: 100%;
  border-radius: 99px;
  width: var(--gauge-pct, 0%);
  background: #34d399;
  animation: gauge-grow var(--gauge-dur, 0.55s) cubic-bezier(.22,1,.36,1) both;
}
.mini-gauge-fill.warn { background: #fbbf24; }
.mini-gauge-fill.crit { background: #fb7185; }
@keyframes gauge-grow {
  from { width: 0%; }
  to { width: var(--gauge-pct, 100%); }
}

/* Interactive Airway Action Banner (slides in smoothly without flashing modal) */
#airway-slot {
  grid-column: 1 / -1;
}
#airway-slot:empty {
  display: none;
}
.airway-action-box {
  background: #fff1f2;
  border: 2.5px solid #be123c;
  border-radius: 14px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  animation: slide-down-in 0.28s cubic-bezier(.34,1.4,.64,1);
}
.airway-action-box.airway-ok {
  background: #fef3c7;
  border-color: #b45309;
}
.airway-action-box.airway-scanning {
  background: #ffe4e6;
  border-color: #f43f5e;
}
@keyframes slide-down-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.airway-action-box b {
  color: #9f1239;
  font-size: 13.5px;
}
.airway-action-box.airway-ok b {
  color: #92400e;
}

/* Triage Hang-Tag Selector (4 Perforated Physical Tags) */
.triage-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 14px 0 10px;
}
.triage-section-head h4 {
  font-size: 15px;
  font-weight: 700;
}
.triage-section-head span {
  font-size: 12px;
  color: var(--ink-soft);
}

.triage-tags-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.triage-tag-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
  padding: 12px 14px 12px 18px;
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.1s cubic-bezier(.34,1.56,.64,1), box-shadow 0.1s;
}
/* Little tag punch hole on the left */
.triage-tag-btn::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface-warm);
  border: 2px solid var(--ink);
  flex-shrink: 0;
}
.triage-tag-btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--ink);
}
.triage-tag-btn:not(:disabled):active {
  transform: translateY(3px);
  box-shadow: 0 0 0 var(--ink);
}
.triage-tag-btn.red { background: var(--p1-bg); color: var(--p1-ink); }
.triage-tag-btn.yellow { background: var(--p2-bg); color: var(--p2-ink); }
.triage-tag-btn.green { background: var(--p3-bg); color: var(--p3-ink); }
.triage-tag-btn.black { background: var(--dead-bg); color: var(--dead-ink); }

.tag-code-badge {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 14px;
  padding: 3px 8px;
  border-radius: 8px;
  border: 2px solid var(--ink);
  color: #fff;
  flex-shrink: 0;
}
.triage-tag-btn.red .tag-code-badge { background: var(--p1-accent); }
.triage-tag-btn.yellow .tag-code-badge { background: var(--p2-accent); color: var(--ink); }
.triage-tag-btn.green .tag-code-badge { background: var(--p3-accent); }
.triage-tag-btn.black .tag-code-badge { background: var(--dead-accent); }

.tag-info b {
  display: block;
  font-size: 15px;
  line-height: 1.2;
}
.tag-info small {
  display: block;
  font-size: 12px;
  opacity: 0.85;
  margin-top: 2px;
}

/* Stamp Overlay Slam Animation */
.stamp-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(255, 253, 246, 0.65);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  pointer-events: none;
}
.stamp-mark {
  font-family: var(--font-num);
  font-size: 32px;
  font-weight: 700;
  padding: 12px 26px;
  border: 5px solid currentColor;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.94);
  transform: rotate(-8deg);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  animation: stamp-slam 0.28s cubic-bezier(.18,.89,.32,1.28) forwards;
}
.stamp-mark.good { color: #059669; }
.stamp-mark.wrong { color: #dc2626; }
@keyframes stamp-slam {
  0% { opacity: 0; transform: scale(2.2) rotate(-18deg); }
  100% { opacity: 1; transform: scale(1) rotate(-8deg); }
}

/* Feedback Box when viewing an already-answered patient */
.reviewed-feedback {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2.5px solid var(--ink);
  font-size: 13.5px;
  line-height: 1.6;
}
.reviewed-feedback.good { background: #dcfce7; }
.reviewed-feedback.wrong { background: #ffe4e6; }
.reviewed-feedback b { display: block; margin-bottom: 4px; font-size: 14.5px; }

/* ---------- Guide / Cheat-Sheet Modal ---------- */
.guide-modal {
  width: min(880px, 100%);
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface-warm);
  border: 3px solid var(--ink);
  border-radius: 26px;
  box-shadow: 0 10px 0 var(--ink);
  padding: 24px;
}
.guide-steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 14px 0 20px;
}
.guide-step-card {
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 12px;
  font-size: 13px;
}
.guide-flow {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 10px 0 12px;
}
.guide-flow-card {
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 11px;
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.guide-flow-card b {
  display: inline-block;
  width: fit-content;
  background: #d1fae5;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 12px;
}
.flow-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  line-height: 1.4;
}
.flow-next {
  display: inline-block;
  background: #e0f2fe;
  color: #0369a1;
  border: 1.5px solid #0369a1;
  border-radius: 99px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
}
.flow-sub {
  font-size: 12px;
  line-height: 1.5;
  padding-left: 4px;
}
.guide-color-cheat {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}
.cheat-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 11px;
  border-radius: 12px;
  border: 2px solid var(--ink);
  font-size: 12.5px;
  line-height: 1.45;
  background: #fff;
}
.cheat-row.green { background: #ecfdf5; }
.cheat-row.yellow { background: #fefce8; }
.cheat-row.red { background: #fff1f2; }
.cheat-row.black { background: #f1f5f9; }
.g-pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 99px;
  border: 1.5px solid var(--ink);
  font-weight: 700;
  font-size: 11.5px;
  white-space: nowrap;
}
.g-pill.red { background: var(--p1-bg); color: var(--p1-ink); }
.g-pill.yellow { background: var(--p2-bg); color: var(--p2-ink); }
.g-pill.green { background: var(--p3-bg); color: var(--p3-ink); }
.g-pill.black { background: var(--dead-bg); color: var(--dead-ink); }
.guide-sort-summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 700;
  margin-bottom: 6px;
}
.trts-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 16px;
  background: #fff;
  border: 2.5px solid var(--ink);
  font-size: 13.5px;
}
.trts-table th, .trts-table td {
  border: 1.5px solid var(--ink);
  padding: 8px 10px;
  text-align: center;
}
.trts-table th {
  background: #d1fae5;
  font-weight: 700;
}

/* ==========================================================================
   RESULT SCREEN (Rank Emblem + Stars + Personality Title + Share Card + Review)
   ========================================================================== */
.results-page {
  max-width: 960px;
  width: 100%;
  margin: 0 auto 40px;
  padding: 10px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.result-hero-card {
  background: var(--surface-warm);
  border: 3px solid var(--ink);
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
  padding: 28px 24px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.result-top-badges {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.rank-emblem {
  width: 92px;
  height: 92px;
  border-radius: 26px;
  border: 3.5px solid var(--ink);
  box-shadow: 0 6px 0 var(--ink);
  display: grid;
  place-items: center;
  font-family: var(--font-num);
  font-size: 42px;
  font-weight: 700;
  transform: rotate(-5deg);
  animation: pop-bounce 0.45s cubic-bezier(.34,1.56,.64,1);
}
.rank-emblem.rank-Splus { background: linear-gradient(135deg, #fde047, #fb7185); color: #fff; text-shadow: 0 2px 0 var(--ink); }
.rank-emblem.rank-S { background: linear-gradient(135deg, #fde047, #f59e0b); color: var(--ink); }
.rank-emblem.rank-A { background: #34d399; color: var(--ink); }
.rank-emblem.rank-B { background: #7dd3fc; color: var(--ink); }
.rank-emblem.rank-C { background: #e2e8f0; color: var(--ink); }

.stars-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}
.star-slot {
  width: 34px;
  height: 34px;
  color: #cbd5e1;
}
.star-slot.lit {
  color: #fbbf24;
  animation: pop-bounce 0.4s cubic-bezier(.34,1.56,.64,1);
}
.star-slot svg { width: 100%; height: 100%; }

.result-title-badge {
  display: inline-block;
  background: #fef3c7;
  border: 2.5px solid var(--ink);
  border-radius: 99px;
  padding: 5px 16px;
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 6px;
}
.result-hero-card h1 {
  font-size: 26px;
  margin-bottom: 4px;
}
.result-hero-card .sub {
  color: var(--ink-soft);
  font-size: 14px;
}

.result-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 20px 0 22px;
}
.stat-tile {
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  padding: 12px 10px;
  box-shadow: 0 3px 0 var(--ink);
}
.stat-tile span {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
}
.stat-tile strong {
  display: block;
  font-family: var(--font-num);
  font-size: 26px;
  color: var(--ink);
  margin-top: 2px;
}

.result-actions-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Review Card Tabs */
.review-card {
  background: var(--surface);
  border: 3px solid var(--ink);
  border-radius: 24px;
  box-shadow: var(--shadow-md);
  padding: 20px;
}
.review-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.review-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.review-item {
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 13px 14px;
  background: var(--surface-warm);
}
.review-item.ok { border-left: 7px solid #10b981; }
.review-item.miss { border-left: 7px solid #f43f5e; background: #fff5f6; }
.review-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.review-tag-pill {
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 99px;
  border: 1.5px solid var(--ink);
}
.review-tag-pill.red { background: var(--p1-bg); color: var(--p1-ink); }
.review-tag-pill.yellow { background: var(--p2-bg); color: var(--p2-ink); }
.review-tag-pill.green { background: var(--p3-bg); color: var(--p3-ink); }
.review-tag-pill.black { background: var(--dead-bg); color: var(--dead-ink); }
.review-tag-pill.none { background: #e2e8f0; color: #475569; }
.review-item p {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.55;
}

/* Share Card Modal (9:16 preview) */
.share-modal {
  width: min(420px, 100%);
  background: var(--surface-warm);
  border: 3px solid var(--ink);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 20px;
  text-align: center;
}
.share-preview-img {
  width: 100%;
  max-height: 62dvh;
  object-fit: contain;
  border-radius: 18px;
  border: 2.5px solid var(--ink);
  margin: 12px 0 16px;
  background: #17323b;
}

.result-hero-text {
  text-align: left;
}
.result-stars-align {
  justify-content: flex-start;
}

/* ==========================================================================
   RESPONSIVE RULES (Tablet, Portrait Phone, Landscape Phone)
   ========================================================================== */
@media (max-width: 1024px) {
  .level-select-wrap {
    grid-template-columns: 1fr;
    gap: 18px;
    padding-top: 2px;
  }
  .deck-stage {
    max-width: 580px;
  }
  .result-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .guide-steps,
  .guide-flow {
    grid-template-columns: repeat(2, 1fr);
  }
  .hud-top {
    flex-wrap: wrap;
    row-gap: 8px;
  }
}

/* Tablet Portrait (681px - 960px) */
@media (max-width: 960px) and (min-width: 681px) {
  .hud-left { max-width: 280px; }
  .scene-viewport { --character-size: clamp(68px, 10vw, 102px); }
}

/* Mobile Devices (<= 680px) */
@media (max-width: 680px) {
  .menu-topbar {
    padding: 10px 14px;
    gap: 8px;
  }
  .brand-logo {
    width: 36px;
    height: 36px;
    border-radius: 11px;
  }
  .brand-text strong {
    font-size: 18px;
  }
  .brand-text small {
    font-size: 11px;
  }
  .level-select-wrap {
    padding: 4px 14px 24px;
    gap: 14px;
  }
  .hero-panel {
    gap: 10px;
  }
  .hero-panel h1 {
    font-size: 24px;
  }
  .hero-panel p {
    font-size: 13px;
  }
  .level-body-pop {
    padding: 14px 14px 16px;
  }
  .level-body-pop h2 {
    font-size: 19px;
  }
  .level-body-top {
    flex-wrap: wrap;
    gap: 6px;
  }
  .level-card-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .level-card-footer .btn-pop {
    width: 100%;
  }

  /* Portrait Mobile Gameplay Shell: Docked Top HUD + Unobstructed Scene + Docked Bottom Comms! */
  .play-stage-shell {
    background: #142c34;
    justify-content: space-between;
  }

  .hud-top {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    padding: 8px 10px;
    background: #142c34;
    border-bottom: 2.5px solid #0b1c22;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 7px;
    flex-shrink: 0;
    pointer-events: auto;
  }
  .hud-left {
    max-width: none;
    width: 100%;
    gap: 6px;
  }
  .stage-chip-row {
    width: 100%;
    justify-content: space-between;
    padding: 5px 10px;
    border-radius: 12px;
  }
  .hud-center {
    width: 100%;
    justify-content: space-between;
    gap: 6px;
    flex-wrap: nowrap;
  }
  .hud-pill {
    padding: 5px 9px;
    border-radius: 12px;
    box-shadow: 0 2px 0 var(--ink);
  }
  .timer-hud {
    flex: 1;
    min-width: 0;
    padding: 5px 10px;
  }
  .timer-val, .score-hud .score-num {
    font-size: 17px;
  }
  .score-hud {
    padding: 5px 10px;
    gap: 6px;
  }
  .score-hud small {
    font-size: 10px;
  }
  .combo-pill {
    padding: 4px 9px;
    font-size: 12.5px;
    white-space: nowrap;
  }
  .hud-right {
    width: 100%;
    justify-content: space-between;
    gap: 5px;
    flex-wrap: nowrap;
  }
  .hud-right .btn-pop.sm {
    padding: 6px 9px;
    font-size: 12px;
    min-height: 34px;
  }
  .hud-right .btn-pop.icon-only {
    width: 34px;
    height: 34px;
    padding: 6px;
  }
  #btn-hud-guide {
    flex: 1;
  }
  /* Scrollable quick-roster strip stays accessible on mobile! */
  .hud-roster {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 4px 6px;
    gap: 5px;
    border-radius: 11px;
  }
  .hud-roster::-webkit-scrollbar { display: none; }
  .roster-chip {
    flex: 0 0 30px;
    width: 30px;
    height: 28px;
  }

  /* Unobstructed Map Scene in the middle — preserves both bus & tent! */
  .scene-viewport {
    flex: 1;
    width: 100%;
    min-height: 260px;
    --character-size: clamp(54px, 16vw, 76px);
  }
  .scene-bg {
    object-fit: cover;
    object-position: center;
  }
  .gather-zone {
    left: 68%;
    top: 10%;
    width: 30%;
    min-height: 26%;
    padding: 4px;
  }
  .gather-zone span {
    font-size: 9.5px;
    padding: 2px 6px;
  }
  .patient-tag-badge {
    font-size: 10.5px;
    padding: 1px 5px;
    border-radius: 7px;
  }
  .announce-banner {
    top: 10px;
    padding: 9px 12px;
  }
  .announce-banner p {
    font-size: 13px;
  }

  /* Docked Bottom Comms Panel (never overlaps bottom patients!) */
  .comms-bubble {
    position: relative;
    left: auto;
    bottom: auto;
    max-width: none;
    width: 100%;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    box-shadow: none;
    padding: 8px 12px;
    flex-shrink: 0;
  }
  .comms-avatar {
    width: 38px;
    height: 38px;
  }
  .comms-text b {
    font-size: 11.5px;
  }
  .comms-text p {
    font-size: 12.5px;
  }

  /* Medical Tablet Modal optimized for thumb play */
  .modal-backdrop {
    padding: 8px;
  }
  .tablet-card {
    border-radius: 20px;
    max-height: 94dvh;
  }
  .tablet-header {
    padding: 10px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .tablet-header h3 {
    font-size: 14px;
  }
  .tablet-body {
    padding: 12px 12px 16px;
  }
  .patient-hero-strip {
    padding: 9px;
    gap: 10px;
    margin-bottom: 10px;
  }
  .patient-avatar-frame {
    width: 62px;
    height: 62px;
    border-radius: 12px;
  }
  .patient-meta h2 {
    font-size: 17px;
  }
  .symptom-quote {
    font-size: 12.5px;
    padding: 5px 8px;
  }
  .vitals-monitor-grid {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 10px;
  }
  .vital-tile {
    min-height: 76px;
    padding: 9px 11px;
  }
  .vital-value {
    font-size: 18px;
  }
  /* Keep 2x2 Triage Tags grid on mobile for fast thumb tapping! */
  .triage-tags-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .triage-tag-btn {
    padding: 9px 8px 9px 10px;
    gap: 7px;
    border-radius: 13px;
  }
  .triage-tag-btn::before {
    display: none;
  }
  .tag-code-badge {
    font-size: 12px;
    padding: 2px 6px;
  }
  .tag-info b {
    font-size: 13px;
  }
  .tag-info small {
    font-size: 10.5px;
  }

  /* Results & Guide on mobile */
  .results-page {
    padding: 8px 12px;
  }
  .result-hero-card {
    padding: 20px 14px;
    border-radius: 22px;
  }
  .result-hero-text {
    text-align: center;
  }
  .result-stars-align {
    justify-content: center;
  }
  .result-hero-card h1 {
    font-size: 21px;
  }
  .result-actions-row .btn-pop {
    width: 100%;
  }
  .review-grid {
    grid-template-columns: 1fr;
  }
  .guide-modal {
    padding: 16px;
    border-radius: 20px;
  }
  .guide-steps,
  .guide-flow,
  .guide-color-cheat {
    grid-template-columns: 1fr;
  }
  .trts-table {
    font-size: 12px;
  }
  .trts-table th, .trts-table td {
    padding: 6px 5px;
  }
}

/* Landscape Mobile (short viewport height <= 520px) */
@media (max-height: 520px) and (orientation: landscape) {
  .hud-top {
    position: absolute;
    top: 6px;
    left: 8px;
    right: 8px;
    flex-direction: row;
    align-items: center;
    background: transparent;
    border-bottom: 0;
    padding: 0;
  }
  .hud-left, .hud-center, .hud-right {
    width: auto;
  }
  .hud-roster {
    display: none;
  }
  .hud-pill {
    padding: 4px 8px;
    border-radius: 10px;
  }
  .timer-val, .score-hud .score-num {
    font-size: 15px;
  }
  .comms-bubble {
    position: absolute;
    left: 8px;
    bottom: 6px;
    width: auto;
    max-width: 340px;
    border: 2px solid var(--ink);
    border-radius: 14px;
    padding: 5px 10px 5px 6px;
  }
  .comms-avatar { width: 30px; height: 30px; }
  .scene-viewport { --character-size: clamp(46px, 11vh, 64px); }
}

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

/* ==========================================================================
   PLAYER PROFILE INPUTS, LEADERBOARD MODAL & PRINT CERTIFICATE STYLES
   ========================================================================== */
.profile-card-box {
  background: var(--surface);
  border: var(--border-w) solid var(--ink);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.profile-card-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--teal-dark);
}
.profile-inputs-row {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 8px;
}
.pop-input {
  width: 100%;
  padding: 8px 11px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--surface-warm);
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.pop-input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.22);
}
.pop-input::placeholder {
  color: var(--ink-muted);
  font-weight: 500;
}

/* Result screen submit-to-leaderboard bar */
.submit-score-bar {
  background: #f0fdf4;
  border: 2.5px solid var(--ink);
  border-radius: 18px;
  padding: 14px;
  margin: 0 0 18px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.submit-score-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr auto;
  gap: 8px;
  align-items: center;
}
.submit-feedback-pill {
  font-size: 13px;
  font-weight: 700;
  color: #065f46;
  display: flex;
  align-items: center;
  gap: 6px;
}
.submit-feedback-pill.err {
  color: #be123c;
}

/* Leaderboard Modal */
.lb-modal {
  width: min(760px, 100%);
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface-warm);
  border: 3px solid var(--ink);
  border-radius: 26px;
  box-shadow: 0 10px 0 var(--ink);
  padding: 22px;
  animation: modal-pop 0.22s cubic-bezier(.34,1.45,.64,1);
}
.lb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.lb-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 99px;
  border: 1.5px solid var(--ink);
  background: #d1fae5;
  color: #065f46;
}
.lb-status-chip.offline {
  background: #fef3c7;
  color: #92400e;
}
.lb-filter-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.lb-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lb-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1.5fr) auto auto auto;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 13.5px;
}
.lb-row.top-1 { background: #fef9c3; border-width: 2.5px; }
.lb-row.top-2 { background: #f8fafc; }
.lb-row.top-3 { background: #ffedd5; }
.lb-row.is-me { outline: 3px solid var(--teal); outline-offset: 1px; }
.lb-pos {
  font-family: var(--font-num);
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}
.lb-player b {
  display: block;
  font-size: 14px;
  line-height: 1.3;
  word-break: break-word;
}
.lb-player small {
  color: var(--ink-soft);
  font-size: 11.5px;
}
.lb-rank-pill {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 13px;
  padding: 3px 9px;
  border-radius: 9px;
  border: 2px solid var(--ink);
  background: #d1fae5;
}
.lb-rank-pill.Splus { background: #ff5a6e; color: #fff; }
.lb-rank-pill.S { background: #fbbf24; }
.lb-rank-pill.A { background: #34d399; }
.lb-rank-pill.B { background: #7dd3fc; }
.lb-rank-pill.C { background: #e2e8f0; }
.lb-score {
  font-family: var(--font-num);
  font-size: 18px;
  font-weight: 700;
  color: var(--teal-dark);
  text-align: right;
}
.lb-meta {
  font-size: 11.5px;
  color: var(--ink-soft);
  text-align: right;
  white-space: nowrap;
}
.lb-empty {
  text-align: center;
  padding: 38px 16px;
  color: var(--ink-soft);
  font-weight: 600;
  background: #fff;
  border: 2px dashed var(--ink);
  border-radius: 16px;
}

/* Print-only comprehensive report block (hidden on screen) */
.print-only-header,
.print-only-review {
  display: none;
}

@media (max-width: 680px) {
  .profile-inputs-row,
  .submit-score-grid {
    grid-template-columns: 1fr;
  }
  .lb-modal {
    padding: 15px;
    border-radius: 20px;
  }
  .lb-row {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 6px;
    padding: 8px 10px;
  }
  .lb-rank-pill,
  .lb-meta {
    display: none;
  }
}

/* ---------- Direct Print Stylesheet (A4 Clean Score Certificate) ---------- */
@media print {
  @page {
    size: A4 portrait;
    margin: 12mm;
  }
  html, body {
    background: #fff !important;
    background-image: none !important;
    color: #111 !important;
    font-size: 12pt;
  }
  .menu-topbar,
  .result-actions-row,
  .submit-score-bar,
  .review-tabs,
  .modal-backdrop,
  .no-print {
    display: none !important;
  }
  .results-page {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 12px !important;
  }
  .result-hero-card,
  .review-card {
    box-shadow: none !important;
    border: 2px solid #17323b !important;
    border-radius: 12px !important;
    padding: 14px !important;
    break-inside: avoid;
  }
  .print-only-header {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #17323b;
    padding-bottom: 10px;
    margin-bottom: 12px;
    text-align: left;
  }
  .print-only-review {
    display: block !important;
  }
  .screen-only-review {
    display: none !important;
  }
  .review-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }
  .review-item {
    break-inside: avoid;
    padding: 8px 10px !important;
    font-size: 10pt !important;
  }
}
