/* ============================================
   The Little Prince 2D World — Styles
   ============================================
   Dreamy watercolor aesthetic with storybook UI.
   Layers: PixiJS canvas → SVG entity overlay → HTML UI
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a1e;
  font-family: 'Georgia', 'Times New Roman', serif;
  color: #f4e4bc;
  -webkit-user-select: none;
  user-select: none;
}

/* --- Game Container --- */
#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#game-container canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* --- Sky Background (behind canvas) --- */
#sky-bg {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: -1;
  transition: background 2s ease;
}

.sky-night {
  background: linear-gradient(180deg, #0a0a1e 0%, #1a1a3e 40%, #2a2a5e 100%);
}

.sky-dawn {
  background: linear-gradient(180deg, #1a1a3e 0%, #4a3a6e 30%, #e8a0bf 70%, #f4e4bc 100%);
}

.sky-day {
  background: linear-gradient(180deg, #87ceeb 0%, #b0e0e6 40%, #f4e4bc 100%);
}

.sky-dusk {
  background: linear-gradient(180deg, #2a1a4e 0%, #8b4a6e 30%, #e8a06e 70%, #f4e4bc 100%);
}

/* --- Vignette Overlay --- */
#vignette {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 5;
  background: radial-gradient(
    ellipse at center,
    transparent 50%,
    rgba(10, 10, 30, 0.4) 100%
  );
}

/* --- Loading Screen --- */
#loading-screen {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 20000;
  background: #0a0a1e;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.8s ease;
}

#loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-title {
  font-size: 2rem;
  color: #ffd700;
  margin-bottom: 1rem;
  letter-spacing: 0.1em;
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

.loading-subtitle {
  font-size: 1rem;
  color: #f4e4bc;
  opacity: 0.7;
  margin-bottom: 2rem;
  font-style: italic;
}

.loading-bar-container {
  width: 300px;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.loading-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #ffd700, #e8a0bf);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.loading-text {
  font-size: 0.8rem;
  color: #f4e4bc;
  opacity: 0.5;
  margin-top: 0.8rem;
}

/* --- Entity Layer (SVG overlay) --- */
#entity-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 10;
}

.entity-wrapper {
  position: absolute;
  pointer-events: none;
  will-change: transform;
}

.entity-wrapper svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* --- Dialogue Box --- */
#dialogue-box {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  width: min(80vw, 600px);
  min-height: 100px;
  z-index: 1000;
  background: linear-gradient(135deg, #faf3e0 0%, #f4e4bc 100%);
  border: 3px solid #c4a882;
  border-radius: 12px;
  padding: 16px 20px;
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: auto;
  cursor: pointer;
}

#dialogue-box.visible {
  transform: translateX(-50%) translateY(0);
}

/* Decorative corners */
#dialogue-box::before,
#dialogue-box::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid #c4a882;
  opacity: 0.5;
}

#dialogue-box::before {
  top: 4px; left: 4px;
  border-right: none; border-bottom: none;
  border-radius: 4px 0 0 0;
}

#dialogue-box::after {
  bottom: 4px; right: 4px;
  border-left: none; border-top: none;
  border-radius: 0 0 4px 0;
}

.dialogue-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.dialogue-portrait {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid #c4a882;
  background: #e8d8c0;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dialogue-portrait[data-speaker="narrator"] {
  display: none;
}

.dialogue-portrait svg {
  width: 100%;
  height: 100%;
}

.dialogue-speaker {
  font-size: 0.85rem;
  font-weight: bold;
  color: #6b4226;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.dialogue-speaker[data-speaker="narrator"] {
  color: #8b7355;
  font-style: italic;
  text-transform: none;
}

.dialogue-text {
  font-size: 1rem;
  line-height: 1.5;
  color: #3a2a1a;
  min-height: 2em;
}

.dialogue-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.dialogue-choice {
  background: rgba(200, 168, 130, 0.2);
  border: 2px solid #c4a882;
  border-radius: 8px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 0.95rem;
  color: #3a2a1a;
  cursor: pointer;
  text-align: left;
  transition: background 0.2s, transform 0.1s;
}

.dialogue-choice:hover {
  background: rgba(200, 168, 130, 0.4);
  transform: translateX(4px);
}

.dialogue-choice:active {
  transform: translateX(2px) scale(0.98);
}

.dialogue-advance {
  text-align: right;
  font-size: 0.75rem;
  color: #8b7355;
  margin-top: 8px;
  opacity: 0.6;
}

