@font-face {
  font-family: "MV Brush";
  src: url("../fonts/brush.woff2") format("woff2");
  font-display: block;
}
@font-face {
  font-family: "MV Hand";
  src: url("../fonts/hand.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "MV Serif";
  src: url("../fonts/serif.woff2") format("woff2");
  font-weight: 200 900;
  font-display: swap;
}

/* one deliberate night palette (the card is a night scene in any system theme) */
:root {
  color-scheme: dark;
  --night: #04060d;
  --night-2: #0b1122;
  --moon: #f6eedb;
  --moon-dim: rgba(246, 238, 219, 0.66);
  --gold: #e3bd78;
  --gold-soft: rgba(227, 189, 120, 0.5);
  --gold-faint: rgba(227, 189, 120, 0.18);
  --seal: #b2301f;
  --seal-deep: #86200f;
  --glass: rgba(10, 14, 28, 0.42);
  --line: rgba(246, 238, 219, 0.16);
  --paper: #e9dfca;
  --ink-text: #1b1a20;
  --ink-soft: rgba(27, 26, 32, 0.62);
  --gold-leaf: #b48a3c;
  --brush: "MV Brush", "Kaiti SC", "STKaiti", "KaiTi", serif;
  --hand: "MV Hand", "Kaiti SC", "STKaiti", "KaiTi", serif;
  --serif: "MV Serif", "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--night);
  color: var(--moon);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  font-family: var(--serif);
}
#stage {
  position: fixed;
  inset: 0;
  background: var(--paper);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#gl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 1.6s var(--ease);
}
#gl.on {
  opacity: 1;
}
button {
  font: inherit;
  color: inherit;
}
[hidden] {
  display: none !important;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ------------------------------------------------------------ cover */
.cover {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto auto auto auto;
  justify-items: center;
  align-items: center;
  padding: calc(var(--safe-t) + 6vh) 16px calc(var(--safe-b) + 5vh);
  text-align: center;
  color: var(--ink-text);
  animation: coverIn 1.6s var(--ease) both;
  transition: opacity 1.4s var(--ease), transform 1.6s var(--ease), filter 1.4s var(--ease);
}
.cover.leaving {
  opacity: 0;
  filter: blur(4px);
  pointer-events: none;
  transition-duration: 0.75s;
}
.cover-bottom {
  display: grid;
  justify-items: center;
}
/* paper layout: the ring is placed over the moon-to-be by script */
.cover.placed {
  display: block;
  padding: 0;
}
.cover.placed .cover-kicker {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--safe-t) + 5.5vh);
}
.cover.placed .cover-to {
  position: absolute;
  left: 0;
  right: 0;
  margin: 0;
}
.cover.placed .cover-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-b) + 4.5vh);
}
@keyframes coverIn {
  from {
    opacity: 0;
  }
}
.cover-kicker {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.6em;
  text-indent: 0.6em;
  color: #8f2a1c;
  opacity: 0.9;
}
.cover-moon {
  position: relative;
  width: min(74vmin, 360px);
  aspect-ratio: 1;
  max-width: 100%;
  display: grid;
  place-items: center;
}
/* once the script knows where the moon will be, the ring sits exactly there */
.cover-moon.placed {
  position: absolute;
  margin: 0;
  max-width: none;
}
.cover-moon svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.cover-moon .ring,
.cover-moon .ring-inner,
.cover-moon .ring-halo {
  fill: none;
}
.cover-moon .ring {
  stroke: var(--gold-leaf);
  stroke-width: 1.1;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  transform: rotate(-90deg);
  transform-origin: 100px 100px;
  animation: drawRing 3.2s var(--ease) 0.4s forwards;
}
.cover-moon .ring-inner {
  stroke: rgba(150, 110, 50, 0.28);
  stroke-width: 0.5;
  stroke-dasharray: 1.2 3.4;
  animation: spin 90s linear infinite;
  transform-origin: 100px 100px;
}
.cover-moon .ring-halo {
  stroke: rgba(190, 140, 60, 0.12);
  stroke-width: 5;
  filter: blur(3px);
  opacity: 0;
  animation: glowIn 3s var(--ease) 2.4s forwards;
}
@keyframes drawRing {
  to {
    stroke-dashoffset: 0;
  }
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes glowIn {
  to {
    opacity: 1;
  }
}
.cover.opening .cover-moon .ring-halo {
  animation: none;
  opacity: 1;
  stroke-width: 60;
  stroke: rgba(255, 226, 170, 0.35);
  transition: stroke-width 1.2s var(--ease), stroke 1.2s var(--ease);
}
.cover-head {
  position: relative;
  margin: 0;
  writing-mode: vertical-rl;
  font-family: var(--brush);
  font-weight: 400;
  font-size: clamp(26px, 8.2vmin, 46px);
  letter-spacing: 0.22em;
  line-height: 1;
  white-space: nowrap;
  color: var(--ink-text);
  text-shadow: 0 0 1px rgba(27, 26, 32, 0.4);
  animation: inkIn 2.2s var(--ease) 0.9s both;
}
@keyframes inkIn {
  from {
    opacity: 0;
    filter: blur(8px);
    transform: translateY(-6px);
  }
}
.cover-to {
  margin: 1.2vh 0 0;
  font-family: var(--hand);
  font-size: clamp(17px, 4.6vmin, 24px);
  letter-spacing: 0.18em;
  color: var(--ink-soft);
  animation: inkIn 1.8s var(--ease) 1.6s both;
}
.seal-btn {
  position: relative;
  width: 68px;
  height: 68px;
  margin-top: 4vh;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  animation: inkIn 1.4s var(--ease) 2s both;
}
.seal-btn:disabled {
  cursor: progress;
}
.seal-face {
  position: relative;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  font-family: var(--brush);
  font-size: 34px;
  line-height: 1;
  color: #fbe9d6;
  background:
    radial-gradient(120% 90% at 30% 20%, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0) 60%),
    linear-gradient(160deg, #c4391f, var(--seal) 55%, var(--seal-deep));
  box-shadow: inset 0 0 0 2px rgba(251, 233, 214, 0.35), inset 0 0 0 4px var(--seal), 0 6px 24px rgba(178, 48, 31, 0.35);
  transition: transform 0.35s var(--ease), filter 0.35s var(--ease);
}
.seal-btn:disabled .seal-face {
  filter: saturate(0.4) brightness(0.7);
}
.seal-ring {
  position: absolute;
  background: conic-gradient(#8f2a1c calc(var(--p, 0) * 1turn), rgba(143, 42, 28, 0.14) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 1.5px), #000 calc(100% - 1px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 1.5px), #000 calc(100% - 1px));
  border-radius: 50%;
  inset: -10px;
  transition: opacity 0.6s var(--ease);
}
.seal-btn:not(:disabled) .seal-ring {
  background: none;
  -webkit-mask: none;
  mask: none;
  border: 1px solid rgba(178, 48, 31, 0.45);
  animation: pulse 2.6s var(--ease) infinite;
}
@keyframes pulse {
  0% {
    transform: scale(0.86);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}
.seal-btn:not(:disabled):hover .seal-face,
.seal-btn:focus-visible .seal-face {
  transform: scale(1.05);
}
.seal-btn:active .seal-face,
.cover.opening .seal-face {
  transform: scale(0.9) rotate(-4deg);
}
.seal-btn:focus-visible {
  outline: 1px solid var(--gold);
  outline-offset: 10px;
  border-radius: 12px;
}
.cover-tap {
  margin: 2.4vh 0 0;
  font-size: 14px;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: var(--ink-text);
  opacity: 0.9;
  min-height: 1.4em;
}
.cover-hint {
  margin: 0.8vh 0 0;
  font-size: 11.5px;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--ink-soft);
  opacity: 0.7;
}

/* ------------------------------------------------------------ HUD */
.hud {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px calc(var(--safe-b) + 14px);
  background: linear-gradient(to top, rgba(4, 6, 13, 0.55), rgba(4, 6, 13, 0));
  transition: opacity 0.6s var(--ease), transform 0.6s var(--ease);
}
.hud.dim {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}
.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  cursor: pointer;
}
.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: var(--moon);
  stroke: var(--moon);
  stroke-width: 0;
}
.icon-btn .wave,
.icon-btn .i-mute path:last-child {
  stroke-width: 1.6;
}
.icon-btn:focus-visible,
.track:focus-visible,
.btn:focus-visible {
  outline: 1px solid var(--gold);
  outline-offset: 3px;
}
#btnPlay .i-play,
#btnPlay.paused .i-pause,
#btnMute .i-mute,
#btnMute.muted .i-sound {
  display: none;
}
#btnPlay.paused .i-play,
#btnMute.muted .i-mute {
  display: block;
}
.track {
  position: relative;
  flex: 1;
  height: 40px;
  cursor: pointer;
  touch-action: none;
}
.track-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}
.track-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, rgba(227, 189, 120, 0.5), var(--gold));
  box-shadow: 0 0 8px rgba(227, 189, 120, 0.7);
}
.track-ticks span {
  position: absolute;
  top: 50%;
  width: 3px;
  height: 3px;
  margin: -1.5px 0 0 -1.5px;
  border-radius: 50%;
  background: var(--moon-dim);
}

