/* ============================================
   HEISENBERG'S EMPIRE — MASTER STYLESHEET
   Breaking Bad palette. Green-dominant. NOT blue.
   ============================================ */

:root {
  /* Background */
  --bg-primary: #0c0e09;
  --bg-secondary: #111408;
  --bg-tertiary: #1a1e0f;

  /* Accents */
  --accent-main: #7ab648;
  --accent-light: #a8d060;
  --accent-money: #d4a017;
  --accent-meth: #4fc3f7;       /* PRODUCT ONLY — never UI accent */
  --accent-danger: #c03018;
  --accent-desert: #c8b878;

  /* Text */
  --text-primary: #dde8cc;
  --text-muted: #5a6640;
  --text-border: #2a3018;

  /* Derived */
  --health-fill: #d0d0d0;
  --heisenberg-fill: #8b1a1a;
  --suspicion-fill: #c03018;
  --stability-fill: #a8d060;

  /* Sizing */
  --font-base: 15px;
  --font-sm: 12.5px;
  --font-lg: 19px;
  --font-xl: 23px;
  --bar-height: 10px;
}

/* ============================================
   RESET & BASE
   ============================================ */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Courier New', 'Consolas', monospace;
  font-size: var(--font-base);
  line-height: 1.4;
}

/* Global scrollbar styling */
* { scrollbar-width: thin; scrollbar-color: #5a6640 #1a1e0f; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #1a1e0f; }
::-webkit-scrollbar-thumb { background: #5a6640; border-radius: 4px; border: 2px solid #1a1e0f; }
::-webkit-scrollbar-thumb:hover { background: #7ab648; }

/* ── Overlay fade transition (shared) ── */
.overlay-fade {
  opacity: 0;
  transition: opacity 150ms ease;
}

.overlay-fade--visible {
  opacity: 1;
}

/* ============================================
   CINEMATIC BACKGROUND SYSTEM (shared by all major screens)
   See public/js/saveload.js BackgroundLoader.setScreenBackground()
   ============================================ */
/*
 * Layers use NEGATIVE z-index so normal-flow + absolute children of the host
 * render on top without us having to force their position/z-index. The host
 * gets `isolation: isolate` so the negative indices are clipped to it and
 * can't escape into the parent stacking context.
 */
.has-cinematic-bg {
  background-color: transparent !important;
  isolation: isolate;
}

.cinematic-bg {
  position: absolute;
  inset: 0;
  background-color: #0c0e09;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  filter: blur(4px) brightness(0.55);   /* stronger blur so UI stays legible on every screen */
  z-index: -3;
  opacity: 0;
  transition: opacity 300ms ease;
  pointer-events: none;
}
.cinematic-bg--shown { opacity: 1; }
.cinematic-bg--diagnosis { filter: blur(8px) brightness(0.5); }
.cinematic-bg--heavy    { filter: blur(6px) brightness(0.45); }  /* key-tab overlays (Empire/Criminal/Psychology/DEA/Home) */
.cinematic-bg--warm     { /* tonal hint for Gus meeting; image carries the colour */ }

.cinematic-grain { display: none; }

.cinematic-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(12,14,9,0.85) 100%);
  pointer-events: none;
  z-index: -1;
}

/* Optional wrapper for UI content (no longer required — kept for back-compat) */
.screen-content {
  position: relative;
  z-index: 0;
}

/* Convenience: full-bleed black fade used by diagnosis exit + Gus stare */
.cinematic-fade-to-black {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  z-index: 9;
  pointer-events: none;
  transition: opacity 2000ms ease;
}
.cinematic-fade-to-black--on { opacity: 1; }

/* ============================================
   LAYOUT — Full-screen grid
   ============================================ */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--text-border);
  z-index: 10;
}

.game-grid {
  display: grid;
  grid-template-columns: 195px 1fr;
  position: relative;
  height: calc(100vh - 64px - 40px);
}

.bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  padding: 0 14px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--text-border);
}

/* ============================================
   TOP BAR
   ============================================ */

.top-bar__left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.portrait-frame {
  width: 46px;
  height: 46px;
  border: 2px solid var(--accent-main);
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
}

