/* ============================================================
   ROOT LAYOUT — WRIST UI 3000 (AFTERFALL STYLE)
   ============================================================ */

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: #050705;
  font-family: "Consolas", "Courier New", monospace;
}

body.pipboy-mode {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9fe88d;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ============================================================
   OUTER DEVICE
   ============================================================ */

.pipboy-root {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

@media (orientation: portrait) { .pipboy-root { flex-direction: column; } }
@media (orientation: landscape) { .pipboy-root { flex-direction: row; } }

.pipboy-bezel {
  width: 100%;
  height: 100%;
  padding: 12px;
  background: radial-gradient(circle at top left, #1b2e18 0%, #050705 60%, #000 100%);
  border-radius: 24px;
  box-shadow: 0 0 40px rgba(0,0,0,0.9), inset 0 0 30px rgba(0,0,0,0.9);
}

.pipboy-frame {
  width: 100%;
  height: 100%;
  background: #050705;
  border-radius: 18px;
  border: 3px solid #304b2b;
  box-shadow: inset 0 0 8px rgba(0,0,0,0.9);
  position: relative;
  overflow: hidden;
}

/* ============================================================
   CRT
   ============================================================ */

.pipboy-crt {
  position: relative;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, #102310 0%, #050705 60%, #020302 100%);
  color: #9fe88d;
  overflow: hidden;
}

.pipboy-crt, .pipboy-crt * {
  box-sizing: border-box;
  color: #9fe88d;
  text-shadow: 0 0 4px rgba(0,255,65,0.4);
}

.pipboy-crt::after {
  content: "";
  position: absolute;
  inset: -40px;
  border-radius: 999px;
  box-shadow:
    0 0 40px rgba(0,255,65,0.12),
    0 0 140px rgba(0,255,65,0.18);
  pointer-events: none;
}

.pipboy-noise,
.pipboy-scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 1;
}

.pipboy-noise {
  background-image: url("data:image/svg+xml,%3Csvg width='160' height='160' viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n' x='0' y='0'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.2' numOctaves='4' stitchTiles='noStitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E");
  mix-blend-mode: screen;
}

.pipboy-scanlines {
  background-image: linear-gradient(to bottom, rgba(0,0,0,0.45) 1px, transparent 2px);
  background-size: 100% 3px;
  opacity: 0.3;
  animation: scanline-flicker 2.2s infinite ease-in-out;
}

@keyframes scanline-flicker {
  0%,100% { opacity: 0.25; }
  50% { opacity: 0.4; }
}

/* ============================================================
   HEADER + TABS
   ============================================================ */

.pipboy-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 10px 18px 4px;
  border-bottom: 1px solid rgba(159,232,141,0.2);
  z-index: 2;
}

.pipboy-title { font-size: 18px; letter-spacing: 0.16em; text-transform: uppercase; }
.pipboy-subtitle { font-size: 10px; opacity: 0.7; margin-top: 2px; }

.pipboy-tabs {
  display: flex;
  padding: 4px 10px 6px;
  border-bottom: 1px solid rgba(159,232,141,0.18);
  gap: 4px;
  z-index: 2;
}

.pipboy-tab {
  background: transparent;
  border: 1px solid rgba(159,232,141,0.3);
  border-radius: 2px;
  font-size: 11px;
  letter-spacing: 0.14em;
  padding: 2px 10px;
  cursor: pointer;
  text-transform: uppercase;
  text-shadow: 0 0 4px rgba(159,232,141,0.7);
}

.pipboy-tab.active {
  background: rgba(159,232,141,0.14);
  box-shadow: 0 0 8px rgba(159,232,141,0.5), inset 0 0 4px rgba(0,0,0,0.9);
}

/* ============================================================
   MAIN PANEL
   ============================================================ */

.pipboy-main {
  position: relative;
  height: calc(100vh - 140px);
  height: calc(100dvh - 140px);
  padding: 6px 10px;
  z-index: 2;
  overflow: hidden;
}

.pipboy-panel {
  position: absolute;
  inset: 0;
  background: #041f04;
  padding: 16px;
  opacity: 0;
  transform: translateX(-16px);
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  display: flex;
  flex-direction: column;
  /* Allow scrolling inside child elements, not the panel itself */
  overflow: hidden;
}

.pipboy-panel.active {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.pipboy-panel.has-compass {
  position: relative;
}

/* General panel-body - scrollable content area */
.panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* Map panel specific - fill available space */
#panel-map {
  padding: 8px;
  display: flex;
  flex-direction: column;
  height: 100%;
}

#panel-map .panel-header {
  flex-shrink: 0;
  margin-bottom: 8px;
}

#panel-map .panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  height: 100%;
}

/* ============================================================
   MAP PANEL — FINAL
   ============================================================ */

