/* ===========================
   Reset & Base
   =========================== */

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

:root {
  --color-bg: #fffdf8;
  --color-scene-bg: #f0ece4;
  --color-panel-bg: #faf7f2;
  --color-panel-border: #e2d8cc;
  --color-text-primary: #3a3028;
  --color-text-speaker: #7a5c44;
  --color-text-muted: #9a8878;
  --color-accent: #c8956a;
  --color-accent-light: #f0dcc8;
  --color-white: #ffffff;

  --font-main: 'Noto Serif TC', 'Georgia', serif;
  --font-mono: 'Courier New', monospace;

  --scene-height: 65vh;
  --dialogue-height: 35vh;
}

html, body {
  height: 100%;
  overflow: hidden;
  background-color: var(--color-bg);
  font-family: var(--font-main);
  color: var(--color-text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ===========================
   Boot Screen
   =========================== */

.boot-screen {
  position: fixed;
  inset: 0;
  background-color: #0a0a0f;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.8s ease;
}

.boot-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.boot-lines {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: #a8c8b0;
  line-height: 2;
  text-align: center;
  max-width: 320px;
  padding: 2rem;
}

.boot-line {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.boot-line.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===========================
   App Shell
   =========================== */

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background-color: var(--color-bg);
}

.app.hidden {
  display: none;
}

/* ===========================
   Scene Area
   =========================== */

.scene {
  position: relative;
  width: 100%;
  height: var(--scene-height);
  overflow: hidden;
  background-color: var(--color-scene-bg);
  flex-shrink: 0;
}

.room-bg {
  position: absolute;
  inset: 0;
  background-color: var(--color-scene-bg);
  background-image: url('../assets/textures/room-bg.png');
  background-size: cover;
  background-position: center bottom;
  background-repeat: no-repeat;
}

/* ===========================
   Objects Layer
   =========================== */

.objects-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.room-object {
  position: absolute;
  transform: translate(-50%, -50%);
  cursor: pointer;
  pointer-events: all;
  transition: filter 0.15s ease, transform 0.15s ease;
  image-rendering: pixelated;
}

.room-object:hover,
.room-object:focus {
  filter: brightness(1.1) drop-shadow(0 0 6px rgba(200, 149, 106, 0.5));
  transform: translate(-50%, -50%) scale(1.05);
  outline: none;
}

.room-object:active {
  transform: translate(-50%, -50%) scale(0.97);
}

.room-object img {
  display: block;
  width: 56px;
  height: 56px;
  object-fit: contain;
  image-rendering: pixelated;
  transition: transform 0.2s ease, filter 0.2s ease;
}

.room-object:hover img,
.room-object:focus img {
  transform: translateY(-4px) scale(1.08);
  filter: brightness(1.12) drop-shadow(0 4px 8px rgba(200, 149, 106, 0.45));
}

.room-object:active img {
  transform: scale(0.94);
  filter: brightness(0.95);
}

/* Placeholder object when image is missing */
.room-object .object-placeholder {
  width: 40px;
  height: 40px;
  background-color: var(--color-accent-light);
  border: 2px solid var(--color-accent);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  color: var(--color-text-speaker);
  text-align: center;
  padding: 2px;
  line-height: 1.2;
}

/* ===========================
   Characters Layer
   =========================== */

.characters-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.character {
  position: absolute;
  transform: translate(-50%, -100%);
  pointer-events: all;
  cursor: pointer;
  transition: left 0.9s cubic-bezier(0.4, 0, 0.2, 1),
              top 0.9s cubic-bezier(0.4, 0, 0.2, 1);
  image-rendering: pixelated;
}

.character img {
  display: block;
  width: 64px;
  height: 96px;
  object-fit: contain;
  image-rendering: pixelated;
  animation: char-float 3.6s ease-in-out infinite;
}

@keyframes char-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.character:active img {
  animation: char-bounce 0.3s ease;
}

@keyframes char-bounce {
  0%   { transform: scale(1); }
  40%  { transform: scale(0.92); }
  100% { transform: scale(1); }
}

/* Placeholder character when image is missing */
.character .char-placeholder {
  width: 48px;
  height: 80px;
  background-color: var(--color-accent-light);
  border: 2px solid var(--color-accent);
  border-radius: 6px 6px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  color: var(--color-text-speaker);
  text-align: center;
}

.character:hover .char-placeholder,
.character:focus .char-placeholder {
  filter: brightness(1.08);
  outline: none;
}

/* ===========================
   Dialogue Panel
   =========================== */

.dialogue-panel {
  position: relative;
  width: 100%;
  height: var(--dialogue-height);
  background-color: var(--color-panel-bg);
  border-top: 2px solid var(--color-panel-border);
  flex-shrink: 0;
  display: flex;
  align-items: stretch;
}

.dialogue-inner {
  position: relative;
  width: 100%;
  padding: 1rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  overflow: hidden;
}

.dialogue-speaker {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-text-speaker);
  letter-spacing: 0.05em;
  min-height: 1.2em;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.dialogue-speaker.visible {
  opacity: 1;
}

.dialogue-text {
  font-size: 0.95rem;
  line-height: 1.75;
  color: var(--color-text-primary);
  flex: 1;
  overflow-y: auto;
  scrollbar-width: none;
}

.dialogue-text::-webkit-scrollbar {
  display: none;
}

.dialogue-text .char {
  opacity: 0;
  transition: opacity 0.04s ease;
}

.dialogue-text .char.shown {
  opacity: 1;
}

.dialogue-prompt {
  position: absolute;
  bottom: 0.75rem;
  right: 1.25rem;
  font-size: 0.65rem;
  color: var(--color-text-muted);
  animation: prompt-pulse 1.4s ease-in-out infinite;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.dialogue-prompt.visible {
  opacity: 1;
}

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

/* Empty state */
.dialogue-panel.empty .dialogue-inner {
  opacity: 0.4;
}

/* ===========================
   Modal
   =========================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(30, 24, 18, 0.72);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
  display: none;
}

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

.modal-container {
  position: relative;
  background-color: var(--color-white);
  border-radius: 12px;
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  overflow-y: auto;
  scrollbar-width: none;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.28);
  transform: translateY(12px);
  transition: transform 0.3s ease;
}

.modal-overlay.visible .modal-container {
  transform: translateY(0);
}

.modal-container::-webkit-scrollbar {
  display: none;
}

.modal-close {
  position: sticky;
  top: 0.75rem;
  left: 100%;
  float: right;
  margin: 0.75rem 0.75rem 0 0;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background-color: var(--color-accent-light);
  color: var(--color-text-speaker);
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease;
  z-index: 10;
}

.modal-close:hover {
  background-color: var(--color-accent);
  color: var(--color-white);
}

.modal-content {
  padding: 1.25rem 1.5rem 2rem;
  clear: both;
}

/* Memory Modal */
.modal-memory .memory-image {
  width: 100%;
  border-radius: 8px;
  margin-bottom: 1rem;
  object-fit: cover;
  background-color: var(--color-accent-light);
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.modal-memory .memory-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-text-speaker);
  margin-bottom: 0.5rem;
}

.modal-memory .memory-quote {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  font-style: italic;
  border-left: 3px solid var(--color-accent-light);
  padding-left: 0.75rem;
  margin-bottom: 1rem;
  line-height: 1.6;
}

.modal-memory .memory-summary {
  font-size: 0.9rem;
  line-height: 1.8;
  color: var(--color-text-primary);
}

/* Gallery Modal */
.modal-gallery .gallery-image-wrap {
  width: 100%;
  aspect-ratio: 4/3;
  background-color: var(--color-accent-light);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-gallery .gallery-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-gallery .gallery-caption {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-align: center;
  margin-bottom: 1rem;
}

.modal-gallery .gallery-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.modal-nav-btn {
  background: none;
  border: 1.5px solid var(--color-panel-border);
  color: var(--color-text-muted);
  border-radius: 6px;
  padding: 0.3rem 0.8rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.modal-nav-btn:hover:not(:disabled) {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.modal-nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.gallery-page-indicator {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* Comfort Modal */
.modal-comfort .comfort-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text-speaker);
  text-align: center;
  margin-bottom: 1rem;
}

.modal-comfort .comfort-text {
  font-size: 0.9rem;
  line-height: 1.9;
  color: var(--color-text-primary);
  text-align: center;
}

/* ===========================
   Utilities
   =========================== */

.hidden {
  display: none !important;
}

/* Desktop centering */
@media (min-width: 540px) {
  .app {
    max-width: 420px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 1px solid var(--color-panel-border);
    border-right: 1px solid var(--color-panel-border);
  }

  body {
    background-color: #e8e4dc;
  }
}