.portrait-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-size: var(--font-xl);
  font-weight: bold;
  /* Phase 13 — fade on stage transitions */
  transition: opacity 300ms ease;
  opacity: 1;
}
.portrait-placeholder--fading {
  opacity: 0;
}
.portrait-placeholder--fallback {
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  font-family: 'Courier New', monospace;
}

.top-bar__bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
}

.top-bar__center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.time-display {
  font-size: var(--font-lg);
  font-weight: bold;
  color: var(--text-primary);
  letter-spacing: 1px;
}

.time-display__separator {
  color: var(--text-muted);
  margin: 0 2px;
}

.speed-indicator__label {
  font-size: var(--font-sm);
  color: var(--accent-main);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.top-bar__right {
  display: flex;
  align-items: center;
}

.hotkey-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  max-width: 320px;
  justify-content: flex-end;
}

.hotkey-hint {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ============================================
   STAT BARS (reusable)
   ============================================ */

.stat-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-bar__label {
  font-size: var(--font-sm);
  color: var(--text-muted);
  min-width: 90px;
}

.stat-bar__track {
  flex: 1;
  height: var(--bar-height);
  background: var(--bg-primary);
  border: 1px solid var(--text-border);
  border-radius: 2px;
  overflow: hidden;
  min-width: 80px;
}

.stat-bar__fill {
  height: 100%;
  transition: width 0.3s ease;
}

.stat-bar__fill--health {
  background: var(--health-fill);
}

.stat-bar__fill--heisenberg {
  background: var(--heisenberg-fill);
}

.stat-bar__fill--heat {
  background: var(--accent-danger);
}

.stat-bar__fill--rep {
  background: var(--accent-money);
}

.stat-bar__fill--relationship {
  background: var(--accent-main);
}

.stat-bar__fill--suspicion {
  background: var(--accent-danger);
}

.stat-bar__fill--stability {
  background: var(--stability-fill);
}

.stat-bar__value {
  font-size: var(--font-sm);
  color: var(--text-muted);
  min-width: 32px;
  text-align: right;
}

.stat-bar__value--small {
  font-size: 12px;
  min-width: 24px;
}

/* Inline variant (inside resource rows / character cards) */
.stat-bar--inline {
  flex: 1;
  gap: 6px;
}

.stat-bar--inline .stat-bar__track {
  height: 8px;
  min-width: 60px;
}

/* ============================================
   LEFT PANEL — Resources
   ============================================ */

.panel {
  padding: 12px;
  background: var(--bg-secondary);
  overflow-y: auto;
}

.panel--left {
  border-right: 1px solid var(--text-border);
  min-width: 195px;
  max-width: 195px;
  overflow: hidden;
}

.panel--right {
  position: absolute;
  top: 0;
  right: 0;
  width: 220px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(12,14,9,0.92);
  border-left: 1px solid var(--text-border);
  padding: 8px;
  overflow-y: auto;
  max-height: 100%;
  z-index: 10;
}
.panel--right > * {
  width: 100%;
  box-sizing: border-box;
}

/* When the right column shows territory/location info, chips/buttons stack vertically */
.panel--right .dh-chip {
  display: block;
  margin: 0;
}
.panel--right .dh-btn {
  display: block;
  width: 100%;
  text-align: left;
  margin-top: 4px;
}

.panel__title {
  font-size: var(--font-sm);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 12px;
}

.resource {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  flex-wrap: wrap;
}

.resource__icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-base);
  flex-shrink: 0;
}

.resource__icon--dirty { color: var(--accent-money); }
.resource__icon--clean { color: var(--accent-main); }
.resource__icon--product { color: var(--accent-meth); }
.resource__icon--methyl { color: var(--text-muted); }
.resource__icon--heat { color: var(--accent-danger); }
.resource__icon--rep { color: var(--accent-money); }

.resource__label {
  font-size: var(--font-sm);
  color: var(--text-muted);
  flex: 1;
  min-width: 70px;
}

.resource__value {
  font-size: var(--font-sm);
  font-weight: bold;
  text-align: right;
}

.resource__value--money { color: var(--accent-money); }
.resource__value--clean { color: var(--accent-main); }
.resource__value--product { color: var(--accent-meth); }

.divider {
  height: 1px;
  background: var(--text-border);
  margin: 10px 0;
}

