:root {
  --ink: #161822;
  --cream: #fff9ec;
  --gold: #ffca28;
  --gold-deep: #f59e0b;
  --crimson: #ef4444;
  --teal: #14b8a6;
  --cobalt: #2563eb;
  --emerald: #22c55e;
  --slate: #262b3d;
  --shadow-comic: 4px 4px 0 #161822;
  --shadow-comic-lg: 7px 7px 0 #161822;
  --font-display: "Trebuchet MS", "Segoe UI Black", "Arial Black", system-ui, sans-serif;
  --font-body: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1b2234;
  color: var(--ink);
  font-family: var(--font-body);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#gameRoot {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* ===========================
   HUD BAR
=========================== */
.hud {
  position: absolute;
  top: env(safe-area-inset-top, 0px);
  bottom: auto;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  pointer-events: none;
  transition: top 0.24s ease, bottom 0.24s ease;
}

.hud.hud-bottom {
  top: auto;
  bottom: env(safe-area-inset-bottom, 0px);
  align-items: flex-end;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 7px;
  pointer-events: auto;
}

.hud-pill {
  background: rgba(255, 249, 236, 0.86);
  backdrop-filter: blur(4px);
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 var(--ink);
  padding: 5px 10px;
}

.wanted-pill {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 118px;
}

.wanted-stars {
  display: flex;
  gap: 3px;
  font-size: 16px;
  line-height: 1;
}

.wanted-stars .star {
  color: #cbd5e1;
  text-shadow: 1px 1px 0 var(--ink);
  transition: transform 0.15s ease, color 0.15s ease;
}

.wanted-stars .star.active {
  color: #facc15;
  transform: scale(1.12);
}

.stealth-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stealth-badge {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 6px;
  border: 2px solid var(--ink);
  color: #fff;
}

.state-clear {
  background: #3b82f6;
}
.state-hidden {
  background: #16a34a;
}
.state-caution {
  background: #f59e0b;
  color: var(--ink);
}
.state-alert {
  background: #dc2626;
  animation: pulseBadge 0.55s infinite alternate;
}

@keyframes pulseBadge {
  from { transform: scale(1); }
  to { transform: scale(1.07); }
}

.cooldown-wrap {
  flex: 1;
  height: 8px;
  background: #e2e8f0;
  border: 2px solid var(--ink);
  border-radius: 99px;
  overflow: hidden;
  min-width: 44px;
}

.cooldown-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #22c55e, #f59e0b, #ef4444);
  transition: width 0.08s linear;
}

.objective-pill {
  text-align: center;
  min-width: 210px;
}

.timer-obj-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.timer-display {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 900;
  color: var(--ink);
  background: var(--gold);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 1px 8px;
}

.timer-display.urgent {
  background: var(--crimson);
  color: #fff;
  animation: pulseBadge 0.4s infinite alternate;
}

.objective-counter {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 900;
  color: var(--cobalt);
}

.health-hearts {
  display: flex;
  gap: 2px;
  font-size: 15px;
}

.health-hearts .heart {
  color: #ef4444;
  text-shadow: 1px 1px 0 var(--ink);
}

.health-hearts .heart.lost {
  color: #cbd5e1;
}

.objective-hint {
  margin-top: 3px;
  font-size: 12px;
  font-weight: 700;
  color: #334155;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 380px;
}

.cash-pill {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.1;
}

.cash-display {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 900;
  color: #15803d;
}

.score-sub {
  font-size: 11px;
  font-weight: 800;
  color: #475569;
}

.hud-icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  border: 3px solid var(--ink);
  background: var(--cream);
  box-shadow: 3px 3px 0 var(--ink);
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.08s ease;
}

.hud-icon-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.hud-icon-btn.inactive {
  opacity: 0.56;
  background: #e2e8f0;
}

.hud-pause-btn {
  width: auto;
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--gold);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 900;
  color: var(--ink);
}

/* ===========================
   TOAST & ACTION BUTTON
=========================== */
.toast-banner {
  position: absolute;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 22;
  background: var(--gold);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: var(--shadow-comic);
  padding: 8px 16px;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 900;
  text-align: center;
  max-width: min(92vw, 460px);
  pointer-events: none;
  animation: toastPop 0.22s ease;
}

.toast-banner.toast-top {
  top: 14px;
}

