:root {
  color-scheme: dark;
  --cream: #fbf3dc;
  --paper: #f3e6c4;
  --gold: #e6c88a;
  --red-ribbon: #a82824;
  --desk-pine: #27483f;
  --desk-birthday: #1d3437;
  --dark-pill: rgba(16, 31, 27, 0.78);
  --dark-pill-border: rgba(243, 230, 196, 0.24);
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", "SimSun", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-family: var(--serif);
  color: var(--cream);
  background: var(--desk-pine);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  height: 100svh;
  overflow: hidden;
  background: var(--desk-pine);
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  cursor: pointer;
  color: inherit;
  border: 0;
  background: none;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

button:disabled {
  opacity: 0.35;
  cursor: default;
}

#desk,
#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#stage {
  touch-action: none;
}

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

/* Top Bar */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 68px;
  padding: 0 clamp(16px, 3.2vw, 42px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  z-index: 20;
}

.top-bar button {
  pointer-events: auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--cream);
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(16px, 1.35vw, 20px);
  letter-spacing: 0.1em;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(16, 31, 27, 0.55);
  border: 1px solid rgba(251, 243, 220, 0.2);
  backdrop-filter: blur(8px);
}

.book-icon {
  color: var(--gold);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.06em;
  white-space: nowrap;
  color: var(--cream);
  background: var(--dark-pill);
  border: 1px solid var(--dark-pill-border);
  padding: 8px 15px;
  border-radius: 999px;
  backdrop-filter: blur(8px);
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}

.pill-btn:hover {
  background: rgba(24, 46, 40, 0.92);
  border-color: rgba(251, 243, 220, 0.45);
}

.pill-btn[aria-pressed="true"],
.pill-btn[aria-expanded="true"] {
  border-color: var(--gold);
  color: var(--gold);
}

.sound-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(251, 243, 220, 0.4);
}

.pill-btn[aria-pressed="true"] .sound-dot {
  background: #df5b4d;
  box-shadow: 0 0 8px #df5b4d;
}

/* Timeline Popover */
.timeline-popover {
  position: fixed;
  top: 74px;
  right: clamp(16px, 3.2vw, 42px);
  width: min(320px, 90vw);
  background: rgba(15, 29, 25, 0.94);
  border: 1px solid rgba(251, 243, 220, 0.28);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: 0 18px 48px rgba(4, 12, 10, 0.65);
  backdrop-filter: blur(12px);
  z-index: 35;
}

.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: rgba(251, 243, 220, 0.72);
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(251, 243, 220, 0.14);
}

.icon-close {
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
  color: var(--cream);
}

.timeline-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.timeline-node {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 10px;
  text-align: left;
  transition: background 0.18s;
}

.timeline-node:hover {
  background: rgba(251, 243, 220, 0.1);
}

.timeline-node.active {
  background: rgba(168, 40, 36, 0.35);
  border: 1px solid rgba(230, 200, 138, 0.45);
}

.tl-year {
  font-family: Georgia, serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--gold);
  min-width: 44px;
}

.tl-name {
  font-family: var(--serif);
  font-size: 15px;
  color: var(--cream);
}

/* Cover Intro Overlay */
.intro-overlay {
  position: fixed;
  left: clamp(24px, 6vw, 84px);
  top: 50%;
  transform: translateY(-50%);
  max-width: 390px;
  pointer-events: none;
  z-index: 15;
}

.cover-badge {
  display: inline-block;
  font-family: Georgia, serif;
  font-size: 14px;
  letter-spacing: 0.18em;
  color: var(--gold);
  border-bottom: 1px solid rgba(230, 200, 138, 0.45);
  padding-bottom: 4px;
}

.intro-overlay h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(34px, 4vw, 56px);
  color: var(--cream);
  margin: 14px 0 12px;
  letter-spacing: 0.08em;
}

.intro-overlay p {
  font-family: var(--sans);
  font-size: clamp(14px, 1.1vw, 16px);
  line-height: 1.75;
  color: rgba(251, 243, 220, 0.85);
  margin: 0 0 22px;
}

.intro-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  pointer-events: auto;
}

.primary-btn,
.act-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #e9cf97;
  color: #261b13;
  border: 1px solid #f7e6be;
  box-shadow: 0 6px 20px rgba(8, 20, 16, 0.45);
  border-radius: 999px;
  padding: 10px 22px;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.08em;
  pointer-events: auto;
  transition: transform 0.15s, background 0.2s;
}