/* ============================================
   CENTER — Map
   ============================================ */

.map-container {
  position: relative;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Detail view header (shown when zoomed into territory) */
/* Location pin tooltips */
.map-tooltip {
  position: absolute;
  padding: 6px 10px;
  background: rgba(12, 14, 9, 0.95);
  border: 1px solid var(--text-border);
  border-radius: 3px;
  font-size: 12px;
  color: var(--text-primary);
  max-width: 180px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 10;
  line-height: 1.4;
}

.map-tooltip--visible {
  opacity: 1;
}

.map-tooltip--criminal { border-color: var(--accent-main); }
.map-tooltip--distribution { border-color: var(--accent-money); }
.map-tooltip--threat { border-color: var(--accent-danger); }
.map-tooltip--story { border-color: var(--accent-desert); }
.map-tooltip--unknown { border-color: var(--text-muted); }

.map-tooltip__desc {
  color: var(--text-muted);
  font-size: 11px;
}

/* Pin pulse animation for active events */
@keyframes pin-pulse {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 0.5; }
}

.pin--active circle {
  animation: pin-pulse 2s ease-in-out infinite;
}

/* Phase 11 — pulsing Saul's office pin when there's an unread Saul reminder */
.pin--pulse circle {
  animation: pin-pulse 1.2s ease-in-out infinite;
  stroke: var(--accent-money);
  stroke-width: 2;
}

.map-placeholder {
  text-align: center;
}

.map-placeholder__text {
  display: block;
  font-size: 38px;
  font-weight: bold;
  color: var(--text-border);
  letter-spacing: 8px;
  text-transform: uppercase;
}

.map-placeholder__sub {
  display: block;
  font-size: var(--font-sm);
  color: var(--text-muted);
  margin-top: 8px;
}

/* ============================================
   RIGHT PANEL — Characters
   ============================================ */

.character-card {
  display: flex;
  gap: 6px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--text-border);
  transition: background 0.15s ease;
}

.character-card:hover {
  background: var(--bg-tertiary);
}

.character-card--locked {
  opacity: 0.5;
}

.character-card__portrait {
  width: 28px;
  height: 28px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: var(--font-lg);
  flex-shrink: 0;
  border: 2px solid var(--accent-main);
  background: var(--bg-tertiary);
  color: var(--text-muted);
}

/* Portrait border colors — will map to relationship later */
.character-card__portrait--jesse { border-color: var(--accent-main); }
.character-card__portrait--skyler { border-color: var(--accent-main); }
.character-card__portrait--hank { border-color: var(--accent-main); }
.character-card__portrait--saul { border-color: var(--text-muted); }
.character-card__portrait--flynn { border-color: var(--accent-main); }
.character-card__portrait--gus { border-color: var(--text-muted); }

.character-card__info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.character-card__name {
  font-size: var(--font-sm);
  font-weight: bold;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.character-card__stat {
  display: flex;
  align-items: center;
  gap: 6px;
}

.character-card__stat-label {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 84px;
  display: inline-block;
  flex-shrink: 0;
  padding-right: 6px;
  white-space: nowrap;
}

.character-card__locked {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

.character-card__status {
  font-size: 10px;
  font-style: italic;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ============================================
   Right-column chip/button helpers (used by territory + location views)
   ============================================ */

.dh-chip {
  font-size: 11px;
  color: var(--text-primary);
  padding: 3px 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--text-border);
  border-radius: 2px;
}

.dh-action {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dh-action__label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.dh-action__val {
  font-size: 12px;
  color: var(--text-primary);
  font-weight: bold;
  min-width: 40px;
}

.dh-action__preview {
  font-size: 11px;
  color: var(--accent-money);
  min-width: 80px;
}

.tp-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 5px;
  background: var(--bg-primary);
  border: 1px solid var(--text-border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.tp-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--accent-main);
  cursor: pointer;
  border: 1px solid var(--accent-light);
}

.tp-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--accent-main);
  cursor: pointer;
  border: 1px solid var(--accent-light);
}

.dh-btn {
  padding: 4px 10px;
  border: 1px solid var(--text-border);
  border-radius: 2px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
  letter-spacing: 0.04em;
}

