/**
 * World Map Styles - Immersive RPG Portal
 *
 * This stylesheet defines the world map interface.
 * All colors are referenced from theme variables defined in /themes/{theme}/theme.css
 */

/* ==================== HexUI Site Header (matching layout.ejs) ==================== */
.hex-site-header {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 8px 16px;
}

.hex-site-header .hex-component {
  width: 100%;
  max-width: 1400px;
}

.hex-logo {
  font-size: 20px;
  font-weight: bold;
  color: var(--gold, #d4a92a);
  letter-spacing: 2px;
}

.hex-avatar {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  border: 2px solid var(--border-light, #6b5c4a);
}

.hex-username {
  color: var(--text-accent, #e8c547);
}

/* ==================== Stats Bar (floating below header, right side) ==================== */
.hex-stats-bar {
  position: absolute;
  top: var(--header-height, 100px); /* Dynamic: set by JS based on header height */
  right: 24px;
  display: flex;
  gap: 12px;
  z-index: 50;
}

.hex-stat-bar-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hex-stat-label {
  font-size: 9px;
  font-weight: bold;
  letter-spacing: 1px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
  margin-bottom: 2px;
  text-align: center;
}

.hex-stat-label.hp { color: var(--color-health, #cc3333); }
.hex-stat-label.mp { color: var(--color-mana, #4477cc); }
.hex-stat-label.hunger { color: var(--color-hunger, #cc8833); }

/* HexUI Back Button positioning */
.hex-back-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 60;
}

/* HexUI Text Panel */
.hex-text-panel p {
  margin: 0;
  line-height: 1.5;
  color: var(--text-primary, #f0e6d3);
}

/* ==================== HexUI Header Responsive ==================== */

/* Small screens */
@media (max-width: 600px) {
  .hex-text-panel {
    bottom: 8px;
    left: 8px;
    right: 8px;
    transform: none;
  }

  .hex-stats-bar {
    right: 8px;
    gap: 8px;
    padding: 6px 10px;
  }
}

/* Full viewport layout */
html, body.world-map-body {
  height: 100%;
  overflow: hidden;
}

body.world-map-body {
  display: flex;
  flex-direction: column;
}

/* ==================== Compact Header ==================== */
.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background-color: var(--bg-dark);
  background-image: var(--asset-header-bg);
  background-repeat: repeat-x;
  border-bottom: var(--border-width, 4px) solid var(--border-dark);
  flex-shrink: 0;
  height: 48px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.header-left {
  display: flex;
  align-items: center;
}

.realm-title {
  font-size: 16px;
  font-weight: bold;
  color: var(--gold);
  letter-spacing: 2px;
}

.header-nav {
  display: flex;
  gap: 16px;
}

.nav-icon {
  color: var(--text-secondary);
  font-size: 14px;
  padding: 4px 8px;
}

.nav-icon:hover {
  color: var(--text-accent);
  text-decoration: none;
}

.icon-char {
  font-family: 'Courier New', monospace;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mini-avatar {
  width: 24px;
  height: 24px;
  border-radius: var(--border-radius, 4px);
  border: 2px solid var(--border-light);
}

.mini-username {
  color: var(--text-accent);
  font-size: 12px;
}

.mini-gold {
  color: var(--gold);
  font-size: 12px;
}

.login-link {
  color: var(--text-accent);
  font-size: 12px;
}

/* Header Stats (HP/MP/Hunger) */
.header-stats {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.mini-stat {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--bg-medium);
  border: 2px solid var(--border-dark);
  font-size: 12px;
  white-space: nowrap;
  line-height: 1;
}

.mini-stat .stat-icon {
  font-weight: bold;
  opacity: 0.7;
  font-size: 10px;
}

.mini-stat .stat-val {
  font-weight: bold;
  min-width: 40px;
  text-align: right;
}

.hp-stat .stat-val {
  color: var(--color-health);
}

.mp-stat .stat-val {
  color: var(--color-mana);
}

.hunger-stat .stat-val {
  color: var(--color-hunger);
}

/* ==================== Main Map Area ==================== */
.map-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  background: var(--bg-darkest);
  padding: 16px;
  width: 100%;
  min-height: 0;
}

.map-viewport {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 1200px;
  flex: 1;
  min-height: 0;
  gap: 12px;
}

#map-container {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
}

#map-container canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
}

/* Back button - positioned over the map */
.map-back-btn {
  position: absolute;
  top: 50px;
  left: 16px;
  z-index: 10;
  padding: 8px 16px;
  font-size: 14px;
}

/* Location indicator - sits in flow above map */
.location-indicator {
  background: var(--bg-dark);
  border: 2px solid var(--border-light);
  padding: 4px 12px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--gold);
  letter-spacing: 1px;
  flex-shrink: 0;
}

/* ==================== Text Panel ==================== */
#hex-text-panel {
  flex-shrink: 0; /* Don't shrink - map adjusts instead */
  width: auto;
  max-width: calc(100vw - 32px); /* Stay within browser window with padding */
  margin: 0 auto; /* Center horizontally */
  position: relative;
}

#map-text {
  text-align: center;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
}

/* Scroll indicator - shows when text panel has overflow */
.text-scroll-indicator {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--gold, #d4a92a);
  opacity: 0.8;
  pointer-events: none;
  z-index: 10;
  animation: scroll-hint 1.5s ease-in-out infinite;
}

.text-scroll-indicator::before,
.text-scroll-indicator::after {
  content: '';
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid var(--gold, #d4a92a);
}

@keyframes scroll-hint {
  0%, 100% { opacity: 0.6; transform: translateX(-50%) translateY(0); }
  50% { opacity: 1; transform: translateX(-50%) translateY(2px); }
}

/* ==================== Home Modal ==================== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  max-width: 400px;
  text-align: center;
}

.modal-content h3 {
  color: var(--gold);
  margin-bottom: 16px;
}

.modal-content p {
  margin-bottom: 12px;
}

.modal-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 24px;
}

/* ==================== Zone Hover Tooltip ==================== */
.zone-tooltip {
  position: absolute;
  background: var(--bg-dark);
  border: 2px solid var(--gold);
  padding: 12px 16px;
  max-width: 280px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  pointer-events: none;
  z-index: 20;
  box-shadow: var(--shadow-lg, 0 4px 12px rgba(0, 0, 0, 0.5));
}

.zone-tooltip .zone-name {
  color: var(--gold);
  font-weight: bold;
  margin-bottom: 4px;
}

/* ==================== Loading State ==================== */
.map-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-secondary);
  font-size: 16px;
}

.map-loading::after {
  content: '';
  animation: loading-dots 1.5s infinite;
}

@keyframes loading-dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* ==================== Zone Highlight (gold outline) ==================== */
.zone-highlight {
  position: absolute;
  border: 3px solid var(--gold);
  pointer-events: none;
  box-shadow: var(--shadow-glow-gold, 0 0 8px rgba(212, 169, 42, 0.5));
}

/* ==================== Responsive ==================== */

/* Small height screens (1080p and below) */
@media (max-height: 900px) {
  .map-main {
    padding: 8px;
  }

  .location-indicator {
    padding: 3px 10px;
    font-size: 12px;
  }
}

/* Very small height screens */
@media (max-height: 750px) {
  .map-header {
    height: 40px;
    padding: 4px 12px;
  }

  .realm-title {
    font-size: 14px;
  }

  .mini-stat {
    padding: 2px 6px;
    font-size: 11px;
  }
}

/* Narrow screens */
@media (max-width: 768px) {
  .map-header {
    padding: 8px 12px;
  }

  .realm-title {
    font-size: 14px;
  }

  .header-nav {
    gap: 8px;
  }

  .nav-icon {
    padding: 4px;
  }

  .map-back-btn {
    top: 8px;
    left: 8px;
    padding: 6px 12px;
    font-size: 12px;
  }

  .location-indicator {
    font-size: 12px;
    padding: 4px 10px;
  }
}

@media (max-width: 480px) {
  .header-nav {
    display: none;
  }

  .mini-username {
    display: none;
  }
}

/* ==================== Touch Device Styles ==================== */
@media (hover: none) and (pointer: coarse) {
  /* Disable browser native touch gestures - we handle them in JavaScript */
  #map-container canvas {
    touch-action: none;
  }

  /* Larger touch targets for nav */
  .nav-icon {
    padding: 8px 12px;
  }

  /* Hide tooltip on touch (use text panel instead) */
  .zone-tooltip {
    display: none !important;
  }

  /* Make back button easier to tap */
  .map-back-btn {
    padding: 12px 20px;
    font-size: 14px;
  }
}

/* ==================== Mobile Stats Bar ==================== */
/* Hidden on desktop - only shows on mobile via media query below */
.mobile-stats-bar,
#mobile-stats-bar {
  display: none !important;
}

@media (max-width: 768px) {
  .mobile-stats-bar,
  #mobile-stats-bar {
    display: flex !important;
    justify-content: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--bg-dark);
    border-bottom: 2px solid var(--border-dark);
  }

  .mobile-stats-bar .mobile-stat {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .mobile-stats-bar .stat-label {
    font-size: 10px;
    font-weight: bold;
    letter-spacing: 1px;
    min-width: 24px;
  }

  .mobile-stats-bar .stat-label.hp { color: var(--color-health, #cc3333); }
  .mobile-stats-bar .stat-label.mp { color: var(--color-mana, #4477cc); }
  .mobile-stats-bar .stat-label.hgr { color: var(--color-hunger, #cc8833); }
}

/* ==================== Mobile Map Layout ==================== */
@media (max-width: 768px) {
  /* Hide desktop stats bar on mobile */
  .hex-stats-bar {
    display: none !important;
  }

  /* Map fills available space on mobile */
  .map-main {
    padding: 8px;
  }

  .map-viewport {
    width: 100%;
  }

  /* Map container responsive on mobile */
  #map-container {
    width: 100% !important;
    max-width: 100vw;
  }

  /* Location indicator */
  .location-indicator {
    font-size: 11px;
    padding: 4px 8px;
    margin-bottom: 4px;
  }

  /* Text panel on mobile */
  #hex-text-panel {
    max-width: 100%;
  }

  /* Back button positioning */
  .hex-back-btn {
    top: 8px;
    left: 8px;
    z-index: 110;
  }

}

/* ==================== Small Phone Layout ==================== */
@media (max-width: 480px) {
  .location-indicator {
    font-size: 10px;
    padding: 3px 6px;
  }

  /* Smaller stat bars on phone */
  .mobile-stats-bar {
    gap: 8px;
    padding: 6px 8px;
  }
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
  body.world-map-body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }

  .map-header {
    padding-top: max(8px, env(safe-area-inset-top));
  }
}

/* ==================== NPC Dialog Modal ==================== */

.npc-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.npc-modal .modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
}

.npc-modal-content {
  position: relative;
  background-color: var(--bg-dark);
  background-image: var(--asset-panel-bg);
  background-repeat: repeat;
  border: 16px solid transparent;
  border-image: var(--asset-modal-frame) 16 fill;
  border-radius: 0;
  padding: 0;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.npc-modal .modal-close {
  position: absolute;
  top: 10px;
  right: 15px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 28px;
  cursor: pointer;
  z-index: 10;
}

.npc-modal .modal-close:hover {
  color: var(--text-primary);
}

.npc-header {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 20px;
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 2px solid var(--border-dark);
}

.npc-portrait {
  width: 80px;
  height: 80px;
  background: var(--bg-medium);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  border: 3px solid var(--border-light);
}

.npc-info h3 {
  color: var(--text-primary);
  margin: 0 0 5px 0;
  font-size: 20px;
}

.npc-info p {
  color: var(--text-secondary);
  margin: 0;
  font-size: 14px;
  font-style: italic;
}

.npc-dialog {
  padding: 20px;
  border-bottom: 1px solid var(--border-dark);
}

.npc-dialog p {
  color: var(--text-primary);
  line-height: 1.6;
  margin: 0;
  font-size: 15px;
}

.npc-responses {
  padding: 15px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.npc-response-btn {
  background-color: var(--bg-medium);
  background-image: var(--asset-button-bg);
  background-repeat: repeat-x;
  border: 2px solid var(--border-light);
  color: var(--text-primary);
  padding: 12px 16px;
  border-radius: 0;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
  font-family: inherit;
  transition: none;
  image-rendering: pixelated;
}

.npc-response-btn:hover {
  filter: brightness(1.2);
  border-color: var(--gold);
}

/* NPC Portrait Icons */
.npc-portrait[data-portrait="harbormaster"]::after { content: ''; }
.npc-portrait[data-portrait="caravanmaster"]::after { content: ''; }
.npc-portrait[data-portrait="guardcaptain"]::after { content: ''; }
.npc-portrait[data-portrait="zova"]::after { content: ''; }
.npc-portrait[data-portrait="siola"]::after { content: ''; }
.npc-portrait[data-portrait="library"]::after { content: ''; }
.npc-portrait[data-portrait="observatory"]::after { content: ''; }
.npc-portrait[data-portrait="willows"]::after { content: ''; }
.npc-portrait[data-portrait="ancienttree"]::after { content: ''; }
.npc-portrait[data-portrait="garrison"]::after { content: ''; }

/* Quest Toast Notifications */
.quest-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: linear-gradient(135deg, var(--bg-medium), var(--bg-dark));
  border: 2px solid var(--color-success);
  border-radius: var(--border-radius-lg, 8px);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-primary);
  font-size: 14px;
  box-shadow: 0 4px 15px rgba(68, 170, 68, 0.3);
  z-index: 10000;
  opacity: 0;
  transform: translateX(100%);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.quest-toast.show {
  opacity: 1;
  transform: translateX(0);
}

.quest-toast-icon {
  font-size: 18px;
  color: var(--color-success);
}

.quest-toast-text {
  flex: 1;
}

/* ==================== HexUI Modal Scrollbar Styling ==================== */

/* Style scrollbar for HexUI modal content */
.hex-component-content {
  scrollbar-width: thin;
  scrollbar-color: var(--border-light, #5a5a4a) var(--bg-dark, #1a1a1a);
}

.hex-component-content::-webkit-scrollbar {
  width: 8px;
}

.hex-component-content::-webkit-scrollbar-track {
  background: var(--bg-dark, #1a1a1a);
}

.hex-component-content::-webkit-scrollbar-thumb {
  background: var(--border-light, #5a5a4a);
  border-radius: 4px;
}

.hex-component-content::-webkit-scrollbar-thumb:hover {
  background: var(--gold, #d4af37);
}