.pipboy-map {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 400px;
  height: 100%;
  border: 2px solid rgba(0,255,65,0.35);
  box-shadow: inset 0 0 20px rgba(0,0,0,0.9), 0 0 12px rgba(0,255,65,0.25);
}

#mapContainer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#mapContainer .leaflet-container {
  width: 100%;
  height: 100%;
  background: transparent;
  /* Touch-action allows pan and pinch-zoom gestures */
  touch-action: none !important;
  pointer-events: auto !important;
}

#mapContainer .leaflet-tile {
  /* Increased brightness from 0.55 to 0.85 for better visibility while maintaining Pip-Boy aesthetic */
  filter: brightness(0.85) contrast(1.2) saturate(0.6) hue-rotate(85deg);
}

/* Grid */
#mapContainer::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(0,255,65,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,255,65,0.05) 1px, transparent 1px);
  background-size: 40px 40px;
  z-index: 40;
}

/* CRT overlay - reduced opacity for better visibility while maintaining Pip-Boy feel */
#mapContainer::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(0,0,0,0.10) 1px, transparent 2px),
    radial-gradient(circle at center, rgba(0,255,65,0.03) 0%, rgba(0,0,0,0.25) 90%);
  mix-blend-mode: overlay;
  opacity: 0.25;
  z-index: 50;
}

/* GPS badge */
.gps-badge {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 2002;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid #00ff41;
  background: rgba(0,0,0,0.85);
  font-size: 11px;
  color: #8fef7a;
  box-shadow: 0 0 8px rgba(0,255,65,0.4);
}

.acc-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.acc-good { background: #00ff41; }
.acc-fair { background: #ffaa00; }
.acc-bad { background: #ff4444; }

/* ============================================================
   MARKERS - No bleeding glow
   ============================================================ */

.leaflet-marker-icon {
  /* Removed drop-shadow to prevent glow bleeding */
}

/* ============================================================
   MAP INTERACTION FIX
   Enables touch gestures (pan, pinch-zoom) on mobile devices
   while preventing page-level swipe/scroll interference
   ============================================================ */

#mapContainer {
  pointer-events: auto !important;
  /* Allow Leaflet to handle its own touch gestures - don't override */
  -webkit-user-select: none;
  user-select: none;
  /* Prevent scroll chaining to parent containers */
  overscroll-behavior: contain;
}

/* Leaflet panes and tile layers should allow touch through */
#mapContainer .leaflet-pane,
#mapContainer .leaflet-tile-pane,
#mapContainer .leaflet-overlay-pane {
  /* Let Leaflet handle touch - don't override */
  pointer-events: auto !important;
}

/* Map panel should not interfere with map touch events */
#panel-map {
  overflow: hidden !important;
  /* Allow touch to pass through to map - don't override Leaflet */
}

#panel-map .panel-body {
  overflow: hidden !important;
  /* Let Leaflet control touch behavior */
  overscroll-behavior: contain;
}

/* Prevent parent elements from capturing touch events */
.pipboy-map {
  /* Let Leaflet handle map gestures */
  -webkit-overflow-scrolling: auto !important;
  overscroll-behavior: contain;
}

/* Ensure radFlash and other overlays don't block touches */
#radFlash,
#mapContainer::before,
#mapContainer::after {
  pointer-events: none !important;
}

.leaflet-control-container { display: none; }

/* ============================================================
   WRIST UI BUTTONS - AFTERFALL THEMED
   ============================================================ */

/* Base button style - HavenTech terminal aesthetic */
button,
.pipboy-button,
.pipboy-button-small {
  background: rgba(0, 0, 0, 0.85);
  color: #00ff41;
  border: 2px solid #00ff41;
  padding: 8px 16px;
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 16px;
  font-weight: bold;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-shadow: 0 0 5px rgba(0, 255, 65, 0.7);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 
    inset 0 0 8px rgba(0, 255, 65, 0.2),
    0 0 12px rgba(0, 255, 65, 0.3);
  position: relative;
  overflow: hidden;
}

/* Small button variant */
.pipboy-button-small {
  padding: 4px 12px;
  font-size: 14px;
}

/* Hover state - amber glow like Pip-Boy selections */
button:hover,
.pipboy-button:hover,
.pipboy-button-small:hover {
  background: rgba(0, 255, 65, 0.15);
  color: #ffaa00;
  border-color: #ffaa00;
  text-shadow: 0 0 8px rgba(255, 170, 0, 0.9);
  box-shadow: 
    inset 0 0 12px rgba(255, 170, 0, 0.3),
    0 0 20px rgba(255, 170, 0, 0.5);
  transform: translateY(-1px);
}

