*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 30%, #1c1f42 0%, #090b18 75%);
  color: var(--text-main);
  font-family: var(--font-sans);
  user-select: none;
  -webkit-font-smoothing: antialiased;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

/* Main centered responsive 16:9 theater viewport */
#app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-stage {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  background: var(--bg-stage);
  overflow: clip;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.85);
}

/* Background Layers */
.stage-bg-layer {
  position: absolute;
  inset: 0;
  z-index: var(--z-bg);
}

.bg-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.75s ease;
  transform: scale(1.015);
}

.bg-img.active {
  opacity: 1;
}

.bg-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 52%, rgba(6, 8, 20, 0.56) 100%),
    linear-gradient(to top, rgba(6, 8, 20, 0.55) 0%, transparent 32%);
  z-index: 2;
}

#particle-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: var(--z-particles-front);
}

/* CG Fullscreen Layer */
#cg-layer {
  position: absolute;
  inset: 0;
  z-index: var(--z-cg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.7s ease;
  background: #070914;
}

#cg-layer.active {
  opacity: 1;
}

#cg-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  animation: cgDrift 18s ease-in-out infinite alternate;
}

@keyframes cgDrift {
  0% { transform: scale(1.0); }
  100% { transform: scale(1.045); }
}

/* Sprite Stage */
#sprite-layer {
  position: absolute;
  inset: 0;
  z-index: var(--z-sprites);
  pointer-events: none;
}

.sprite-slot {
  position: absolute;
  bottom: -10px;
  height: 92%;
  aspect-ratio: 8 / 11;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: left 0.45s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s ease, transform 0.35s ease, filter 0.35s ease;
  opacity: 0;
}

.sprite-slot.pos-center {
  left: 50%;
  transform: translateX(-50%) scale(1);
}

.sprite-slot.pos-left {
  left: 24%;
  transform: translateX(-50%) scale(0.97);
}

.sprite-slot.pos-right {
  left: 76%;
  transform: translateX(-50%) scale(0.97);
}

.sprite-slot.visible {
  opacity: 1;
}

.sprite-slot.speaking {
  z-index: 14;
  filter: drop-shadow(0 10px 28px rgba(0, 0, 0, 0.55)) brightness(1.03);
}

.sprite-slot.speaking.pos-center {
  transform: translateX(-50%) scale(1.03);
}

.sprite-slot.speaking.pos-left,
.sprite-slot.speaking.pos-right {
  transform: translateX(-50%) scale(1.01);
}

.sprite-slot.dimmed {
  z-index: 11;
  filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.4)) brightness(0.74) saturate(0.88);
}

.sprite-img-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: spriteBreath 4.2s ease-in-out infinite;
}

.sprite-img-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

@keyframes spriteBreath {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-4px); }
}

/* Fallback CSS mood visual enhancements */
.sprite-slot.mood-happy .sprite-img-wrap {
  animation: moodHappyBounce 1.8s ease-in-out infinite;
}

.sprite-slot.mood-happy .sprite-img-wrap::after {
  content: "✦";
  position: absolute;
  top: 12%;
  right: 22%;
  font-size: clamp(18px, 2vw, 28px);
  color: #ffe38f;
  text-shadow: 0 0 12px rgba(255, 215, 110, 0.9);
  animation: sparkleFloat 1.5s ease-in-out infinite alternate;
}

.sprite-slot.mood-blush .sprite-img-wrap {
  animation: moodBlushSway 3.0s ease-in-out infinite;
}

.sprite-slot.mood-blush .sprite-img-wrap::after {
  content: "♡";
  position: absolute;
  top: 13%;
  right: 21%;
  font-size: clamp(18px, 2vw, 26px);
  color: #ff9ab4;
  text-shadow: 0 0 14px rgba(255, 124, 152, 0.9);
  animation: sparkleFloat 1.4s ease-in-out infinite alternate;
}

@keyframes moodHappyBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes moodBlushSway {
  0%, 100% { transform: rotate(0deg) translateY(0); }
  50% { transform: rotate(-1.2deg) translateY(-3px); }
}

@keyframes sparkleFloat {
  0% { transform: translateY(0) scale(0.95); opacity: 0.75; }
  100% { transform: translateY(-7px) scale(1.15); opacity: 1; }
}

/* Title Screen */
#title-screen {
  position: absolute;
  inset: 0;
  z-index: var(--z-ui);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4.5% 5.5%;
  background: linear-gradient(
    90deg,
    rgba(9, 11, 24, 0.82) 0%,
    rgba(9, 11, 24, 0.42) 48%,
    rgba(9, 11, 24, 0.16) 100%
  );
}

.title-badge-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(244, 178, 102, 0.16);
  border: 1px solid rgba(244, 178, 102, 0.42);
  color: #ffd8a3;
  font-size: clamp(11px, 1.05vw, 14px);
  letter-spacing: 0.08em;
}

