:root {
  color-scheme: dark;
  --ink: #fffaf3;
  --muted: #c8bdaf;
  --surface: #251f2c;
  --surface-strong: #302738;
  --line: #4a3d4e;
  --plum: #a9769d;
  --peach: #e8a77f;
  --gold: #f2ca7c;
  --ok: #8ed7b4;
  --bad: #ff9a9a;
  --shadow: 0 24px 70px #09060c55;
}

* { box-sizing: border-box; }
html { background: #120f16; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "SF Pro Text", "PingFang TC", sans-serif;
  background:
    radial-gradient(circle at 12% 2%, #57384a 0, transparent 30rem),
    radial-gradient(circle at 88% 22%, #3c2c4a 0, transparent 34rem),
    #120f16;
}
button, input { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.shell { width: min(1120px, calc(100% - 32px)); margin-inline: auto; }

.site-head { display: flex; align-items: center; justify-content: space-between; min-height: 82px; gap: 18px; }
.brand { display: flex; gap: 11px; align-items: center; color: var(--ink); text-decoration: none; font-weight: 850; letter-spacing: -.03em; font-size: 21px; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 14px; background: linear-gradient(145deg, var(--peach), var(--plum)); box-shadow: 0 10px 24px #0005; }
.public-nav, .app-nav, .app-shell-nav, .app-meta { display: flex; align-items: center; gap: 6px; }
.quiet-link, .nav-item, .text-button { color: var(--muted); text-decoration: none; padding: 10px 12px; border: 0; border-radius: 999px; background: transparent; }
.quiet-link:hover, .nav-item:hover, .text-button:hover, .quiet-link:focus-visible, .nav-item:focus-visible, .text-button:focus-visible { color: var(--ink); background: #ffffff0c; }
.nav-item.active { color: var(--ink); background: #ffffff12; }
.credit-badge { padding: 8px 12px; border: 1px solid #8d6689; border-radius: 999px; color: var(--muted); white-space: nowrap; }
.credit-badge b { color: var(--gold); }

.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, .72fr); gap: 48px; align-items: center; min-height: 570px; padding: 48px 0; }
.eyebrow { color: var(--gold); font-size: 12px; font-weight: 850; letter-spacing: .13em; text-transform: uppercase; }
.hero h1, .workspace h1 { margin: 14px 0 18px; font-size: clamp(46px, 7vw, 78px); line-height: .96; letter-spacing: -.065em; }
.hero h1 { max-width: 10ch; }
.hero-message > p { max-width: 47ch; margin: 0 0 28px; color: var(--muted); font-size: 19px; }
.hero-action { display: inline-grid; place-items: center; width: fit-content; text-decoration: none; }
.keepsake { display: grid; place-items: center; min-height: 430px; }
.story-card { position: relative; display: flex; flex-direction: column; justify-content: flex-end; width: min(350px, 88vw); aspect-ratio: 4 / 5; padding: 30px; overflow: hidden; border-radius: 34px; background: linear-gradient(160deg, #c98672, #815a7d 52%, #3e2c56); box-shadow: var(--shadow); transform: rotate(2deg); }
.story-card::before { position: absolute; top: -60px; left: -70px; width: 250px; height: 250px; border-radius: 50%; background: #ffd4a240; content: ""; }
.story-card::after { position: absolute; inset: 14px; border: 1px solid #fff5; border-radius: 25px; content: ""; }
.story-card .moon { position: absolute; top: 46px; right: 36px; font-size: 72px; }
.story-card strong { z-index: 1; font-size: 34px; line-height: 1.05; letter-spacing: -.04em; }
.story-card span:last-child { z-index: 1; margin-top: 9px; color: #fff9; }

.how { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; align-items: center; gap: 16px; padding: 18px; border-block: 1px solid var(--line); }
.how > div { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 54px; }
.how span { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: #ffffff10; color: var(--gold); font-weight: 850; }
.how i { color: #8f8392; font-style: normal; }
.auth-wrap { padding: 54px 0 96px; }
.panel { min-width: 0; padding: clamp(24px, 5vw, 44px); border: 1px solid var(--line); border-radius: 28px; background: linear-gradient(145deg, #292230ed, #1b171fed); box-shadow: var(--shadow); }
.auth-panel { width: min(720px, 100%); margin-inline: auto; }
.step-heading, .view-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.step-heading h2, .view-heading h1, .workspace h2 { margin: 5px 0 8px; font-size: clamp(28px, 4vw, 44px); line-height: 1.05; letter-spacing: -.045em; }
.step-heading p, .view-heading p { margin: 0; color: var(--muted); }
.step-count { display: grid; flex: 0 0 auto; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: #ffffff10; color: var(--gold); font-weight: 850; }
.form-row { display: flex; gap: 10px; margin-top: 24px; }
.field, .search input { width: 100%; min-height: 52px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 15px; outline: none; background: #110e14; color: var(--ink); }
.field:focus, .search input:focus { border-color: var(--peach); box-shadow: 0 0 0 4px #e8a77f20; }
.policy-check { display: grid; grid-template-columns: 22px 1fr; gap: 10px; align-items: start; margin-top: 16px; color: var(--muted); font-size: 14px; }
.policy-check input { width: 20px; height: 20px; accent-color: var(--peach); }
.policy-check a { color: var(--gold); }
.primary, .secondary { min-height: 50px; padding: 13px 18px; border-radius: 15px; font-weight: 850; transition: transform 160ms ease, filter 160ms ease, background 160ms ease; }
.primary { border: 0; background: linear-gradient(135deg, var(--peach), #d68db2); color: #251823; }
.secondary { border: 1px solid var(--line); background: #ffffff0b; color: var(--ink); }
.primary:hover, .secondary:hover { filter: brightness(1.07); transform: translateY(-1px); }
.primary:active, .secondary:active { transform: scale(.99); }
.primary:focus-visible, .secondary:focus-visible, .nav-item:focus-visible, .text-button:focus-visible { outline: 3px solid #f5d196; outline-offset: 3px; }
.primary:disabled, .secondary:disabled { cursor: not-allowed; opacity: .45; transform: none; }
.status { min-height: 24px; margin-top: 12px; color: var(--ok); }
.status.error { color: var(--bad); }
.dev-link { display: inline-block; margin-top: 9px; color: var(--gold); }

.session-loading { padding-top: 50px; }
.skeleton { overflow: hidden; border-radius: 24px; background: #ffffff0b; }
.skeleton::after { display: block; width: 40%; height: 100%; background: linear-gradient(90deg, transparent, #ffffff12, transparent); animation: shimmer 1.5s infinite; content: ""; }
.skeleton-hero { width: 70%; height: 110px; }
.skeleton-panel { height: 360px; margin-top: 30px; }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

.workspace { padding: 42px 0 90px; }
.workspace h1 { max-width: 13ch; font-size: clamp(42px, 6vw, 68px); }
.workspace-view { animation: enter 180ms ease both; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.view-heading { align-items: end; margin-bottom: 30px; }
.library-tools { display: grid; justify-items: end; gap: 10px; }
.segmented { display: flex; padding: 4px; border: 1px solid var(--line); border-radius: 999px; background: #ffffff08; }
.segmented button { min-height: 40px; padding: 7px 15px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); }
.segmented button.active { background: #fffaf3; color: #241923; }
.search { width: min(300px, 100%); }
.story-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.library-card { display: grid; grid-template-rows: 190px 1fr auto; min-height: 390px; overflow: hidden; border: 1px solid var(--line); border-radius: 24px; background: #211b28; transition: transform 180ms ease, border-color 180ms ease; }
.library-card:hover { border-color: #8d6689; transform: translateY(-2px); }
.cover-art { position: relative; display: grid; place-items: center; overflow: hidden; font-size: 62px; }
.cover-art::before, .cover-art::after { position: absolute; border-radius: 50%; background: #fff2; content: ""; }
.cover-art::before { top: -35px; left: -20px; width: 150px; height: 150px; }
.cover-art::after { right: -20px; bottom: -55px; width: 190px; height: 190px; }
.cover-peach { background: linear-gradient(145deg, #b87872, #70415f); }
.cover-plum { background: linear-gradient(145deg, #8c6a99, #463852); }
.cover-moon { background: linear-gradient(145deg, #4f557d, #262b49); }
.cover-sage { background: linear-gradient(145deg, #67847b, #304a49); }
.cover-amber { background: linear-gradient(145deg, #b58450, #624538); }
.cover-blue { background: linear-gradient(145deg, #587899, #313e63); }
.library-card-body { padding: 20px 20px 12px; }
.library-card h2 { margin: 0 0 8px; font-size: 22px; }
.library-card p { display: -webkit-box; margin: 0; overflow: hidden; color: var(--muted); -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 16px; color: #a99dac; font-size: 13px; }
.library-card .story-action { margin: 0 20px 20px; }
.generation-list { display: grid; gap: 12px; }
.generation-card { display: grid; grid-template-columns: 58px 1fr auto; align-items: center; gap: 16px; min-height: 92px; padding: 16px; border: 1px solid var(--line); border-radius: 20px; background: #211b28; }
.generation-card .mini-cover { width: 58px; height: 58px; }
.generation-card h2 { margin: 0; font-size: 19px; }
.generation-card p { margin: 3px 0 0; color: var(--muted); }
.generation-card audio { width: min(300px, 34vw); }
.empty-state { display: grid; justify-items: center; min-height: 330px; align-content: center; text-align: center; color: var(--muted); }
.empty-state > span { font-size: 55px; color: var(--gold); }
.empty-state h2 { margin: 12px 0 2px; color: var(--ink); }
.empty-state p { margin: 0; }

.invite-card { display: grid; grid-template-columns: 170px 1fr; align-items: center; gap: 32px; padding: clamp(25px, 5vw, 50px); border: 1px solid #8d6689; border-radius: 28px; background: linear-gradient(145deg, #47334c, #2a2134); }
.reward-ring { display: grid; place-items: center; align-content: center; width: 160px; aspect-ratio: 1; border: 12px solid #ffffff12; border-top-color: var(--gold); border-radius: 50%; }
.reward-ring b { font-size: 48px; line-height: 1; }
.reward-ring span { color: var(--muted); font-size: 13px; }
.reward-ring small { margin-top: 5px; color: var(--gold); font-size: 11px; font-weight: 800; }
.invite-card h2 { margin-top: 0; }
.invite-card p { max-width: 52ch; color: var(--muted); }
.invite-actions, .account-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 18px; }
.stat-grid > div { display: grid; min-height: 130px; place-items: center; align-content: center; border: 1px solid var(--line); border-radius: 22px; background: #211b28; }
.stat-grid b { font-size: 38px; }
.stat-grid span { color: var(--muted); }
.settings-list { overflow: hidden; border: 1px solid var(--line); border-radius: 22px; }
.settings-list > div { display: flex; justify-content: space-between; gap: 20px; padding: 20px; background: #211b28; }
.settings-list > div + div { border-top: 1px solid var(--line); }
.settings-list span { color: var(--muted); }
.account-download { display: inline-grid; place-items: center; text-decoration: none; }
.secondary.danger { border-color: #ff9a9a66; color: #ffc1c1; }

.footer { display: flex; justify-content: space-between; gap: 18px; padding: 28px 0 45px; border-top: 1px solid var(--line); color: var(--muted); }
.toast { position: fixed; z-index: 20; bottom: 24px; left: 50%; padding: 13px 18px; border-radius: 999px; opacity: 0; background: #f8eee3; color: #241923; box-shadow: var(--shadow); pointer-events: none; transform: translate(-50%, 20px); transition: opacity 180ms, transform 180ms; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.confirm-dialog { width: min(440px, calc(100% - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 24px; background: linear-gradient(145deg, #302638, #1b171f); color: var(--ink); box-shadow: var(--shadow); }
.confirm-dialog::backdrop { background: #09060ccc; backdrop-filter: blur(7px); }
.confirm-dialog form { padding: 28px; }
.confirm-dialog h2 { margin-top: 0; }
.confirm-dialog p { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.danger-action { background: linear-gradient(135deg, #f19a8f, #d97a92); }

@media (max-width: 850px) {
  .nav-item { white-space: nowrap; }
  .app-shell-nav { min-width: 0; }
  .hero { grid-template-columns: 1fr; min-height: auto; padding-top: 36px; }
  .keepsake { min-height: 330px; }
  .story-card { width: 250px; }
  .story-card strong { font-size: 25px; }
  .story-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .view-heading { display: grid; }
  .library-tools { justify-items: stretch; }
  .search { width: 100%; }
}

@media (max-width: 600px) {
  .shell { width: min(100% - 22px, 540px); }
  .site-head { min-height: 66px; flex-wrap: wrap; }
  .public-nav .quiet-link:first-child { display: none; }
  .app-shell-nav { display: grid; width: 100%; order: 3; gap: 8px; }
  .app-nav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); width: 100%; }
  .app-nav .nav-item { min-width: 0; padding-inline: 6px; font-size: 14px; text-align: center; }
  .app-meta { justify-content: flex-end; }
  .app-meta .nav-item { min-height: 44px; }
  .brand { font-size: 19px; }
  .hero h1 { font-size: 50px; }
  .hero { gap: 16px; }
  .keepsake { min-height: 290px; }
  .how { grid-template-columns: 1fr 1fr 1fr; gap: 5px; }
  .how i { display: none; }
  .how > div { display: grid; justify-items: center; gap: 4px; font-size: 14px; }
  .form-row { display: grid; }
  .primary, .secondary { width: 100%; }
  .story-grid { grid-template-columns: 1fr; }
  .library-card { grid-template-columns: 110px 1fr; grid-template-rows: 1fr auto; min-height: 180px; }
  .library-card .cover-art { grid-row: 1 / 3; font-size: 40px; }
  .library-card .story-action { grid-column: 2; margin: 0 16px 16px; }
  .library-card-body { padding: 16px; }
  .generation-card { grid-template-columns: 48px 1fr; }
  .generation-card audio, .generation-card > button { grid-column: 1 / -1; width: 100%; }
  .invite-card { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .invite-actions { display: grid; }
  .stat-grid { gap: 7px; }
  .stat-grid > div { min-height: 100px; }
  .stat-grid b { font-size: 30px; }
  .footer { display: grid; }
  .dialog-actions { display: grid; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
  .story-card, .library-card:hover { transform: none; }
}