/* Active/pressed state */
button:active,
.pipboy-button:active,
.pipboy-button-small:active {
  background: rgba(0, 255, 65, 0.25);
  transform: translateY(0);
  box-shadow: 
    inset 0 0 15px rgba(0, 255, 65, 0.5),
    0 0 8px rgba(0, 255, 65, 0.3);
}

/* Disabled state - faded out */
button:disabled,
.pipboy-button:disabled,
.pipboy-button-small:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: rgba(0, 0, 0, 0.6);
  border-color: rgba(0, 255, 65, 0.3);
  text-shadow: none;
  box-shadow: none;
}

/* Scanline effect on buttons */
button::before,
.pipboy-button::before,
.pipboy-button-small::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(0, 255, 65, 0.2),
    transparent
  );
  transition: left 0.5s ease;
  pointer-events: none;
}

button:hover::before,
.pipboy-button:hover::before,
.pipboy-button-small:hover::before {
  left: 100%;
}

/* Danger/warning button variant (for admin/reset actions) */
button.danger,
.pipboy-button.danger {
  border-color: #ff4444;
  color: #ff4444;
  text-shadow: 0 0 5px rgba(255, 68, 68, 0.7);
  box-shadow: 
    inset 0 0 8px rgba(255, 68, 68, 0.2),
    0 0 12px rgba(255, 68, 68, 0.3);
}

button.danger:hover,
.pipboy-button.danger:hover {
  background: rgba(255, 68, 68, 0.15);
  border-color: #ff6666;
  text-shadow: 0 0 8px rgba(255, 68, 68, 0.9);
  box-shadow: 
    inset 0 0 12px rgba(255, 68, 68, 0.3),
    0 0 20px rgba(255, 68, 68, 0.5);
}

/* Success/confirm button variant */
button.success,
.pipboy-button.success {
  border-color: #00d4ff;
  color: #00d4ff;
  text-shadow: 0 0 5px rgba(0, 212, 255, 0.7);
  box-shadow: 
    inset 0 0 8px rgba(0, 212, 255, 0.2),
    0 0 12px rgba(0, 212, 255, 0.3);
}

button.success:hover,
.pipboy-button.success:hover {
  background: rgba(0, 212, 255, 0.15);
  border-color: #00e4ff;
  text-shadow: 0 0 8px rgba(0, 212, 255, 0.9);
  box-shadow: 
    inset 0 0 12px rgba(0, 212, 255, 0.3),
    0 0 20px rgba(0, 212, 255, 0.5);
}

/* Make sure all buttons inherit Pip-Boy theming */
input[type="button"],
input[type="submit"],
input[type="reset"] {
  background: rgba(0, 0, 0, 0.85);
  color: #00ff41;
  border: 2px solid #00ff41;
  padding: 8px 16px;
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 16px;
  font-weight: bold;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-shadow: 0 0 5px rgba(0, 255, 65, 0.7);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 
    inset 0 0 8px rgba(0, 255, 65, 0.2),
    0 0 12px rgba(0, 255, 65, 0.3);
}

input[type="button"]:hover,
input[type="submit"]:hover,
input[type="reset"]:hover {
  background: rgba(0, 255, 65, 0.15);
  color: #ffaa00;
  border-color: #ffaa00;
  text-shadow: 0 0 8px rgba(255, 170, 0, 0.9);
  box-shadow: 
    inset 0 0 12px rgba(255, 170, 0, 0.3),
    0 0 20px rgba(255, 170, 0, 0.5);
}

/* ============================================================
   QUEST UI STYLES
   ============================================================ */

.quest-entry {
  padding: 12px;
  margin-bottom: 12px;
  border: 1px solid rgba(0, 255, 65, 0.3);
  background: rgba(0, 0, 0, 0.3);
}

.quest-entry.active {
  border-color: #00ff41;
  background: rgba(0, 255, 65, 0.05);
}

.quest-title {
  font-size: 1.2em;
  font-weight: bold;
  color: #00ff41;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.quest-description {
  font-size: 0.9em;
  color: #9fe88d;
  margin-bottom: 12px;
  opacity: 0.9;
}

.quest-objectives {
  margin-top: 8px;
}

.quest-objective {
  padding: 4px 0;
  color: #9fe88d;
  font-size: 0.95em;
}

.quest-objective.completed {
  color: #00ff41;
  text-decoration: line-through;
  opacity: 0.7;
}

/* ============================================================
   NPC DIALOGUE STYLES - FALLOUT-STYLE
   ============================================================ */

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog-npc-portrait {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

.dialog-npc-icon {
  width: 80px;
  height: 80px;
  border: 2px solid #00ff41;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  background: rgba(0, 255, 65, 0.1);
  box-shadow: 0 0 20px rgba(0, 255, 65, 0.3), inset 0 0 10px rgba(0, 255, 65, 0.1);
}

.dialog-header-row {
  text-align: center;
  margin-bottom: 4px;
}

.dialog-npc-name {
  font-size: 1.4em;
  font-weight: bold;
  color: #00ff41;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  text-shadow: 0 0 8px rgba(0, 255, 65, 0.7);
}

.dialog-npc-desc {
  text-align: center;
  font-size: 0.85em;
  color: #9fe88d;
  opacity: 0.8;
  font-style: italic;
  margin-bottom: 8px;
}

.dialog-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, #00ff41, transparent);
  margin: 8px 0;
}