.title-hero {
  max-width: 52%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.title-en {
  font-size: clamp(11px, 1.1vw, 15px);
  letter-spacing: 0.34em;
  color: var(--accent-amber);
  text-transform: uppercase;
}

.title-main {
  font-family: var(--font-serif);
  font-size: clamp(34px, 4.6vw, 66px);
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1.14;
  background: linear-gradient(135deg, #fffdf9 0%, #ffe0b5 56%, #ff9eb4 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.7));
}

.title-sub {
  font-size: clamp(13px, 1.3vw, 18px);
  color: #e4dff0;
  line-height: 1.7;
  max-width: 92%;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

.title-actions {
  display: flex;
  flex-direction: column;
  gap: 11px;
  margin-top: 10px;
  width: clamp(230px, 24vw, 310px);
}

.btn-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-radius: 14px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border-soft);
  backdrop-filter: blur(14px);
  font-size: clamp(14px, 1.3vw, 18px);
  font-weight: 600;
  letter-spacing: 0.08em;
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.btn-title:hover {
  transform: translateX(6px);
  border-color: var(--accent-amber);
  background: rgba(244, 178, 102, 0.18);
  box-shadow: var(--shadow-glow);
}

.btn-title.primary {
  background: linear-gradient(135deg, rgba(244, 178, 102, 0.88), rgba(255, 124, 152, 0.85));
  color: #150e1c;
  border-color: rgba(255, 242, 224, 0.65);
}

.btn-title.primary:hover {
  background: linear-gradient(135deg, #ffd191, #ff99b0);
}

.title-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: clamp(11px, 0.95vw, 13px);
  color: var(--text-dim);
}

/* VN Stage UI */
#vn-screen {
  position: absolute;
  inset: 0;
  z-index: var(--z-ui);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 2.2% 4.2% 2.6%;
  pointer-events: none;
}

#vn-screen.ui-hidden {
  pointer-events: auto;
}

#vn-screen.ui-hidden #vn-dialogue-wrap,
#vn-screen.ui-hidden #vn-top-bar {
  opacity: 0;
  pointer-events: none;
}

#vn-top-bar {
  position: absolute;
  top: 2.4%;
  left: 3.2%;
  right: 3.2%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: auto;
  transition: opacity 0.25s ease;
}

.vn-location-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 15px;
  border-radius: 999px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  font-size: clamp(12px, 1.05vw, 14px);
  color: #ffe3be;
}

.vn-quick-tools {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.btn-tool {
  position: relative;
  padding: 6px 12px;
  border-radius: 10px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border-soft);
  backdrop-filter: blur(12px);
  font-size: clamp(11px, 0.98vw, 13px);
  color: var(--text-main);
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.15s ease;
}

.btn-tool:hover {
  background: rgba(244, 178, 102, 0.22);
  border-color: var(--accent-amber);
  transform: translateY(-1px);
}

.btn-tool.active {
  background: rgba(244, 178, 102, 0.34);
  border-color: var(--accent-amber);
  color: #fff5e2;
}

.unread-dot {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent-rose);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 10px rgba(255, 124, 152, 0.85);
}

/* Dialogue Box */
#vn-dialogue-wrap {
  position: relative;
  width: 100%;
  pointer-events: auto;
  transition: opacity 0.25s ease;
}

#vn-speaker-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 22px;
  margin-bottom: -2px;
  padding: 7px 22px;
  border-radius: 14px 14px 0 0;
  background: linear-gradient(135deg, rgba(28, 33, 68, 0.95), rgba(19, 23, 49, 0.95));
  border: 1px solid var(--glass-border);
  border-bottom: none;
  font-size: clamp(14px, 1.35vw, 19px);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #ffd79f;
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.35);
}

#vn-dialogue-box {
  position: relative;
  min-height: clamp(120px, 19vh, 172px);
  padding: 20px 30px 24px;
  border-radius: var(--radius-lg);
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
}

#vn-dialogue-text {
  font-size: clamp(15px, 1.42vw, 21px);
  line-height: 1.75;
  letter-spacing: 0.03em;
  color: var(--text-main);
  padding-right: 24px;
}

#vn-next-arrow {
  position: absolute;
  right: 22px;
  bottom: 16px;
  color: var(--accent-amber);
  font-size: clamp(14px, 1.3vw, 18px);
  animation: bounceNext 1.1s ease-in-out infinite;
}

@keyframes bounceNext {
  0%, 100% { transform: translateY(0); opacity: 0.7; }
  50% { transform: translateY(4px); opacity: 1; }
}

/* Choices Overlay */
#vn-choices {
  position: absolute;
  inset: 0;
  z-index: var(--z-choices);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding-bottom: 14%;
  background: rgba(8, 10, 22, 0.38);
  backdrop-filter: blur(3px);
}