.primary-btn:hover,
.act-btn:hover {
  background: #f5dfb0;
  transform: translateY(-1px);
}

/* Book Top-Left Chapter HUD */
.chapter-hud {
  position: fixed;
  top: 76px;
  left: clamp(16px, 3.2vw, 42px);
  max-width: min(370px, 52vw);
  background: rgba(15, 30, 26, 0.68);
  border: 1px solid rgba(251, 243, 220, 0.22);
  border-radius: 16px;
  padding: 12px 16px;
  backdrop-filter: blur(8px);
  pointer-events: none;
  z-index: 15;
}

.hud-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--gold);
}

.hud-title {
  margin: 4px 0 4px;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(20px, 1.9vw, 28px);
  color: var(--cream);
  letter-spacing: 0.06em;
}

.hud-hint {
  margin: 0 0 10px;
  font-family: var(--sans);
  font-size: 12.5px;
  line-height: 1.5;
  color: rgba(251, 243, 220, 0.84);
}

.hud-trigger-row {
  pointer-events: auto;
}

.act-btn {
  padding: 7px 16px;
  font-size: 14px;
}

/* Bottom-Left Excerpt & Read Entry */
.bottom-left-bar {
  position: fixed;
  left: clamp(16px, 3.2vw, 42px);
  bottom: 18px;
  max-width: min(440px, calc(100vw - 455px));
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(15, 30, 26, 0.76);
  border: 1px solid rgba(251, 243, 220, 0.22);
  border-radius: 999px;
  padding: 8px 10px 8px 18px;
  backdrop-filter: blur(8px);
  z-index: 16;
}

.excerpt-line {
  margin: 0;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--cream);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.read-page-btn {
  flex-shrink: 0;
  background: rgba(251, 243, 220, 0.14);
  border: 1px solid rgba(251, 243, 220, 0.32);
  color: var(--cream);
  font-family: var(--serif);
  font-weight: 600;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 999px;
  transition: background 0.2s;
}

.read-page-btn:hover {
  background: rgba(251, 243, 220, 0.25);
}

/* Slide-out Cream Story Card */
.story-card {
  position: fixed;
  left: clamp(16px, 3.2vw, 42px);
  bottom: 76px;
  width: min(390px, calc(100vw - 32px));
  background: #fbf3dc;
  color: #362c21;
  border: 1px solid #d5c198;
  border-radius: 16px;
  padding: 20px 22px 18px;
  box-shadow: 0 18px 48px rgba(5, 14, 11, 0.55);
  z-index: 28;
  animation: slideUpCard 0.24s ease-out;
}

@keyframes slideUpCard {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card-close {
  position: absolute;
  top: 10px;
  right: 12px;
  font-family: var(--sans);
  font-size: 14px;
  color: #6b5842;
  padding: 4px 8px;
  border-radius: 8px;
}

.card-close:hover {
  background: rgba(107, 88, 66, 0.1);
}

.card-year-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 18px;
  color: #8f2a24;
  margin-bottom: 10px;
}

.card-full-copy {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.8;
  color: #3b3125;
  margin: 0 0 14px;
}

.card-actions {
  display: flex;
  justify-content: flex-end;
}

.dark-act {
  background: #8f2a24;
  color: #fbf3dc;
  border-color: #a83731;
}

.dark-act:hover {
  background: #a5322b;
}

/* Bottom-Right Dark Page-Turning Panel */
.turn-panel {
  position: fixed;
  right: clamp(16px, 3.2vw, 42px);
  bottom: 16px;
  background: rgba(14, 28, 24, 0.84);
  border: 1px solid rgba(251, 243, 220, 0.25);
  border-radius: 16px;
  padding: 8px 14px 10px;
  backdrop-filter: blur(10px);
  z-index: 16;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.turn-panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-family: var(--sans);
  font-size: 11.5px;
  color: rgba(251, 243, 220, 0.76);
}

.turn-progress {
  font-weight: 600;
  color: var(--gold);
}

.turn-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.arrow-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(251, 243, 220, 0.28);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  color: var(--cream);
  transition: background 0.18s;
}