.dialog-text {
  font-size: 1.05em;
  line-height: 1.6;
  color: #9fe88d;
  padding: 12px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(0, 255, 65, 0.2);
  border-radius: 4px;
  text-shadow: 0 0 2px rgba(0, 255, 65, 0.3);
}

/* Starter gear notification */
.starter-gear-list {
  margin-top: 12px;
  padding: 10px;
  background: rgba(0, 255, 65, 0.05);
  border: 1px solid rgba(0, 255, 65, 0.3);
}

.starter-gear-list h4 {
  color: #ffaa00;
  margin-bottom: 8px;
  font-size: 0.9em;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.starter-gear-item {
  padding: 4px 0;
  color: #9fe88d;
  font-size: 0.9em;
}

.starter-gear-item::before {
  content: "• ";
  color: #00ff41;
}

/* ============================================================
   QUEST PANEL STYLES
   ============================================================ */

.pip-entry {
  margin-bottom: 12px;
  padding: 8px;
  background: rgba(0, 255, 65, 0.05);
  border-radius: 4px;
}

.pip-entry.active {
  border-left: 3px solid #00ff41;
}

.pip-entry.done {
  opacity: 0.6;
}

.pip-entry.available-quest {
  border-left: 3px solid #ffaa00;
  background: rgba(255, 170, 0, 0.05);
}

/* ── Battle Panel ─────────────────────────────────────────── */
.battle-idle,
.battle-active {
  padding: 8px;
  font-family: var(--pip-font, 'VT323', monospace);
  font-size: 1em;
  color: var(--pip-green, #00ff41);
}

.battle-status-header,
.battle-label-header {
  font-size: 1.1em;
  letter-spacing: 2px;
  border-bottom: 1px solid currentColor;
  margin-bottom: 8px;
  padding-bottom: 4px;
  opacity: 0.8;
}

.battle-stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
}

.battle-label {
  min-width: 80px;
  opacity: 0.7;
  font-size: 0.9em;
}

.battle-val {
  opacity: 0.95;
}

.battle-bar-wrap {
  flex: 1;
  height: 10px;
  background: rgba(0, 255, 65, 0.15);
  border: 1px solid rgba(0, 255, 65, 0.4);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.battle-bar {
  height: 100%;
  background: #00ff41;
  transition: width 0.3s ease;
}

.battle-bar.enemy-bar {
  background: #ff4141;
}

.battle-combatant {
  margin-bottom: 10px;
}

.battle-enemy-name {
  font-size: 1.15em;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.battle-vs {
  text-align: center;
  font-size: 1.2em;
  opacity: 0.5;
  margin: 4px 0;
}

.battle-gear-line {
  font-size: 0.88em;
  opacity: 0.75;
  margin: 4px 0;
}

.battle-special-row {
  display: flex;
  gap: 6px;
  margin: 8px 0 4px;
  flex-wrap: wrap;
}

.battle-special-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid rgba(0, 255, 65, 0.35);
  border-radius: 3px;
  padding: 2px 5px;
  min-width: 28px;
}

.bs-key {
  font-size: 0.72em;
  opacity: 0.7;
  letter-spacing: 1px;
}

.bs-val {
  font-size: 1em;
}

.battle-options {
  display: flex;
  gap: 10px;
  margin: 12px 0 8px;
}

.battle-msg {
  min-height: 1.4em;
  color: #ffcc00;
  font-size: 1em;
  margin-top: 6px;
}

.battle-idle-note {
  margin-top: 10px;
  opacity: 0.5;
  font-size: 0.85em;
}

/* ============================================================
   BOOT SCREEN (BUG-008)
   ============================================================ */
#bootScreen {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 9999;
}
#bootText {
  font-family: 'VT323', 'Courier New', monospace;
  font-size: clamp(10px, 2.5vw, 16px);
  color: #00ff41;
  white-space: pre-wrap;
  overflow: hidden;
  max-width: 100vw;
  text-align: center;
  padding: 0 12px;
  line-height: 1.4;
}

/* ============================================================
   MAP LOG OVERLAY (BUG-002)
   ============================================================ */
.map-log {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1001;
  color: #00ff41;
  font-size: 11px;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.6);
  pointer-events: none;
  min-height: 0;
  line-height: 1.4;
}
.map-log:empty {
  display: none;
}
