:root {
  --bg-deep: #040814;
  --accent-cyan: #7ee3ff;
  --accent-indigo: #7c8cff;
  --accent-gold: #ffd89b;
  --glass-bg: rgba(8, 16, 36, 0.56);
  --glass-border: rgba(145, 195, 255, 0.22);
  --text-main: #eef5ff;
  --text-dim: rgba(215, 232, 255, 0.72);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  user-select: none;
}

#canvas-container {
  position: fixed;
  inset: 0;
  z-index: 1;
}

#canvas-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Hypnotic Heavy Eyelids & Warm Vignette Overlay */
#eyelid-overlay {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  --vignette-strength: 0.25;
  --eyelid-close: 0;
}

#vignette-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    rgba(6, 12, 32, 0) 38%,
    rgba(5, 10, 28, calc(var(--vignette-strength) * 0.78)) 78%,
    rgba(2, 5, 16, calc(var(--vignette-strength) * 0.96)) 100%
  );
  transition: opacity 0.6s ease;
}

#eyelid-top, #eyelid-bottom {
  position: absolute;
  left: 0;
  right: 0;
  height: calc(var(--eyelid-close) * 28vh);
  pointer-events: none;
  transition: height 0.5s ease-out;
}

#eyelid-top {
  top: 0;
  background: linear-gradient(to bottom, rgba(2, 4, 14, 0.96) 0%, rgba(4, 8, 24, 0.65) 55%, rgba(4, 8, 24, 0) 100%);
}

#eyelid-bottom {
  bottom: 0;
  background: linear-gradient(to top, rgba(2, 4, 14, 0.96) 0%, rgba(4, 8, 24, 0.65) 55%, rgba(4, 8, 24, 0) 100%);
}

/* Title Screen */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.1s ease;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
}

.title-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 30%, rgba(54, 115, 196, 0.32), transparent 60%),
    url("assets/sanctuary_title_bg.webp") center/cover no-repeat,
    linear-gradient(180deg, #060d24 0%, #091a3d 55%, #030714 100%);
  transform: scale(1.03);
  filter: saturate(1.08);
}

.title-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    rgba(4, 9, 24, 0.78) 0%,
    rgba(6, 14, 34, 0.56) 50%,
    rgba(3, 8, 22, 0.84) 100%
  );
  backdrop-filter: blur(2px);
}

.title-content {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 2.5rem;
  max-width: 960px;
  width: min(92vw, 960px);
  padding: 2.2rem 2.6rem;
  border-radius: 28px;
  background: rgba(7, 15, 36, 0.58);
  border: 1px solid rgba(150, 210, 255, 0.24);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(18px);
}

.title-portrait-wrap {
  flex: 0 0 260px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  position: relative;
}

.title-portrait-wrap::before {
  content: "";
  position: absolute;
  inset: 12% 8%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(110, 195, 255, 0.35), transparent 72%);
  filter: blur(18px);
  z-index: 0;
}

#title-portrait {
  position: relative;
  z-index: 1;
  width: 260px;
  max-height: 360px;
  object-fit: contain;
  filter: drop-shadow(0 12px 28px rgba(70, 150, 255, 0.35));
  animation: gentleFloat 6.5s ease-in-out infinite;
}

@keyframes gentleFloat {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
}

.title-text-col {
  flex: 1;
  min-width: 0;
}

.eyebrow {
  font-size: 0.78rem;
  letter-spacing: 0.24em;
  color: var(--accent-cyan);
  margin-bottom: 0.6rem;
  opacity: 0.9;
}

.main-title {
  font-size: clamp(2rem, 4.4vw, 3.1rem);
  font-weight: 500;
  letter-spacing: 0.12em;
  line-height: 1.2;
  background: linear-gradient(120deg, #ffffff 10%, #bce7ff 60%, #a5b4ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sub-title {
  font-size: 0.98rem;
  letter-spacing: 0.22em;
  color: var(--text-dim);
  margin-top: 0.35rem;
  margin-bottom: 1.25rem;
}

.lead-copy {
  font-size: 0.95rem;
  line-height: 1.85;
  color: rgba(232, 242, 255, 0.88);
  margin-bottom: 1.7rem;
}

.title-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-bottom: 1.2rem;
}

.btn-primary, .btn-secondary, .btn-ghost {
  cursor: pointer;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 0.85rem 1.8rem;
  transition: transform 0.2s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.btn-primary {
  border: none;
  color: #041024;
  background: linear-gradient(135deg, #9cecff 0%, #8fb2ff 100%);
  box-shadow: 0 8px 28px rgba(110, 200, 255, 0.42);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 34px rgba(126, 227, 255, 0.6);
}

.btn-secondary {
  border: 1px solid rgba(156, 236, 255, 0.5);
  color: #e4f6ff;
  background: rgba(20, 48, 92, 0.55);
}

.btn-secondary:hover {
  background: rgba(34, 74, 134, 0.72);
}

.btn-ghost {
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  padding: 0.85rem 1.35rem;
}

.btn-ghost:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.hint-note {
  font-size: 0.78rem;
  color: rgba(196, 218, 250, 0.65);
  line-height: 1.5;
}

/* Experience HUD */
.hud {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1.1rem 1.4rem;
  pointer-events: none;
  transition: opacity 0.6s ease;
}

.hud.hidden {
  opacity: 0;
  pointer-events: none;
}

.hud.idle .hud-top,
.hud.idle .hud-bottom {
  opacity: 0.14;
}

.hud-top, .hud-bottom {
  transition: opacity 0.9s ease;
  pointer-events: auto;
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.chapter-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.chapter-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan);
}

.hud-top-right {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.depth-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.42rem 0.85rem;
  border-radius: 999px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  font-size: 0.78rem;
}

.depth-label {
  color: var(--text-dim);
}

.depth-bar-track {
  width: 66px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.depth-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #6ecbff, #a395ff);
  transition: width 0.35s ease;
}

.icon-btn {
  cursor: pointer;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-main);
  font-size: 0.78rem;
  backdrop-filter: blur(12px);
  transition: background 0.2s ease;
}