/* ------------------------------------------------------------ end card */
.endui {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 0 16px calc(var(--safe-b) + 3.2vh);
  animation: rise 1.4s var(--ease) both;
}
.endui.with-hud {
  padding-bottom: calc(var(--safe-b) + 84px);
}
@media (min-aspect-ratio: 13/10) {
  .endui {
    justify-content: flex-start;
    padding-left: 51vw;
  }
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}
.btn {
  min-height: 44px;
  padding: 0 22px;
  border-radius: 999px;
  font-size: 15px;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.2s var(--ease), background 0.3s var(--ease);
}
.btn:active {
  transform: scale(0.97);
}
.btn-ghost {
  border: 1px solid var(--gold-soft);
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--moon);
}
.btn-solid {
  border: 1px solid rgba(251, 233, 214, 0.25);
  background: linear-gradient(160deg, #c4391f, var(--seal) 60%, var(--seal-deep));
  color: #fbe9d6;
  box-shadow: 0 6px 20px rgba(178, 48, 31, 0.3);
}
.btn-wide {
  width: 100%;
  margin-top: 6px;
}

/* ------------------------------------------------------------ make-your-own sheet */
.sheet {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(2, 3, 8, 0.55);
  animation: fade 0.4s var(--ease) both;
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
.sheet-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  box-sizing: border-box;
  display: grid;
  gap: 12px;
  padding: 26px 20px calc(var(--safe-b) + 22px);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: linear-gradient(180deg, rgba(20, 26, 48, 0.94), rgba(8, 11, 22, 0.97));
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  animation: sheetUp 0.5s var(--ease) both;
}
@media (min-width: 700px) {
  .sheet {
    align-items: center;
  }
  .sheet-card {
    border-radius: 20px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 22px;
  }
}
@keyframes sheetUp {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}
.sheet-title {
  margin: 0;
  font-family: var(--brush);
  font-weight: 400;
  font-size: 26px;
  letter-spacing: 0.12em;
  color: var(--moon);
}
.sheet-sub {
  margin: -4px 0 6px;
  font-size: 13px;
  color: var(--moon-dim);
  letter-spacing: 0.06em;
}
.sheet-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}
.sheet-close svg {
  width: 20px;
  height: 20px;
  stroke: var(--moon-dim);
}
.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  letter-spacing: 0.12em;
  color: var(--gold);
}
.field input,
.linkbox input {
  width: 100%;
  box-sizing: border-box;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(4, 6, 13, 0.6);
  color: var(--moon);
  font-family: var(--serif);
  font-size: 16px;
  letter-spacing: 0.06em;
  -webkit-user-select: text;
  user-select: text;
}
.field input::placeholder {
  color: rgba(246, 238, 219, 0.3);
}
.field input:focus,
.linkbox input:focus {
  outline: none;
  border-color: var(--gold-soft);
  box-shadow: 0 0 0 3px var(--gold-faint);
}
.linkbox {
  display: grid;
  gap: 10px;
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.linkbox input {
  font-size: 13px;
  color: var(--moon-dim);
}
.linkbox .row {
  display: flex;
  gap: 10px;
}
.linkbox .row .btn {
  flex: 1;
}
.copy-msg {
  margin: 0;
  min-height: 1.2em;
  font-size: 13px;
  text-align: center;
  color: var(--gold);
}

/* ------------------------------------------------------------ fallback */
.nogl {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 0 16px;
  text-align: center;
  font-size: 16px;
  letter-spacing: 0.1em;
  background: radial-gradient(40% 30% at 50% 36%, #3a3326 0%, var(--night) 70%);
}

/* short landscape screens (phones on their side): moon on the left, invitation on the right */
@media (orientation: landscape) and (max-height: 560px) {
  .cover:not(.placed) {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr auto auto auto auto auto 1fr;
    column-gap: 4vw;
    padding: calc(var(--safe-t) + 3vh) 16px calc(var(--safe-b) + 3vh);
  }
  .cover-moon {
    grid-column: 1;
    grid-row: 1 / span 7;
    width: min(80vh, 340px);
  }
  .cover-kicker {
    grid-column: 2;
    grid-row: 2;
  }
  .cover-to {
    grid-column: 2;
    grid-row: 3;
    margin-top: 2vh;
  }
  .seal-btn {
    grid-column: 2;
    grid-row: 4;
    margin-top: 3vh;
  }
  .cover-tap {
    grid-column: 2;
    grid-row: 5;
  }
  .cover-hint {
    grid-column: 2;
    grid-row: 6;
  }
  .hud {
    padding-top: 10px;
    padding-bottom: calc(var(--safe-b) + 8px);
  }
}
.sheet-card {
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (prefers-reduced-motion: reduce) {
  .cover-moon .ring-inner,
  .seal-btn:not(:disabled) .seal-ring {
    animation: none;
  }
}