@keyframes toastPop {
  from { opacity: 0; transform: translate(-50%, -10px) scale(0.92); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

.action-btn {
  position: absolute;
  right: max(18px, env(safe-area-inset-right, 18px));
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 18px;
  border: 3px solid var(--ink);
  background: linear-gradient(180deg, #34d399, #10b981);
  color: var(--ink);
  box-shadow: var(--shadow-comic-lg);
  cursor: pointer;
  font-family: var(--font-display);
  transition: transform 0.08s ease, filter 0.15s ease, bottom 0.24s ease;
}

.action-btn.above-bottom-hud {
  bottom: 92px;
}

.action-btn.mode-exit {
  background: linear-gradient(180deg, #fbbf24, #f59e0b);
}
.action-btn.mode-talk {
  background: linear-gradient(180deg, #60a5fa, #3b82f6);
  color: #fff;
}
.action-btn.mode-deliver {
  background: linear-gradient(180deg, #fde047, #eab308);
}
.action-btn.mode-clue {
  background: linear-gradient(180deg, #c084fc, #9333ea);
  color: #fff;
}
.action-btn.mode-escort {
  background: linear-gradient(180deg, #fb7185, #e11d48);
  color: #fff;
}
.action-btn.mode-blocked {
  background: linear-gradient(180deg, #ef4444, #991b1b);
  color: #fff;
  animation: pulseBadge 0.55s infinite alternate;
}

.action-btn:active {
  transform: translate(3px, 3px);
  box-shadow: 3px 3px 0 var(--ink);
}

.action-icon {
  font-size: 24px;
  line-height: 1;
}

.action-text-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.05;
}

.action-label {
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.action-hint {
  font-size: 11px;
  font-weight: 800;
  opacity: 0.85;
}

/* ===========================
   OVERLAYS & COMIC PANELS
=========================== */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(16, 20, 32, 0.56);
  backdrop-filter: blur(3px);
}

.menu-overlay {
  background: radial-gradient(circle at center, rgba(20, 26, 42, 0.25), rgba(14, 17, 29, 0.72));
}

.comic-panel {
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--shadow-comic-lg);
  padding: 22px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
}

.menu-card {
  max-width: 470px;
  text-align: center;
  background: linear-gradient(180deg, #fffdf6 0%, #fef3c7 100%);
}

.modal-panel {
  max-width: 620px;
}

.modal-wide {
  max-width: 820px;
}

.modal-narrow {
  max-width: 390px;
  text-align: center;
}

.title-badge {
  display: inline-block;
  background: var(--cobalt);
  color: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  padding: 4px 12px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.09em;
  margin-bottom: 10px;
}

.game-title {
  margin: 0;
  font-family: var(--font-display);
  line-height: 0.94;
  font-size: clamp(38px, 7vw, 58px);
  letter-spacing: -0.02em;
  text-shadow: 4px 4px 0 var(--ink);
  -webkit-text-stroke: 2px var(--ink);
}

.title-run {
  display: inline-block;
  color: var(--gold);
  transform: rotate(-3deg);
}
.title-pedro {
  display: block;
  color: var(--crimson);
  font-size: 1.15em;
}
.title-run2 {
  display: inline-block;
  color: var(--teal);
  transform: rotate(2deg);
}

.title-tagline {
  margin: 10px 0 14px;
  font-size: 14px;
  font-weight: 800;
  color: #334155;
}

.menu-stats-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 18px;
}

.stat-chip {
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 700;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-subrow {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.comic-btn {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 16px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-comic);
  cursor: pointer;
  color: var(--ink);
  background: #fff;
  transition: transform 0.08s ease, filter 0.12s ease;
}

.comic-btn:hover:not(:disabled) {
  filter: brightness(1.04);
}

.comic-btn:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 var(--ink);
}

.comic-btn:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #fde047, #f59e0b);
}
.btn-secondary {
  background: linear-gradient(180deg, #60a5fa, #2563eb);
  color: #fff;
}
.btn-accent {
  background: linear-gradient(180deg, #34d399, #0d9488);
  color: #fff;
}
.btn-danger {
  background: linear-gradient(180deg, #f87171, #dc2626);
  color: #fff;
}
.btn-small {
  font-size: 13px;
  padding: 9px 10px;
}
.btn-compact {
  padding: 9px 18px;
}

/* Modal Headers & Lists */
.modal-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  border-bottom: 3px solid var(--ink);
  padding-bottom: 10px;
}

.modal-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
}

.modal-footer {
  margin-top: 16px;
  display: flex;
  justify-content: flex-start;
}

.unlock-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 13px;
  background: #fef08a;
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.chapter-card {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 3px 3px 0 var(--ink);
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.chapter-card.locked {
  opacity: 0.65;
  background: #e2e8f0;
}

.chapter-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.chapter-tag {
  font-family: var(--font-display);
  font-size: 11px;
  background: var(--cobalt);
  color: #fff;
  padding: 2px 8px;
  border-radius: 6px;
  border: 2px solid var(--ink);
}

.chapter-stars {
  font-size: 15px;
  color: #f59e0b;
}

.chapter-card h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 17px;
}

.chapter-card p {
  margin: 0;
  font-size: 13px;
  color: #334155;
  line-height: 1.35;
}

.outfits-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px;
}

.outfit-card {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 3px 3px 0 var(--ink);
  padding: 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.outfit-swatch {
  width: 52px;
  height: 52px;
  margin: 0 auto;
  border-radius: 12px;
  border: 3px solid var(--ink);
  display: grid;
  place-items: center;
  font-size: 24px;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px;
}

.control-card {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 12px;
}

.control-card h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 16px;
}

.control-card ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.45;
}

.scheme-pill {
  background: #dcfce7;
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 4px 10px;
  font-family: var(--font-display);
  font-size: 12px;
}

/* Comic Dialogue Overlay */
.dialogue-box {
  max-width: 680px;
  background: linear-gradient(180deg, #fffdf5 0%, #fef9c3 100%);
}

.dialogue-top {
  display: flex;
  gap: 16px;
  align-items: center;
}

.portrait-frame {
  flex-shrink: 0;
  width: 112px;
  height: 112px;
  border-radius: 14px;
  border: 4px solid var(--ink);
  background: #e0f2fe;
  box-shadow: 4px 4px 0 var(--ink);
  overflow: hidden;
}

.portrait-frame canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.dialogue-body {
  flex: 1;
  min-width: 0;
}

.dialogue-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.speaker-tag {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 900;
  background: var(--crimson);
  color: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 8px;
  padding: 3px 10px;
}

.sfx-burst {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 900;
  background: var(--gold);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 2px 10px;
  transform: rotate(3deg);
}

.dialogue-text {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.45;
  color: var(--ink);
}

.dialogue-footer {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 2px dashed #94a3b8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dialogue-dots {
  display: flex;
  gap: 6px;
}

.dialogue-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #cbd5e1;
  border: 2px solid var(--ink);
}

.dialogue-dot.active {
  background: var(--crimson);
  transform: scale(1.2);
}

.dialogue-actions {
  display: flex;
  gap: 8px;
}

/* Result Overlay */
.result-banner {
  text-align: center;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--ink);
  -webkit-text-stroke: 1.5px var(--ink);
}

.result-banner.fail {
  color: var(--crimson);
}

.result-stars {
  text-align: center;
  font-size: 32px;
  color: #f59e0b;
  margin: 4px 0;
  text-shadow: 2px 2px 0 var(--ink);
}

.subtitle-text {
  text-align: center;
  font-weight: 700;
  color: #334155;
  margin: 4px 0 14px;
}

.result-stats {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 14px;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 16px;
}

.result-stats .stat-val {
  text-align: right;
  font-family: var(--font-display);
  color: var(--cobalt);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

/* ===========================
   MOBILE / PORTRAIT ADAPTATIONS
=========================== */
@media (max-width: 680px) {
  .hud {
    flex-wrap: wrap;
    padding: 8px;
    gap: 6px;
  }

  .hud-left {
    order: 1;
  }

  .hud-right {
    order: 2;
    margin-left: auto;
  }

  .hud-center {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .objective-pill {
    width: 100%;
    min-width: 0;
    padding: 5px 8px;
  }

  .objective-hint {
    max-width: 92vw;
    font-size: 11px;
  }

  .wanted-pill {
    min-width: 96px;
    padding: 5px 8px;
  }

  .wanted-stars {
    font-size: 13px;
  }

  .timer-display {
    font-size: 16px;
  }

  .objective-counter {
    font-size: 13px;
  }

  .hud-icon-btn {
    width: 36px;
    height: 36px;
    font-size: 15px;
  }

  .hud-pause-btn {
    width: auto;
    padding: 0 8px;
    font-size: 11px;
  }

  .toast-banner {
    top: 124px;
    font-size: 12px;
    padding: 6px 12px;
  }

  .toast-banner.toast-top {
    top: 12px;
  }

  .action-btn {
    padding: 11px 15px;
    right: 12px;
    bottom: 14px;
  }

  .action-btn.above-bottom-hud {
    bottom: 146px;
  }

  .dialogue-top {
    flex-direction: column;
    text-align: center;
  }

  .portrait-frame {
    width: 92px;
    height: 92px;
  }

  .menu-subrow {
    grid-template-columns: 1fr;
  }
}