.icon-btn:hover {
  background: rgba(40, 75, 130, 0.68);
}

/* Breath Cue */
.breath-cue {
  align-self: center;
  margin-top: auto;
  margin-bottom: 0.6rem;
  padding: 0.3rem 0.9rem;
  border-radius: 999px;
  background: rgba(8, 18, 42, 0.35);
  border: 1px solid rgba(135, 210, 255, 0.18);
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  color: rgba(195, 232, 255, 0.82);
  opacity: 0.85;
  transition: opacity 0.6s ease, transform 0.6s ease;
}

/* Subtitle */
.subtitle-wrap {
  align-self: center;
  width: min(92vw, 720px);
  margin-bottom: 0.9rem;
  padding: 0.85rem 1.35rem;
  border-radius: 18px;
  background: rgba(5, 11, 26, 0.56);
  border: 1px solid rgba(150, 200, 255, 0.16);
  backdrop-filter: blur(10px);
  text-align: center;
  transition: opacity 0.5s ease;
}

.subtitle-wrap.hidden {
  opacity: 0;
}

.subtitle-speaker {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  color: var(--accent-cyan);
  margin-bottom: 0.3rem;
}

.subtitle-text {
  font-size: clamp(0.92rem, 1.9vw, 1.08rem);
  line-height: 1.75;
  color: rgba(244, 249, 255, 0.95);
  min-height: 1.75em;
}

/* Bottom Controls */
.hud-bottom {
  display: flex;
  justify-content: center;
}

.hud-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 0.85rem;
  border-radius: 18px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(14px);
}

.ctrl-btn {
  cursor: pointer;
  padding: 0.4rem 0.78rem;
  border-radius: 999px;
  border: 1px solid rgba(165, 210, 255, 0.22);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  font-size: 0.78rem;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.ctrl-btn:hover {
  background: rgba(130, 195, 255, 0.2);
}

.ctrl-btn.active {
  background: rgba(110, 190, 255, 0.24);
  border-color: rgba(126, 227, 255, 0.55);
}

.ctrl-wake {
  border-color: rgba(255, 216, 155, 0.45);
  color: var(--accent-gold);
}

.ctrl-wake:hover {
  background: rgba(255, 216, 155, 0.18);
}

.vol-ctrl {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.74rem;
  color: var(--text-dim);
  padding: 0 0.25rem;
}

.vol-ctrl input[type="range"] {
  width: 62px;
  accent-color: var(--accent-cyan);
}

/* Debug Drawer */
.debug-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(92vw, 370px);
  z-index: 20;
  background: rgba(6, 12, 28, 0.92);
  border-left: 1px solid rgba(145, 200, 255, 0.28);
  backdrop-filter: blur(18px);
  padding: 1.15rem;
  overflow-y: auto;
  transform: translateX(105%);
  transition: transform 0.3s ease;
}

.debug-drawer.open {
  transform: translateX(0);
}

.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.debug-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent-cyan);
}

.debug-section {
  margin-bottom: 1.15rem;
}

.debug-section h3 {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 0.55rem;
}

.debug-chapter-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.dbg-ch-btn {
  cursor: pointer;
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(145, 200, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  font-size: 0.8rem;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.dbg-ch-btn:hover {
  background: rgba(126, 227, 255, 0.14);
}

.dbg-ch-btn.current {
  border-color: var(--accent-cyan);
  background: rgba(126, 227, 255, 0.2);
}

.dbg-ch-meta {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
}

.debug-row {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  margin-bottom: 0.7rem;
}

.debug-row select, .debug-row input {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(155, 205, 255, 0.24);
  border-radius: 8px;
  color: var(--text-main);
  padding: 0.35rem 0.5rem;
}

.debug-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.debug-state-json {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.7rem;
  line-height: 1.5;
  padding: 0.65rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.42);
  color: #bfe8ff;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Mobile Portrait Responsive */
@media (max-width: 720px) {
  .title-content {
    flex-direction: column;
    text-align: center;
    gap: 1.2rem;
    padding: 1.4rem 1.25rem;
    max-height: 92vh;
    overflow-y: auto;
  }

  .title-portrait-wrap {
    flex: none;
  }

  #title-portrait {
    width: 155px;
    max-height: 200px;
  }

  .title-actions {
    justify-content: center;
  }

  .lead-copy {
    font-size: 0.86rem;
    margin-bottom: 1.15rem;
  }

  .hud {
    padding: 0.75rem 0.8rem;
  }

  .hud-top {
    flex-wrap: wrap;
  }

  .depth-bar-track {
    width: 44px;
  }

  .subtitle-wrap {
    padding: 0.65rem 0.9rem;
    margin-bottom: 0.6rem;
  }

  .hud-controls {
    gap: 0.35rem;
    padding: 0.45rem 0.6rem;
  }

  .ctrl-btn {
    font-size: 0.72rem;
    padding: 0.35rem 0.62rem;
  }
}
