:root {
  --ink: #3b2d2b;
  --paper: #f4ead5;
  --paper-deep: #e8d6b8;
  --gold: #d7ad69;
  --night: #100d16;
  --muted: #a8a1ad;
  --danger: #d55b45;
  --tilt-x: 0deg;
  --tilt-y: 0deg;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: #f7f2eb;
  background: radial-gradient(ellipse at 50% -10%, #30252b 0, #171317 34%, #09090b 72%, #050506 100%);
  font-family: "Noto Serif SC", "Songti SC", Georgia, serif;
  overflow-x: hidden;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.stars, .stars::before, .stars::after {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(235,218,185,.8) .7px, transparent .9px);
  background-size: 97px 97px;
  opacity: .18;
}
.stars::before, .stars::after { content: ""; transform: translate(31px, 47px); background-size: 173px 173px; opacity: .22; }
.stars::after { transform: translate(-19px, 9px); background-size: 251px 251px; opacity: .12; }
.aurora { position: fixed; inset: 0; background: radial-gradient(ellipse at 20% 15%, rgba(133,103,77,.12), transparent 34%), radial-gradient(ellipse at 82% 78%, rgba(78,79,63,.09), transparent 38%); pointer-events: none; }

.view { min-height: 100vh; position: relative; }
.center-view { display: grid; place-items: center; padding: 24px; }
.envelope-scene { text-align: center; }
.envelope-scene::before { content: ""; position: absolute; width: 430px; height: 430px; left: 50%; top: 35%; transform: translate(-50%, -50%); border-radius: 50%; background: radial-gradient(circle, rgba(107,34,31,.22), transparent 66%); filter: blur(20px); pointer-events: none; }
.envelope { position: relative; width: 310px; height: 204px; margin: 0 auto 34px; transform-style: preserve-3d; filter: drop-shadow(0 28px 30px rgba(0,0,0,.55)); }
.envelope-back, .envelope-flap { position: absolute; inset: 0; background: #5b3937; border-radius: 2px; }
.envelope-back { z-index: 3; }
.envelope-back { clip-path: polygon(0 0,100% 0,100% 100%,0 100%); }
.envelope-flap { clip-path: polygon(0 0,50% 58%,100% 0); background: #754544; transform-origin: top; transition: transform .85s cubic-bezier(.2,.8,.2,1); z-index: 4; }
.envelope-letter { position: absolute; z-index: 2; left: 25px; right: 25px; bottom: 5px; height: 142px; background: linear-gradient(90deg, rgba(128,83,45,.13), transparent 12%, transparent 88%, rgba(128,83,45,.11)), repeating-linear-gradient(0deg, rgba(113,78,51,.10) 0 1px, transparent 1px 26px), #eadbbf; transform: translateY(-28px) scaleY(.38); transform-origin: center bottom; opacity: 0; box-shadow: 0 1px 7px rgba(30,15,10,.28); }
.envelope-letter::after { content: "✦"; position: absolute; inset: 0; display: grid; place-items: center; color: rgba(128,83,45,.16); font-size: 42px; }
.envelope-seal { position: absolute; z-index: 5; left: 50%; top: 78px; transform: translateX(-50%); width: 57px; height: 57px; display: grid; place-items: center; border-radius: 48% 52% 50% 46%; background: radial-gradient(circle at 32% 28%, #d15b4c, #8b241f 68%, #591515); color: #f3d6a4; box-shadow: 0 6px 14px rgba(0,0,0,.38), inset 2px 2px 4px rgba(255,180,130,.22); transition: opacity .3s; font-size: 22px; }
.envelope.opening .envelope-flap { transform: rotateX(180deg); }
.envelope.opening .envelope-letter { opacity: 1; animation: letter-rise-unfold 1.45s cubic-bezier(.2,.8,.2,1) .82s both; }
.envelope.opening .envelope-seal { opacity: 0; }
.envelope-hint { color: var(--muted); }
.envelope-scene .primary { border-radius: 3px; padding: 12px 32px; letter-spacing: .14em; }
.question-progress { height: 4px; background: rgba(255,255,255,.1); border-radius: 4px; margin: 24px 0 4px; overflow: hidden; }
.question-progress i { display: block; width: 0; height: 100%; background: var(--gold); transition: width .35s; }
.glass { background: rgba(32, 25, 38, .72); border: 1px solid rgba(255,255,255,.12); box-shadow: 0 24px 80px rgba(0,0,0,.35); backdrop-filter: blur(18px); border-radius: 24px; }
.login-card, .consent-card, .questionnaire-card, .final-card { width: min(620px, 100%); padding: clamp(28px, 6vw, 58px); }
.questionnaire-card { width: min(760px, 100%); }
h1, h2, p { margin-top: 0; }
h1 { font-weight: 500; letter-spacing: .04em; }
.eyebrow { color: var(--gold); font: 600 11px/1.4 system-ui, sans-serif; letter-spacing: .28em; }
label { display: block; margin: 22px 0 9px; color: #d7ceda; font-size: 14px; }
input, textarea {
  width: 100%; border: 1px solid rgba(255,255,255,.16); border-radius: 12px; padding: 13px 15px;
  color: inherit; background: rgba(255,255,255,.065); outline: none; resize: vertical;
}
input:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(215,173,105,.12); }
button { border: 0; border-radius: 999px; padding: 12px 20px; transition: transform .2s, background .2s, opacity .2s; }
button:hover { transform: translateY(-1px); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.primary { margin-top: 22px; background: var(--gold); color: #241b20; font-weight: 700; }
.ghost { color: #f4edf5; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16); }
.small { padding: 8px 13px; font: 12px system-ui, sans-serif; white-space: nowrap; }
.button-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.fine-print, .status { color: var(--muted); font-size: 13px; margin-top: 18px; }
.error { min-height: 1.3em; color: #ff9988; margin: 12px 0 0; }
.question-block { margin-top: 30px; padding-top: 24px; border-top: 1px solid rgba(255,255,255,.09); }
.question-block legend { font-size: 18px; margin-bottom: 14px; }
.choices { display: grid; gap: 9px; }
.choice { display: flex; align-items: center; gap: 10px; margin: 0; padding: 12px 14px; border: 1px solid rgba(255,255,255,.1); border-radius: 12px; }
.choice input { width: auto; }

.letter-stage { padding: 110px 18px 330px; perspective: 1300px; }
.reader-toolbar { position: fixed; z-index: 20; top: 16px; left: 50%; transform: translateX(-50%); width: max-content; padding: 10px 18px; font: 12px system-ui, sans-serif; letter-spacing: .16em; color: #cdbca5; }
.progress-track { height: 4px; flex: 1; overflow: hidden; background: rgba(255,255,255,.12); border-radius: 4px; }
.progress-track i { display: block; width: 0; height: 100%; background: var(--gold); transition: width .2s; }
.letter-paper {
  position: relative; z-index: 2; width: min(760px, 100%); margin: 0 auto; padding: clamp(38px, 8vw, 86px);
  color: var(--ink); background: linear-gradient(90deg, rgba(163,115,61,.13), transparent 9%, transparent 91%, rgba(163,115,61,.12)), repeating-linear-gradient(0deg, rgba(124,87,53,.075) 0 1px, transparent 1px 34px), radial-gradient(circle at 20% 15%, rgba(255,255,255,.32), transparent 28%), #eadbbf;
  box-shadow: 0 50px 100px rgba(0,0,0,.48), inset 0 0 70px rgba(110,70,40,.08); border: 1px solid rgba(112,76,44,.28);
  transform: rotateX(var(--tilt-x)) rotateY(var(--tilt-y)); transform-style: preserve-3d; transition: transform .18s ease-out, opacity 1s;
}
.paper-grain { position: absolute; inset: 0; pointer-events: none; opacity: .16; background-image: repeating-linear-gradient(7deg, transparent 0 4px, rgba(84,51,30,.08) 5px); mix-blend-mode: multiply; }
.letter-paper::before { content: attr(data-watermark); position: absolute; top: 48%; left: 50%; transform: translate(-50%, -50%) rotate(-18deg); color: rgba(107,70,44,.055); font: 700 clamp(48px, 10vw, 88px) Georgia, serif; letter-spacing: .16em; pointer-events: none; white-space: nowrap; }
.letter-heading { padding-bottom: 34px; border-bottom: 1px solid rgba(78,51,38,.2); }
.letter-meta { display: flex; justify-content: space-between; gap: 12px; font: 800 clamp(18px, 3vw, 28px)/1.2 system-ui, sans-serif; letter-spacing: .12em; color: #765143; }
.letter-meta b { font-weight: 800; color: #62453a; }
.letter-heading h1 { display: none; }
.heading-line { display: flex; align-items: center; gap: 12px; margin-top: 23px; color: #a47a53; }
.heading-line i { height: 1px; flex: 1; background: linear-gradient(90deg, transparent, rgba(107,70,44,.45)); }
.heading-line i:last-child { background: linear-gradient(90deg, rgba(107,70,44,.45), transparent); }
.paper-corner { position: absolute; width: 80px; height: 80px; opacity: .5; border-color: #a9825e; border-style: solid; }
.corner-tl { top: 22px; left: 22px; border-width: 1px 0 0 1px; }
.corner-br { right: 22px; bottom: 22px; border-width: 0 1px 1px 0; }
.wax-seal { position: absolute; top: 34px; right: 42px; display: grid; place-items: center; width: 43px; height: 43px; border-radius: 50%; color: #f3d6a4; background: radial-gradient(circle at 35% 30%, #bd5545, #74251f 70%); box-shadow: 0 5px 12px rgba(80,28,23,.25); font-size: 19px; transform: rotate(12deg); }
.letter-section { padding: 58px 0 35px; border-bottom: 1px solid rgba(78,51,38,.15); }
.letter-section h2 { font-size: 25px; font-weight: 500; }
.letter-section p { font-size: clamp(17px, 2.5vw, 20px); line-height: 2; letter-spacing: .035em; }
.interaction { margin: 38px 0 10px; padding: 24px; border-radius: 4px; background: rgba(128,83,49,.08); }
.interaction p { font-size: 16px; line-height: 1.6; }
.interaction-options { display: flex; flex-wrap: wrap; gap: 9px; }
.interaction-options button { background: transparent; color: var(--ink); border: 1px solid rgba(59,45,43,.28); padding: 8px 14px; }
.interaction-options button.selected { color: #fff; background: #6c4b42; }
.signature { padding: 60px 0; text-align: right; font-size: 18px; }
.finish-panel { padding-top: 30px; }
.reply-open { margin: 15px 0 4px; padding: 0; color: #765144; background: transparent; border-bottom: 1px solid rgba(118,81,68,.45); border-radius: 0; }
.reply-open:hover { color: #9a5942; }
.finish-panel textarea { color: var(--ink); border-color: rgba(59,45,43,.24); background: rgba(255,255,255,.25); }
.finish-panel label, .finish-panel .status { color: #785f56; }
.letter-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 48px; }
.keep-button, .burn-button { width: 100%; color: #fff0df; }
.keep-button { background: linear-gradient(100deg, #68745c, #9a9d67); box-shadow: 0 12px 30px rgba(112,126,82,.2); }
.burn-button { color: #fff0df; background: linear-gradient(100deg, #5e241d, #ae4a27); box-shadow: 0 12px 30px rgba(118,42,26,.25); }
.fire-pot { position: fixed; z-index: 1; left: 50%; bottom: 20px; width: 250px; height: 190px; transform: translateX(-50%); opacity: .95; }
.pot { position: absolute; bottom: 0; width: 100%; height: 76px; border-radius: 12px 12px 80px 80px; background: linear-gradient(#392526, #160f12); box-shadow: 0 25px 50px #000; }
.fire-glow { position: absolute; inset: 18px -45px 20px; border-radius: 50%; background: radial-gradient(ellipse, rgba(255,99,38,.38), transparent 68%); filter: blur(18px); animation: glow 1.8s ease-in-out infinite alternate; }
.flames { position: absolute; left: 28px; right: 28px; bottom: 58px; height: 112px; filter: blur(.5px) drop-shadow(0 0 28px #ff5727); }
.flames i { position: absolute; bottom: 0; left: 25%; width: 48px; height: 90px; border-radius: 50% 10% 50% 50%; background: linear-gradient(#ffe15e, #f34b1b 70%); transform: rotate(40deg); animation: flame .7s ease-in-out infinite alternate; }
.flames i:nth-child(2) { left: 47%; height: 72px; animation-delay: -.32s; }
.flames i:nth-child(3) { left: 62%; width: 35px; height: 64px; animation-delay: -.5s; }
.flames i:nth-child(4) { left: 10%; width: 34px; height: 55px; animation-delay: -.18s; }
.flames i:nth-child(5) { left: 75%; width: 28px; height: 57px; animation-delay: -.4s; }
@keyframes flame { to { transform: rotate(25deg) scale(.82, 1.12); } }
@keyframes glow { to { opacity: .65; transform: scale(1.08); } }
@keyframes letter-rise-unfold {
  0% { z-index: 2; transform: translateY(-28px) scaleY(.38); }
  42% { z-index: 2; transform: translateY(-116px) scaleY(.38); }
  68% { z-index: 2; transform: translateY(-238px) scaleY(.38); }
  76% { z-index: 5; transform: translateY(-262px) scaleY(.38) rotate(-2deg); }
  88% { z-index: 5; transform: translateY(-158px) scaleY(.72) rotate(1deg); }
  100% { z-index: 5; transform: translateY(-84px) scaleY(1) rotate(0); }
}
.letter-paper.burning { animation: fall-into-fire 3.1s cubic-bezier(.55,.08,.8,.35) forwards; transform-origin: center bottom; }
.letter-paper.burning::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, #24100c, #c64a1f 4%, transparent 16%); animation: scorch 3s linear forwards; }
@keyframes fall-into-fire { 0% { transform: translateY(0) rotate(0); } 52% { transform: translateY(130px) rotate(2deg) scale(.87); } 100% { transform: translateY(calc(100vh + 500px)) rotate(-9deg) scale(.35); opacity: .15; } }
@keyframes scorch { from { background-position-y: 1000px; } to { background-position-y: 0; } }
.ashes { position: absolute; inset: 0; background: radial-gradient(ellipse at bottom, rgba(198,95,51,.16), transparent 45%); }

#toast { position: fixed; z-index: 100; left: 50%; bottom: 24px; transform: translate(-50%, 20px); padding: 11px 18px; border-radius: 10px; background: #ece2d0; color: #2e2224; opacity: 0; pointer-events: none; transition: .25s; font: 14px system-ui, sans-serif; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.admin-body { background: #121018; color: #eee8ef; font-family: system-ui, sans-serif; }
.admin-dashboard { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 42px 0 90px; }
.admin-header, .panel-heading { display: flex; justify-content: space-between; gap: 20px; align-items: center; }
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 24px 0; }
.summary-card, .admin-panel { background: #1c1822; border: 1px solid rgba(255,255,255,.08); border-radius: 16px; }
.summary-card { padding: 20px; }
.summary-card strong { display: block; margin-top: 8px; font-size: 26px; color: #f1c27b; }
.admin-panel { padding: 24px; margin: 16px 0; }
.admin-panel h2 { margin-bottom: 16px; }
.admin-panel p { color: #aaa2ad; }
.data-list { display: grid; gap: 10px; }
.data-item { padding: 14px; background: rgba(255,255,255,.035); border-radius: 10px; white-space: pre-wrap; }
.data-item b { color: #d9b77e; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px; border-bottom: 1px solid rgba(255,255,255,.07); text-align: left; white-space: nowrap; }
th { color: #b8aebe; font-size: 12px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.media-card { overflow: hidden; background: #100e14; border-radius: 12px; }
.media-card img, .media-card video { display: block; width: 100%; aspect-ratio: 4/3; object-fit: cover; background: #08070a; }
.media-card p { padding: 10px; margin: 0; font-size: 12px; }
.reply-view { white-space: pre-wrap; line-height: 1.75; }
.config-editor { min-height: 360px; margin-top: 18px; color: #e9d9c5; background: #110f15; border-color: rgba(215,173,105,.25); font: 13px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; }
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.editor-field { display: grid; gap: 7px; margin: 0; color: #c8b9c8; font-size: 12px; }
.editor-field.wide { grid-column: 1 / -1; }
.editor-field input, .editor-field textarea { margin: 0; color: #f0e7ef; background: #121017; border-color: rgba(255,255,255,.12); }
.visual-card { display: grid; gap: 12px; margin: 12px 0; padding: 16px; border: 1px solid rgba(255,255,255,.08); background: rgba(255,255,255,.025); border-radius: 8px; }
.editor-panel h3 { margin: 22px 0 8px; color: #e1bd81; font-size: 14px; }
@media (max-width: 700px) { .editor-grid { grid-template-columns: 1fr; } .editor-field.wide { grid-column: auto; } }
.danger-outline { color: #ff9b88; background: transparent; border: 1px solid rgba(255,120,100,.4); }
.switch input { display: none; }
.switch span { display: block; width: 48px; height: 27px; border-radius: 20px; background: #39343e; padding: 3px; transition: .2s; }
.switch span::after { content: ""; display: block; width: 21px; height: 21px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: #b47739; }
.switch input:checked + span::after { transform: translateX(21px); }

@media (max-width: 700px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .letter-stage { padding-inline: 10px; }
  .letter-paper { padding: 42px 26px; }
  .letter-meta { flex-direction: column; letter-spacing: .14em; }
  .wax-seal { top: 24px; right: 24px; transform: scale(.8) rotate(12deg); }
  .reader-toolbar .progress-track { min-width: 50px; }
  .admin-header, .panel-heading { align-items: flex-start; flex-direction: column; }
  .letter-choice { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

.editor-section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 26px 0 10px; }
.editor-section-title h3 { margin: 0; color: #e1bd81; font-size: 14px; }
.visual-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.visual-card-head b { color: #d9b77e; font-size: 13px; }
.editor-toggle { display: flex; align-items: center; gap: 10px; margin-top: 14px; color: #c8b9c8; font-size: 13px; }
.editor-toggle input { width: auto; }
.editor-field input, .editor-field textarea { font: 14px system-ui, sans-serif; }
.danger-outline.small, .ghost.small { padding: 6px 12px; font-size: 12px; }
@media (max-width: 700px) { .editor-grid { grid-template-columns: 1fr; } .editor-field.wide { grid-column: auto; } }