.arrow-btn:hover:not(:disabled) {
  background: rgba(251, 243, 220, 0.14);
}

.year-ticks {
  display: flex;
  align-items: center;
  gap: 4px;
}

.year-tick {
  padding: 5px 8px;
  border-radius: 8px;
  font-family: Georgia, serif;
  font-size: 12px;
  color: rgba(251, 243, 220, 0.72);
  border: 1px solid transparent;
  transition: all 0.18s;
}

.year-tick small {
  font-family: var(--sans);
  font-size: 10px;
  margin-left: 2px;
  opacity: 0.85;
}

.year-tick:hover {
  color: var(--cream);
  background: rgba(251, 243, 220, 0.1);
}

.year-tick.active {
  color: var(--cream);
  background: rgba(168, 40, 36, 0.45);
  border-color: var(--gold);
}

/* Birthday Letter Dialog */
.letter-dialog {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(540px, 92vw);
  max-height: 86svh;
}

.letter-dialog::backdrop {
  background: rgba(10, 22, 19, 0.72);
  backdrop-filter: blur(6px);
}

.letter-sheet {
  position: relative;
  background: #fbf3dc;
  color: #382d21;
  border: 1px solid #d8c39a;
  border-radius: 14px;
  padding: 34px clamp(24px, 4.5vw, 48px) 30px;
  box-shadow: 0 24px 70px rgba(4, 12, 10, 0.72);
  background-image: repeating-linear-gradient(
    0deg,
    rgba(162, 134, 92, 0.06) 0 1px,
    transparent 1px 32px
  );
}

.letter-ribbon-mark {
  width: 44px;
  height: 4px;
  border-radius: 2px;
  background: var(--red-ribbon);
  margin-bottom: 16px;
}

.letter-sheet h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 25px;
  color: #2f2419;
  margin: 0 0 16px;
}

.letter-sheet p {
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.95;
  color: #3f3326;
  margin: 14px 0;
}

.letter-signature {
  margin-top: 24px;
  text-align: right;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 16px;
  line-height: 1.65;
  color: #2f2419;
}

.letter-signature span {
  font-weight: 400;
  font-size: 14px;
  color: #6e5b43;
}

/* Mobile Portrait & Narrow Tablet Layout */
@media (max-width: 820px), (max-aspect-ratio: 17/20) {
  .top-bar {
    height: 56px;
    padding: 0 10px;
  }
  .brand {
    font-size: 14px;
    padding: 6px 10px;
    gap: 6px;
    white-space: nowrap;
  }
  .top-actions {
    gap: 6px;
  }
  .pill-btn {
    font-size: 11.5px;
    padding: 6px 9px;
  }
  .intro-overlay {
    left: 16px;
    right: 16px;
    top: auto;
    bottom: 92px;
    transform: none;
    max-width: none;
    text-align: center;
    background: rgba(14, 28, 24, 0.78);
    padding: 16px 18px;
    border-radius: 16px;
    border: 1px solid rgba(251, 243, 220, 0.2);
    backdrop-filter: blur(8px);
  }
  .intro-overlay h1 {
    font-size: 28px;
    margin: 8px 0;
  }
  .intro-overlay p {
    font-size: 13.5px;
    margin-bottom: 14px;
  }
  .intro-buttons {
    justify-content: center;
  }
  .chapter-hud {
    top: 60px;
    left: 12px;
    right: 12px;
    max-width: none;
    padding: 10px 14px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
  }
  .hud-title {
    font-size: 19px;
    margin: 0;
  }
  .hud-hint {
    width: 100%;
    margin: 2px 0 4px;
    font-size: 12px;
  }
  .bottom-left-bar {
    left: 12px;
    right: 12px;
    bottom: 90px;
    max-width: none;
  }
  .turn-panel {
    left: 12px;
    right: 12px;
    bottom: 12px;
    padding: 7px 12px 9px;
  }
  .turn-controls {
    justify-content: space-between;
  }
  .year-tick {
    padding: 5px 6px;
    font-size: 11px;
  }
  .story-card {
    left: 12px;
    right: 12px;
    bottom: 145px;
    width: auto;
  }
}

.loading-pill {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 25;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(24, 38, 32, 0.78);
  color: #f6ebd1;
  font-size: 13px;
  letter-spacing: 0.04em;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.loading-pill[hidden] {
  display: none;
}
