:root {
    --navy-deep: #060a18;
    --navy-bg: #0b1330;
    --navy-panel: #101a3d;
    --navy-panel-2: #16214a;
    --navy-line: #263266;
    --gold: #c9a769;
    --gold-soft: #e3cfa0;
    --rose: #d99aa6;
    --ink: #eef1fb;
    --ink-muted: #97a1c9;
    --ink-faint: #5f6a97;
    --ok: #7fb99a;
    --bad: #cf7d7d;
    --radius: 2px;
    --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  }

  :root:not([data-theme="light"]) {
    color-scheme: dark;
  }

  @media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
      --navy-deep: #060a18;
      --navy-bg: #0b1330;
    }
  }

  * { box-sizing: border-box; }

  html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
  }

  body {
    background: radial-gradient(ellipse 140% 90% at 50% -10%, #1a2456 0%, var(--navy-bg) 45%, var(--navy-deep) 100%);
    color: var(--ink);
    font-family: var(--sans);
    -webkit-font-smoothing: antialiased;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 32px 18px 56px;
    overflow-x: hidden;
  }

  .stars {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
      radial-gradient(1px 1px at 12% 18%, rgba(238,241,251,.5) 0, transparent 100%),
      radial-gradient(1px 1px at 78% 8%, rgba(238,241,251,.35) 0, transparent 100%),
      radial-gradient(1.5px 1.5px at 34% 62%, rgba(201,167,105,.4) 0, transparent 100%),
      radial-gradient(1px 1px at 88% 42%, rgba(238,241,251,.3) 0, transparent 100%),
      radial-gradient(1px 1px at 6% 78%, rgba(238,241,251,.3) 0, transparent 100%),
      radial-gradient(1.5px 1.5px at 62% 88%, rgba(201,167,105,.3) 0, transparent 100%),
      radial-gradient(1px 1px at 95% 75%, rgba(238,241,251,.35) 0, transparent 100%);
    background-size: 100% 100%;
    opacity: .8;
    z-index: 0;
  }

  .stage {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 460px;
  }

  /* ---------- header thread ---------- */
  .thread {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 30px;
    color: var(--ink-faint);
    font-size: 12px;
    letter-spacing: .04em;
  }
  .thread .rule { width: 26px; height: 1px; background: var(--navy-line); }

  /* ---------- panel ---------- */
  .panel {
    background: linear-gradient(175deg, var(--navy-panel-2), var(--navy-panel));
    border: 1px solid var(--navy-line);
    border-radius: var(--radius);
    padding: 40px 30px 32px;
    position: relative;
    box-shadow: 0 30px 60px -25px rgba(0,0,0,.6);
  }
  .panel::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold) 50%, transparent);
    opacity: .6;
  }

  /* ---------- screens ---------- */
  .screen { display: none; }
  .screen.active { display: block; animation: rise .5s ease both; }
  @keyframes rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
  }
  @media (prefers-reduced-motion: reduce) {
    .screen.active { animation: none; }
  }

  /* ---------- cover ---------- */
  .cover-mark {
    text-align: center;
    font-size: 26px;
    margin-bottom: 18px;
    letter-spacing: .3em;
    color: var(--gold);
  }
  .cover h1 {
    font-family: var(--serif);
    font-weight: 500;
    font-style: italic;
    font-size: 40px;
    line-height: 1.15;
    text-align: center;
    margin: 0 0 6px;
    color: var(--ink);
  }
  .cover .for-line {
    text-align: center;
    font-size: 13px;
    color: var(--ink-faint);
    margin-bottom: 22px;
  }
  .cover .name {
    text-align: center;
    font-family: var(--serif);
    font-size: 25px;
    color: var(--gold-soft);
    margin: 0 0 28px;
    letter-spacing: .01em;
  }
  .cover p.lede {
    font-size: 14.5px;
    line-height: 1.75;
    color: var(--ink-muted);
    text-align: center;
    margin: 0 0 30px;
    padding: 0 4px;
  }
  .stat-row {
    display: flex;
    justify-content: center;
    gap: 26px;
    margin-bottom: 30px;
  }
  .stat { text-align: center; }
  .stat b {
    display: block;
    font-family: var(--serif);
    font-size: 22px;
    color: var(--gold-soft);
  }
  .stat span {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--ink-faint);
  }

  /* ---------- buttons ---------- */
  .btn {
    display: block;
    width: 100%;
    text-align: center;
    background: var(--gold);
    color: #1a1206;
    font-family: var(--sans);
    font-weight: 600;
    font-size: 14.5px;
    letter-spacing: .01em;
    border: none;
    border-radius: var(--radius);
    padding: 15px 20px;
    cursor: pointer;
    transition: transform .15s ease, background .2s ease;
  }
  .btn:hover { background: var(--gold-soft); }
  .btn:active { transform: scale(.98); }
  .btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
  .btn[disabled] { opacity: .35; cursor: not-allowed; }

  .btn-ghost {
    background: transparent;
    color: var(--ink-muted);
    border: 1px solid var(--navy-line);
  }
  .btn-ghost:hover { background: rgba(255,255,255,.03); color: var(--ink); }

  /* ---------- quiz header ---------- */
  .qmeta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 14px;
  }
  .qmeta .count {
    font-family: var(--serif);
    font-style: italic;
    color: var(--gold-soft);
    font-size: 15px;
  }
  .qmeta .count b { color: var(--gold); font-style: normal; }
  .qmeta .tag {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--ink-faint);
  }

  .progress-track {
    height: 3px;
    width: 100%;
    background: var(--navy-line);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 26px;
  }
  .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--rose), var(--gold));
    width: 0%;
    transition: width .4s ease;
  }

  .qtext {
    font-family: var(--serif);
    font-size: 23px;
    line-height: 1.4;
    color: var(--ink);
    margin: 0 0 24px;
    min-height: 64px;
  }

  .options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 22px; }
  .opt {
    text-align: left;
    background: rgba(255,255,255,.02);
    border: 1px solid var(--navy-line);
    color: var(--ink-muted);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.5;
    padding: 13px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    transition: border-color .15s ease, background .15s ease, color .15s ease;
  }
  .opt .k {
    font-family: var(--serif);
    font-style: italic;
    color: var(--ink-faint);
    flex-shrink: 0;
  }
  .opt:hover:not([disabled]) { border-color: var(--gold); color: var(--ink); }
  .opt:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
  .opt[disabled] { cursor: default; }
  .opt.correct { border-color: var(--ok); background: rgba(127,185,154,.1); color: var(--ink); }
  .opt.correct .k { color: var(--ok); }
  .opt.wrong { border-color: var(--bad); background: rgba(207,125,125,.08); color: var(--ink-muted); }

  .feedback {
    font-size: 12.5px;
    color: var(--ink-faint);
    min-height: 18px;
    margin-bottom: 16px;
    letter-spacing: .01em;
  }
  .feedback.show-ok { color: var(--ok); }
  .feedback.show-bad { color: var(--bad); }

  /* ---------- results ---------- */
  .score-wrap { text-align: center; margin-bottom: 22px; }
  .score-wrap .n {
    font-family: var(--serif);
    font-size: 58px;
    color: var(--gold-soft);
    line-height: 1;
  }
  .score-wrap .of { font-size: 13px; color: var(--ink-faint); margin-top: 6px; }
  .verdict {
    font-family: var(--serif);
    font-style: italic;
    font-size: 19px;
    text-align: center;
    color: var(--ink);
    margin: 0 0 18px;
  }
  .note {
    font-size: 14px;
    line-height: 1.8;
    color: var(--ink-muted);
    text-align: center;
    margin: 0 0 28px;
    padding: 0 4px;
  }
  .sign {
    text-align: center;
    font-family: var(--serif);
    font-style: italic;
    color: var(--gold);
    font-size: 15px;
    margin-bottom: 28px;
  }

  .divider { height: 1px; background: var(--navy-line); margin: 26px 0; }

  footer {
    text-align: center;
    margin-top: 22px;
    font-size: 11px;
    color: var(--ink-faint);
    letter-spacing: .04em;
  }

  /* ---------- gift / envelope ---------- */
  .gift-intro { text-align: center; }
  .envelope-wrap {
    display: flex;
    justify-content: center;
    margin: 6px 0 26px;
  }
  .envelope {
    position: relative;
    width: 168px;
    height: 112px;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
  }
  .env-body {
    position: absolute;
    inset: 0;
    background: linear-gradient(160deg, #1a2554, #101a3d);
    border: 1px solid var(--navy-line);
    border-radius: 3px;
  }
  .env-flap {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 60px;
    background: linear-gradient(160deg, #202c60, #16214a);
    clip-path: polygon(0 0, 100% 0, 50% 62%);
    border-bottom: 1px solid var(--navy-line);
    transform-origin: top center;
    transition: transform .55s cubic-bezier(.6,-0.1,.3,1.4);
  }
  .envelope.open .env-flap { transform: rotateX(180deg); }
  .env-seal {
    position: absolute;
    top: 38px; left: 50%;
    transform: translate(-50%, 0);
    width: 30px; height: 30px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, var(--gold-soft), var(--gold) 70%);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px;
    box-shadow: 0 3px 8px rgba(0,0,0,.4);
    transition: opacity .25s ease .1s, transform .25s ease .1s;
    z-index: 2;
  }
  .envelope.open .env-seal { opacity: 0; transform: translate(-50%,0) scale(.4); }
  .env-hint {
    text-align: center;
    font-size: 11.5px;
    color: var(--ink-faint);
    letter-spacing: .04em;
    margin-bottom: 4px;
  }

  .letter {
    max-height: 0;
    overflow: hidden;
    transition: max-height .6s ease;
  }
  .letter.open { max-height: 3200px; }
  .letter-inner { padding-top: 6px; }

  .letter-head {
    text-align: center;
    margin-bottom: 22px;
  }
  .letter-head .k { font-size: 22px; margin-bottom: 8px; }
  .letter-head h2 {
    font-family: var(--serif);
    font-style: italic;
    font-weight: 500;
    font-size: 24px;
    margin: 0 0 6px;
    color: var(--ink);
  }
  .letter-head p {
    font-size: 12.5px;
    color: var(--ink-faint);
    margin: 0;
  }

  .timeline { position: relative; padding-left: 22px; margin-bottom: 26px; }
  .timeline::before {
    content: "";
    position: absolute;
    left: 5px; top: 4px; bottom: 4px;
    width: 1px;
    background: linear-gradient(var(--gold), var(--navy-line) 85%);
  }
  .tl-item { position: relative; padding-bottom: 22px; }
  .tl-item:last-child { padding-bottom: 0; }
  .tl-item::before {
    content: "";
    position: absolute;
    left: -22px; top: 5px;
    width: 9px; height: 9px;
    border-radius: 50%;
    background: var(--navy-bg);
    border: 1.5px solid var(--gold);
  }
  .tl-date {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--gold-soft);
    margin-bottom: 5px;
  }
  .tl-quote {
    font-family: var(--serif);
    font-style: italic;
    font-size: 17px;
    line-height: 1.5;
    color: var(--ink);
    margin: 0 0 5px;
  }
  .tl-note {
    font-size: 12.5px;
    color: var(--ink-muted);
    line-height: 1.6;
    margin: 0;
  }

  .letter-close {
    text-align: center;
    padding: 20px 6px 2px;
    border-top: 1px solid var(--navy-line);
    margin-top: 6px;
  }
  .letter-close p {
    font-size: 14px;
    line-height: 1.85;
    color: var(--ink-muted);
    margin: 0 0 16px;
  }

  .chat-link {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    background: rgba(201,167,105,.06);
    border: 1px solid var(--navy-line);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 28px;
    transition: border-color .15s ease, background .15s ease;
  }
  .chat-link:hover { border-color: var(--gold); background: rgba(201,167,105,.1); }
  .chat-link .ic {
    font-size: 20px;
    flex-shrink: 0;
  }
  .chat-link .tx { flex: 1; min-width: 0; }
  .chat-link .tx b {
    display: block;
    font-family: var(--serif);
    font-style: italic;
    font-size: 15.5px;
    color: var(--ink);
    font-weight: 500;
  }
  .chat-link .tx span {
    display: block;
    font-size: 11.5px;
    color: var(--ink-faint);
    margin-top: 2px;
  }
  .chat-link .arrow {
    color: var(--gold);
    font-size: 16px;
    flex-shrink: 0;
  }
