@font-face {
  font-family: "Playfair Display";
  font-style: italic;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/playfair-display-latin-700-italic.woff2") format("woff2");
}

:root {
  color-scheme: dark;
  --bg: #070a16;
  --ink: #f3e7c8;
  --muted: #b9b2a0;
  --gold: #f3c45f;
  --gold-soft: #e9c97a55;
  --glass: #0c0f1d99;
  --kai: "STKaiti", "KaiTi", "Kaiti SC", "Noto Serif CJK SC", serif;
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
button, input { color: inherit; font: inherit; -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 1px solid var(--gold); outline-offset: 3px; }

#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; outline: none; }

.loading {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 5;
  background: var(--bg); color: var(--gold); letter-spacing: .3em; font-size: 14px;
  transition: opacity .9s ease;
}
.loading span { display: inline-block; animation: spin 3s linear infinite; margin-right: 8px; }
.loading.done { opacity: 0; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.fallback { position: fixed; inset: 40% 10% auto; text-align: center; line-height: 1.8; color: var(--muted); z-index: 6; }

/* ---------- top-left intro ---------- */
.intro {
  position: fixed; z-index: 2;
  left: max(clamp(16px, 2.6vw, 36px), env(safe-area-inset-left));
  top: max(clamp(14px, 2.6vh, 30px), env(safe-area-inset-top));
  max-width: min(460px, calc(100vw - 96px));
  pointer-events: none;
}
.intro > * { pointer-events: auto; }
.eyebrow {
  margin: 0; font: 11px/1.6 Georgia, "Times New Roman", serif; letter-spacing: .32em;
  color: #e7d6ab; opacity: .9;
}
.flake { color: var(--gold); display: inline-block; animation: spin 9s linear infinite; }
.script {
  margin: 2px 0 4px; font-family: "Playfair Display", Georgia, serif; font-style: italic; font-weight: 700;
  font-size: clamp(34px, 4.4vw, 60px); line-height: 1.12; letter-spacing: .005em;
  background: linear-gradient(180deg, #fff4cf 0%, #f6d27a 45%, #d4943a 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px #f3b84a4d);
  pointer-events: none;
}
.greeting { margin: 0; font-family: var(--kai); font-size: 15px; letter-spacing: .22em; color: #eadfc4; overflow-wrap: anywhere; }
.dedication { margin: 4px 0 0; font-family: var(--kai); font-size: 14px; letter-spacing: .16em; color: #d6be86; }
.countdown { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 12px 0 10px; font-size: 12px; color: #d8cdb2; }
.cd-icon { display: inline-grid; place-items: center; color: var(--gold); }
.cd {
  padding: 3px 7px; border: 1px solid var(--gold-soft); border-radius: 6px;
  background: #0c0f1d88; letter-spacing: .04em; white-space: nowrap;
}
.cd b { color: #ffe7a8; font-weight: 600; font-variant-numeric: tabular-nums; margin-right: 1px; }
.countdown.festive .cd { display: none; }
.countdown .festive-text { color: #ffe7a8; letter-spacing: .14em; font-family: var(--kai); font-size: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; min-height: 34px; padding: 6px 13px;
  border: 1px solid #ffffff22; border-radius: 9px; background: var(--glass);
  font-size: 12px; letter-spacing: .1em; color: #e6dcc3; backdrop-filter: blur(6px);
  transition: border-color .2s, background-color .2s;
}

/* ---------- top-right controls ---------- */
.controls {
  position: fixed; z-index: 2; display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
  right: max(clamp(14px, 2.4vw, 32px), env(safe-area-inset-right));
  top: max(clamp(14px, 2.6vh, 30px), env(safe-area-inset-top));
}
.pill {
  display: inline-flex; align-items: center; gap: 8px; min-height: 34px; padding: 6px 14px;
  border: 1px solid var(--gold-soft); border-radius: 999px; background: var(--glass);
  font-size: 12px; letter-spacing: .12em; color: #f1e3bd; backdrop-filter: blur(6px);
  transition: border-color .2s, background-color .2s;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.pill.galaxy .dot { background: #9fc6ff; box-shadow: 0 0 8px #9fc6ff; }
.icons { display: flex; gap: 8px; }
.icon {
  width: 38px; height: 38px; display: grid; place-items: center; padding: 0;
  border: 1px solid #ffffff22; border-radius: 50%; background: var(--glass); color: #eadfc4;
  backdrop-filter: blur(6px); transition: border-color .2s, background-color .2s, color .2s;
}
#music .on { display: none; }
#music[aria-pressed="true"] .on { display: block; }
#music[aria-pressed="true"] .off { display: none; }
#music[aria-pressed="true"] { color: var(--gold); border-color: var(--gold-soft); animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px #f3c45f14; } }
.chip:hover, .pill:hover, .icon:hover { border-color: #f3c45f99; background-color: #1d1a14cc; }

/* ---------- bottom hint ---------- */
.hintbar {
  position: fixed; z-index: 2; left: 50%; transform: translateX(-50%);
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 46px); margin: 0;
  padding: 7px 18px; border: 1px solid #ffffff1c; border-radius: 999px;
  background: #11131f99; backdrop-filter: blur(8px);
  font-size: 12px; letter-spacing: .08em; color: #cfc8b6; white-space: nowrap; pointer-events: none;
}
.hintbar i { font-style: normal; padding: 0 9px; opacity: .55; }
.hintbar .touch { display: none; }

/* ---------- bottom signature ---------- */
.signature {
  position: fixed; z-index: 2; left: 0; right: 0; margin: 0; text-align: center;
  bottom: max(14px, env(safe-area-inset-bottom));
  font-family: var(--kai); font-size: clamp(22px, 2.4vw, 30px); letter-spacing: .2em; line-height: 1.3;
  color: #ffe9b8; text-shadow: 0 0 18px #f3b84a88, 0 0 42px #e8505b44, 0 1px 2px #000c;
  pointer-events: none;
}
.signature::before {
  content: ""; position: fixed; z-index: -1; left: 0; right: 0; bottom: 0; height: 150px;
  background: linear-gradient(to top, #05070fe6 0%, #05070f99 45%, #05070f00 100%);
}
.signature span { letter-spacing: 0; padding: 0 .12em; opacity: .85; }

/* ---------- cursor ring ---------- */
#cursor {
  position: fixed; left: 0; top: 0; z-index: 4; width: 26px; height: 26px; margin: -13px 0 0 -13px;
  border: 1.5px solid #f6e3b0; border-radius: 50%; pointer-events: none;
  box-shadow: 0 0 10px #f3c45f55; opacity: 0; transition: width .2s, height .2s, margin .2s, opacity .3s, border-color .2s;
}
#cursor.show { opacity: .85; }
#cursor.hot { width: 44px; height: 44px; margin: -22px 0 0 -22px; border-color: var(--gold); }

/* ---------- dialogs ---------- */
dialog {
  width: min(430px, calc(100vw - 28px)); padding: 0; border: 1px solid var(--gold-soft);
  border-radius: 16px; background: #0d0f19f2; color: var(--ink);
  box-shadow: 0 30px 80px #000c;
}
dialog::backdrop { background: #000a; backdrop-filter: blur(3px); }
.panel { display: grid; gap: 14px; padding: 22px 22px 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel h2 { margin: 0; font-size: 17px; font-weight: 500; letter-spacing: .08em; }
.close { width: 36px; height: 36px; border: 1px solid transparent; border-radius: 50%; background: none; font-size: 22px; line-height: 1; color: var(--muted); }
.panel-note { margin: -6px 0 2px; color: #9d988a; font-size: 13px; line-height: 1.65; }
.panel label { display: grid; gap: 6px; font-size: 12px; letter-spacing: .1em; color: #cbbf9f; }
.panel .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.panel input {
  width: 100%; min-height: 42px; padding: 0 12px;
  background: #ffffff08; border: 1px solid #ffffff1a; border-radius: 10px; font-size: 15px; color: var(--ink);
}
.panel input:focus { border-color: #f3c45f99; outline: none; }
#f-link { font: 12px/1 ui-monospace, Consolas, monospace; color: #cbbf9f; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.panel-actions button {
  flex: 1 1 auto; min-height: 44px; padding: 0 16px; border-radius: 22px;
  border: 1px solid var(--gold-soft); background: #ffffff08; font-size: 14px; color: #ecdcb2;
}
.panel-actions .primary { background: var(--gold); border-color: var(--gold); color: #1b1406; font-weight: 600; }
.panel-actions .primary:hover { background-color: #ffd785 !important; }

.lightbox {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px;
  background: #000c; backdrop-filter: blur(4px); cursor: zoom-out; animation: fade .3s ease;
}
.lightbox[hidden] { display: none; }
.lightbox figure { margin: 0; text-align: center; }
.lightbox img {
  max-width: min(86vw, 640px); max-height: 74vh; border-radius: 6px;
  border: 10px solid #2a2418; box-shadow: 0 0 0 1px #f3c45f66, 0 30px 80px #000;
}
.lightbox figcaption { margin-top: 12px; font-size: 12px; color: #8f897a; letter-spacing: .12em; }
@keyframes fade { from { opacity: 0; } }

#toast {
  position: fixed; left: 50%; bottom: 120px; z-index: 30; transform: translate(-50%, 12px);
  padding: 10px 18px; border-radius: 20px; border: 1px solid var(--gold-soft);
  background: #14120cee; color: var(--ink); font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  .eyebrow { font-size: 9.5px; letter-spacing: .22em; }
  .greeting { font-size: 13px; letter-spacing: .14em; }
  .countdown { gap: 4px; margin: 9px 0 8px; }
  .cd { padding: 2px 5px; font-size: 11px; }
  .icons { flex-direction: column; }
  .pill { width: 38px; height: 38px; min-height: 38px; padding: 0; justify-content: center; }
  .pill #mode-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .pill .dot { width: 9px; height: 9px; }
  .intro { max-width: calc(100vw - 80px); }
  .script { font-size: clamp(30px, 8.6vw, 40px); }
  .hintbar { font-size: 11px; padding: 7px 14px; }
  .hintbar i { padding: 0 5px; }
}
@media (pointer: coarse), (max-width: 700px) {
  .hintbar .desk { display: none; }
  .hintbar .touch { display: inline; }
  #cursor { display: none; }
}