.dialogue-advance::after {
  content: ' ▼';
  animation: bounce-arrow 1s ease-in-out infinite;
}

@keyframes bounce-arrow {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}

@keyframes sparkle-pulse {
  0% { opacity: 0.4; transform: translateX(-50%) scale(0.8); }
  100% { opacity: 1; transform: translateX(-50%) scale(1.2); }
}

/* --- HUD --- */
#hud {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 100;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.hud-button {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 2px solid rgba(255, 215, 0, 0.4);
  background: rgba(10, 10, 30, 0.5);
  backdrop-filter: blur(4px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
  color: #ffd700;
  font-size: 1.2rem;
}

.hud-button:hover {
  background: rgba(255, 215, 0, 0.15);
  border-color: rgba(255, 215, 0, 0.7);
}

.hud-location {
  background: rgba(10, 10, 30, 0.5);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 215, 0, 0.2);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.8rem;
  color: #f4e4bc;
  letter-spacing: 0.05em;
}

/* --- Codex Panel --- */
#codex-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  width: min(90vw, 500px);
  max-height: 70vh;
  z-index: 1500;
  background: linear-gradient(135deg, #faf3e0 0%, #e8d8c0 100%);
  border: 3px solid #8b7355;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  overflow-y: auto;
}

#codex-panel.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.codex-title {
  font-size: 1.3rem;
  color: #6b4226;
  text-align: center;
  margin-bottom: 16px;
  letter-spacing: 0.1em;
  border-bottom: 2px solid #c4a882;
  padding-bottom: 12px;
}

.codex-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.codex-entry {
  background: rgba(255, 255, 255, 0.3);
  border: 1px solid #c4a882;
  border-radius: 8px;
  padding: 12px;
}

.codex-rule-area {
  font-size: 0.85rem;
  color: #8b7355;
  margin-bottom: 4px;
}

.codex-rule-text {
  font-size: 0.95rem;
  color: #3a2a1a;
  font-style: italic;
  line-height: 1.4;
}

.codex-enforcement {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 4px;
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.codex-enforcement-visual { background: #7ec8e3; color: #1a3a4e; }
.codex-enforcement-soft { background: #ffd700; color: #4a3a1e; }
.codex-enforcement-hard { background: #e8a0bf; color: #4a1a2e; }

.codex-empty {
  color: #8b7355;
  font-style: italic;
  text-align: center;
  padding: 20px;
}

/* --- Codex Notification --- */
#codex-notification {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  z-index: 1200;
  background: rgba(10, 10, 30, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 215, 0, 0.4);
  border-radius: 10px;
  padding: 10px 20px;
  max-width: min(80vw, 400px);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#codex-notification.visible {
  transform: translateX(-50%) translateY(0);
}

.notification-icon {
  display: inline;
  font-size: 1rem;
  margin-right: 6px;
}

.notification-text {
  font-size: 0.85rem;
  color: #ffd700;
  font-style: italic;
}

/* --- Mobile D-Pad --- */
#dpad {
  position: fixed;
  bottom: 20px;
  left: 20px;
  width: 96px;
  height: 96px;
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

@media (hover: none) and (pointer: coarse) {
  #dpad {
    opacity: 0.6;
    pointer-events: auto;
  }
}

#dpad svg {
  width: 100%;
  height: 100%;
}

/* --- Interact Button (mobile) --- */
#interact-btn {
  position: fixed;
  bottom: 40px;
  right: 30px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(255, 215, 0, 0.5);
  background: rgba(10, 10, 30, 0.5);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: #ffd700;
  cursor: pointer;
}

@media (hover: none) and (pointer: coarse) {
  #interact-btn {
    display: flex;
  }
}

/* --- Controls Help --- */
#controls-help {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 100;
  font-size: 0.7rem;
  color: rgba(244, 228, 188, 0.4);
  text-align: right;
  line-height: 1.6;
  pointer-events: none;
}

@media (hover: none) and (pointer: coarse) {
  #controls-help {
    display: none;
  }
}

/* --- Transition Overlay --- */
#transition-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 10000;
  pointer-events: none;
}

/* --- Responsive --- */
@media (max-width: 480px) {
  #dialogue-box {
    width: 95vw;
    bottom: 10px;
    padding: 12px 14px;
  }

  .loading-title { font-size: 1.5rem; }
  .loading-bar-container { width: 200px; }
}
