:root {
  --bg: #07060a;
  --ink: #f4efe8;
  --muted: rgba(244, 239, 232, 0.58);
  --line: rgba(244, 239, 232, 0.14);
  --panel: rgba(12, 10, 16, 0.72);
  --accent: #d7a36a;
  --warm: #c45c3e;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --player-h: calc(128px + var(--safe-b));
  font-synthesis: none;
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 18%, #2a2038 0%, #120e18 60%);
  color: var(--ink);
  font-family: "Songti SC", "STSong", "Noto Serif SC", Georgia, serif;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: none;
  overflow: hidden;
}

#app.pure .top-bar,
#app.pure .cam-rail,
#app.pure .hint,
#app.pure .player-actions {
  opacity: 0;
  pointer-events: none;
}

#app.pure #guide-sheet {
  display: none;
}

#app.lettering .top-bar,
#app.lettering .cam-rail,
#app.lettering .hint,
#app.lettering .player,
#app.lettering .dedication,
#app.lettering .subtitle,
#app.lettering .sheet {
  opacity: 0;
  pointer-events: none;
}

.letter-gate {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px 18px calc(24px + var(--safe-b));
  background:
    radial-gradient(ellipse at 50% 28%, rgba(72, 48, 68, 0.55), transparent 55%),
    linear-gradient(165deg, #1a1422 0%, #0c0a10 55%, #141018 100%);
  transition: opacity 0.55s ease, visibility 0.55s ease;
}

.letter-gate.leaving {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.letter-seal {
  appearance: none;
  border: 0;
  background: transparent;
  color: #f3ebe2;
  font: inherit;
  display: grid;
  justify-items: center;
  gap: 14px;
  cursor: pointer;
  animation: seal-breathe 3.2s ease-in-out infinite;
}

.letter-seal[hidden] {
  display: none !important;
}

.seal-wax {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.55rem;
  letter-spacing: 0.12em;
  color: #f8ebe4;
  background:
    radial-gradient(circle at 35% 30%, #c45a5a, #8a2e36 62%, #5c1c24 100%);
  box-shadow:
    0 0 0 6px rgba(140, 48, 56, 0.35),
    0 18px 40px rgba(0, 0, 0, 0.45);
}

.seal-to {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.28em;
}

.seal-hint {
  font-size: 0.82rem;
  color: rgba(243, 235, 226, 0.55);
  letter-spacing: 0.16em;
}

@keyframes seal-breathe {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.letter-paper {
  width: min(92vw, 380px);
  padding: 34px 28px 22px;
  border-radius: 4px 14px 10px 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 28%),
    linear-gradient(145deg, #efe6d6 0%, #e7d9c4 48%, #dfd0b8 100%);
  color: #2a221c;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.35) inset,
    0 24px 60px rgba(0, 0, 0, 0.45);
  animation: letter-in 0.55s ease;
}

.letter-paper[hidden] {
  display: none;
}

@keyframes letter-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.letter-dear {
  margin: 0 0 1.1rem;
  font-size: 1.12rem;
  letter-spacing: 0.08em;
}

.letter-line {
  margin: 0 0 0.72rem;
  font-size: 1.02rem;
  line-height: 1.75;
  letter-spacing: 0.06em;
}

.letter-from {
  margin: 1.6rem 0 1.2rem;
  text-align: right;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: #5a4438;
}

.letter-enter {
  appearance: none;
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 999px;
  background: #2a221c;
  color: #f3ebe2;
  font: inherit;
  font-size: 0.92rem;
  letter-spacing: 0.14em;
}

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

.top-bar {
  position: absolute;
  top: calc(12px + var(--safe-t));
  left: 14px;
  right: 14px;
  z-index: 6;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  transition: opacity 0.35s ease;
}

.brand {
  margin: 0;
  font-size: clamp(1.35rem, 6.2vw, 1.9rem);
  letter-spacing: 0.04em;
  text-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}

.song {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.guide-sheet {
  max-height: min(62vh, 520px);
  overflow: auto;
}

.guide-list {
  margin: 10px 0 4px;
  padding-left: 1.15rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.55;
  display: grid;
  gap: 8px;
}

.guide-list b {
  color: var(--ink);
  font-weight: 600;
}

.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  backdrop-filter: blur(12px);
}

.dedication {
  position: absolute;
  left: 18px;
  right: 18px;
  top: calc(72px + var(--safe-t));
  z-index: 5;
  margin: 0;
  text-align: center;
  font-size: 0.86rem;
  line-height: 1.55;
  color: #ffe7cf;
  text-shadow: 0 8px 28px rgba(0, 0, 0, 0.65);
  transition: opacity 0.9s ease, transform 0.9s ease;
  pointer-events: none;
}

.dedication.hidden {
  opacity: 0;
  transform: translateY(-6px);
}

.subtitle {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(var(--player-h) + 36px);
  z-index: 7;
  margin: 0 auto;
  max-width: 34rem;
  text-align: center;
  font-size: clamp(1.02rem, 4.4vw, 1.28rem);
  line-height: 1.45;
  letter-spacing: 0.04em;
  color: #fffaf2;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(12, 10, 14, 0.42);
  backdrop-filter: blur(8px);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  width: fit-content;
}

.subtitle.hidden {
  opacity: 0;
  transform: translateY(8px);
}

.subtitle.pop {
  animation: sub-pop 0.35s ease;
}

@keyframes sub-pop {
  from {
    opacity: 0.35;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.cam-rail {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-54%);
  z-index: 6;
  display: grid;
  gap: 8px;
  width: min(34vw, 126px);
  transition: opacity 0.35s ease;
}

.cam-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(10, 8, 14, 0.55);
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 8px;
  font: inherit;
  font-size: 0.72rem;
  line-height: 1.35;
  text-align: left;
  letter-spacing: 0.02em;
  backdrop-filter: blur(10px);
}

.cam-btn.active {
  border-color: rgba(215, 163, 106, 0.55);
  background: rgba(215, 163, 106, 0.16);
}

.hint {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(var(--player-h) + 8px);
  z-index: 5;
  margin: 0;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  pointer-events: none;
  transition: opacity 0.45s ease;
}

.hint.fade {
  opacity: 0;
}

.player {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 8;
  padding: 12px 14px calc(12px + var(--safe-b));
  background: linear-gradient(180deg, transparent, rgba(5, 4, 8, 0.55) 18%, rgba(5, 4, 8, 0.92));
  backdrop-filter: blur(8px);
}

.player-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
}

.play-btn {
  appearance: none;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 0;
  background: linear-gradient(160deg, #e0b27a, #b86b3d);
  color: #1a1008;
  font-size: 1.05rem;
  box-shadow: 0 10px 28px rgba(184, 107, 61, 0.35);
}

.meta {
  min-width: 0;
}

.track-title {
  margin: 0 0 6px;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seek {
  width: 100%;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  outline: none;
}

.seek::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #f0d2a4;
  border: 0;
}

.time-row {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.player-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
  transition: opacity 0.35s ease;
}

.action {
  appearance: none;
  min-height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font: inherit;
  font-size: 0.84rem;
  letter-spacing: 0.04em;
}

.sheet {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(var(--player-h) + 8px);
  z-index: 9;
  padding: 16px 14px 12px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
  display: grid;
  gap: 10px;
}

.sheet[hidden] {
  display: none;
}

.sheet-title {
  margin: 0;
  font-size: 1rem;
}

.gate-copy {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.mode-card {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: inherit;
  border-radius: 14px;
  padding: 12px;
  text-align: left;
  font: inherit;
  display: grid;
  gap: 3px;
}

.mode-name {
  font-size: 0.98rem;
}

.mode-desc {
  color: var(--muted);
  font-size: 0.8rem;
}

.ghost-btn,
.file-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  min-height: 42px;
}

.file-btn {
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(215, 163, 106, 0.14);
  border: 1px solid rgba(215, 163, 106, 0.3);
}

.file-btn input {
  display: none;
}

.toast {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  z-index: 12;
  margin: 0;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(10, 8, 12, 0.82);
  border: 1px solid var(--line);
  font-size: 0.86rem;
  pointer-events: none;
  transition: opacity 0.3s ease;
  max-width: 86vw;
  text-align: center;
}

.toast.hidden {
  opacity: 0;
}

@media (min-width: 768px) {
  .player,
  .sheet {
    max-width: 460px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }

  .sheet {
    transform: translateX(-50%);
  }

  .cam-rail {
    right: max(18px, calc(50% - 280px));
  }
}