.dh-btn:hover:not(.dh-btn--disabled) {
  background: var(--bg-tertiary);
  border-color: var(--accent-money);
  box-shadow: 0 0 6px rgba(212, 160, 23, 0.18);
}

.dh-btn:active {
  transform: scale(0.97);
}

.dh-btn--disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.dh-btn--primary {
  border-color: var(--accent-main);
  color: var(--accent-light);
}

.dh-note {
  font-size: 10px;
  color: var(--text-muted);
  font-style: italic;
}

/* Scout option card */
.scout-option {
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--text-border);
  border-radius: 2px;
  font-family: 'Courier New', monospace;
  transition: border-color 0.15s;
}

.scout-option[data-available="1"]:hover {
  border-color: var(--accent-main);
}

/* ============================================
   BOTTOM BAR — Speed Controls
   ============================================ */

.speed-controls {
  display: flex;
  gap: 4px;
}

.speed-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--text-border);
  color: var(--text-muted);
  padding: 4px 10px;
  font-size: var(--font-sm);
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.1s, color 0.1s, box-shadow 0.1s;
  font-family: inherit;
}

.speed-btn:hover {
  background: var(--bg-primary);
  color: var(--accent-main);
  box-shadow: 0 0 6px rgba(122, 182, 72, 0.2);
}

.speed-btn--active {
  background: var(--accent-main);
  color: var(--bg-primary);
  border-color: var(--accent-main);
  font-weight: bold;
}

.speed-btn--active:hover {
  background: var(--accent-light);
  color: var(--bg-primary);
}

/* Button press animation */
.speed-btn:active {
  transform: scale(0.97);
}

.version-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--text-border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============================================
   Bug-fix Pass 3 Group 1 — right column owns territory/location info
   (#map-right-panel floating overlay deleted; .panel--right is the single right column)
   ============================================ */

.mrp-back {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  padding: 0 0 6px 0;
  cursor: pointer;
  letter-spacing: 0.05em;
  text-align: left;
  width: auto !important;
  align-self: flex-start;
}
.mrp-back:hover { color: var(--accent-main); }

.mrp-header {
  font-size: 18px;
  font-weight: bold;
  color: var(--text-primary);
}

.mrp-status {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  margin-top: -4px;
}

.mrp-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--text-border);
}

.mrp-section__title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.mrp-req {
  font-size: 12px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.mrp-req--ok { color: var(--accent-money); }
.mrp-req--bad { color: var(--accent-danger); }
.mrp-req__icon { display: inline-block; width: 14px; text-align: center; }

.mrp-msg {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.5;
}
.mrp-msg--good { color: var(--accent-money); font-style: normal; }
.mrp-msg--bad { color: var(--accent-danger); font-style: normal; }

/* ============================================
   PHASE 20 — Patron Walter monologue cards
   ============================================ */

.event-card-overlay--monologue .event-card {
  border: 2px solid #d4a017 !important;
  box-shadow: 0 0 40px rgba(212, 160, 23, 0.25);
}
.event-card--monologue .event-card__subtitle {
  color: #d4a017;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-size: 10px;
}

/* ============================================
   PHASE 22 — Minimum-viable responsive (below 1024px)
   Hide side panels, stack the grid, let map fill width.
   Not full mobile support — just "doesn't completely break."
   ============================================ */

@media (max-width: 1023px) {
  .game-grid {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto auto auto;
  }
  .panel--left,
  .panel--right {
    display: none;
  }
  .top-bar {
    padding: 4px 8px;
    flex-wrap: wrap;
  }
  .map-container {
    min-height: 60vh;
  }
}

/* Bug-fix Pass 3 — bills modal checkboxes (override default browser blue) */
#bills-modal input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border: 1px solid var(--accent-main, #7ab648);
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.4);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  margin: 0;
  transition: background 0.15s, border-color 0.15s;
}
#bills-modal input[type="checkbox"]:checked {
  background: var(--accent-main, #7ab648);
  border-color: var(--accent-main, #7ab648);
}
#bills-modal input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 0px;
  width: 5px;
  height: 10px;
  border: solid #0c0e09;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
#bills-modal input[type="checkbox"]:disabled {
  border-color: var(--accent-danger, #c03018);
  cursor: not-allowed;
  opacity: 0.6;
}