.choice-btn {
  width: min(680px, 84%);
  padding: 15px 24px;
  border-radius: 16px;
  background: rgba(18, 22, 46, 0.92);
  border: 1px solid rgba(244, 178, 102, 0.42);
  backdrop-filter: blur(16px);
  font-size: clamp(14px, 1.32vw, 18px);
  font-weight: 500;
  text-align: center;
  color: #fff7eb;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.choice-btn:hover {
  transform: translateY(-2px) scale(1.015);
  background: linear-gradient(135deg, rgba(244, 178, 102, 0.3), rgba(255, 124, 152, 0.28));
  border-color: #ffd59e;
  box-shadow: 0 12px 34px rgba(244, 178, 102, 0.25);
}

/* Toast Notification */
#toast-stack {
  position: absolute;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast-item {
  padding: 9px 20px;
  border-radius: 999px;
  background: rgba(20, 24, 52, 0.94);
  border: 1px solid var(--accent-amber);
  color: #ffe3b8;
  font-size: clamp(12px, 1.1vw, 15px);
  font-weight: 600;
  box-shadow: var(--shadow-soft);
  animation: toastInOut 2.5s ease forwards;
}

.toast-item.heart {
  border-color: var(--accent-rose);
  color: #ffd2de;
}

@keyframes toastInOut {
  0% { opacity: 0; transform: translateY(-10px) scale(0.95); }
  12% { opacity: 1; transform: translateY(0) scale(1); }
  82% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-8px) scale(0.97); }
}

/* Flash FX */
#screen-fx {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 95;
  opacity: 0;
}

#screen-fx.flash {
  display: block;
  background: #fff7ee;
  animation: fxFlash 0.45s ease;
}

@keyframes fxFlash {
  0% { opacity: 0.72; }
  100% { opacity: 0; }
}

/* Autoplay Live Showcase Banner, Focus Ring & Audio-Unlock Gate */
#autoplay-banner {
  position: absolute;
  left: 22px;
  bottom: 18px;
  z-index: 88;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(14, 18, 40, 0.92);
  border: 1px solid rgba(244, 178, 102, 0.65);
  backdrop-filter: blur(14px);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.6);
  font-size: 13px;
  color: #ffe3b5;
}

.btn-autoplay-pause {
  padding: 4px 11px;
  border-radius: 999px;
  background: linear-gradient(135deg, #f4b266, #ff859e);
  color: #170e1d;
  font-weight: 700;
  font-size: 12px;
}

.autoplay-focus {
  outline: 3px solid #ffd58a !important;
  box-shadow: 0 0 0 6px rgba(244, 178, 102, 0.35), 0 0 28px rgba(255, 200, 110, 0.85) !important;
  transform: scale(1.03) !important;
}

#autoplay-gate {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 9, 20, 0.72);
  backdrop-filter: blur(10px);
  cursor: pointer;
}

.autoplay-gate-card {
  width: min(540px, 86%);
  padding: 28px 32px;
  border-radius: 22px;
  background: var(--glass-bg-strong);
  border: 1px solid rgba(244, 178, 102, 0.55);
  box-shadow: 0 24px 68px rgba(0, 0, 0, 0.82), var(--shadow-glow);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.autoplay-gate-title {
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 700;
  color: #ffe3b8;
}

.autoplay-gate-sub {
  font-size: 14px;
  line-height: 1.65;
  color: #dbd7ea;
}

.autoplay-gate-btn {
  padding: 12px 26px;
  font-size: 15px;
}

/* Audiobook Voice Indicator & Replay Control */
.vn-speaker-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding-left: 22px;
  margin-bottom: -2px;
}

.vn-speaker-row #vn-speaker-badge {
  margin-left: 0;
  margin-bottom: 0;
}

#vn-voice-indicator:not(.hidden) {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(244, 178, 102, 0.2);
  border: 1px solid rgba(244, 178, 102, 0.55);
  color: #ffe3b5;
  font-size: 12px;
  animation: voicePulse 1.4s ease-in-out infinite;
}

@keyframes voicePulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(244, 178, 102, 0.35);
    opacity: 0.9;
  }
  50% {
    box-shadow: 0 0 12px rgba(244, 178, 102, 0.65);
    opacity: 1;
  }
}

.btn-voice-replay:not(.hidden) {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(25, 30, 62, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #f4efe6;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.15s ease;
}

.btn-voice-replay:hover {
  background: rgba(244, 178, 102, 0.28);
  border-color: var(--accent-amber);
  transform: translateY(-1px);
}


/* Mobile Portrait Hint Pill */
.mobile-rotate-hint {
  display: none;
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 96;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(14, 18, 40, 0.88);
  border: 1px solid rgba(244, 178, 102, 0.55);
  color: #ffe3b5;
  font-size: 11px;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

.mobile-rotate-hint.dismissed {
  display: none !important;
}

@media (max-width: 760px) and (orientation: portrait) {
  .mobile-rotate-hint:not(.dismissed) {
    display: inline-flex;
    align-items: center;
    gap: 4px;
  }
}
