:root {
  color-scheme: dark;
  --ink: #f7f4ed;
  --muted: #a9acc4;
  --night: #090c1c;
  --night-soft: #11152e;
  --panel: rgba(24, 28, 59, 0.86);
  --panel-strong: #191e3e;
  --line: rgba(255, 255, 255, 0.1);
  --gold: #f5c86a;
  --gold-deep: #dca849;
  --lavender: #a99bf7;
  --mint: #78d7b0;
  --danger: #ff9d9d;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--night); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 78% 10%, rgba(101, 84, 181, 0.22), transparent 30rem),
    radial-gradient(circle at 15% 45%, rgba(30, 91, 111, 0.14), transparent 32rem),
    linear-gradient(160deg, #0b0e20 0%, #111630 52%, #090c1c 100%);
  overflow-x: hidden;
}

button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button { color: inherit; }

.sky { position: fixed; inset: 0; pointer-events: none; overflow: hidden; opacity: 0.8; }
.star { position: absolute; width: 3px; height: 3px; border-radius: 50%; background: #fff8d7; box-shadow: 0 0 11px #fff0a4; animation: twinkle 3.5s ease-in-out infinite; }
.star-one { top: 13%; left: 8%; }
.star-two { top: 7%; left: 56%; animation-delay: -1.4s; }
.star-three { top: 32%; right: 7%; animation-delay: -2.1s; }
.star-four { top: 61%; left: 3%; animation-delay: -0.7s; }

.topbar {
  position: relative;
  z-index: 2;
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(245, 200, 106, 0.4);
  border-radius: 50% 50% 44% 56%;
  color: #211b2d;
  background: linear-gradient(145deg, #fff0b4, var(--gold));
  box-shadow: 0 8px 24px rgba(245, 200, 106, 0.2);
  font-family: Georgia, serif;
  font-size: 19px;
  font-weight: 700;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; letter-spacing: 0.08em; }
.brand small { margin-top: 3px; color: var(--muted); font-size: 11px; letter-spacing: 0.04em; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.status { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.status i { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 9px currentColor; }
.status-ready { color: var(--mint); }
.status-error { color: var(--danger); }
.status-checking i { animation: pulse 1.2s ease-in-out infinite; }
.quiet-button { padding: 9px 13px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 255, 255, 0.04); font-size: 12px; }
.quiet-button:hover { border-color: rgba(245, 200, 106, 0.35); background: rgba(245, 200, 106, 0.08); }

main { position: relative; z-index: 1; width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding-bottom: 80px; }
.hero { min-height: 390px; display: grid; grid-template-columns: 1.15fr 0.85fr; align-items: center; gap: 60px; padding: 34px 32px 36px; }
.eyebrow { margin: 0 0 17px; color: var(--gold); font-size: 12px; font-weight: 700; letter-spacing: 0.25em; }
.hero h1 { margin: 0; max-width: 760px; font-family: Georgia, "STSong", serif; font-size: clamp(42px, 5vw, 70px); font-weight: 500; line-height: 1.14; letter-spacing: -0.04em; }
.hero h1 em { color: var(--gold); font-style: normal; }
.hero-text { max-width: 650px; margin: 24px 0 0; color: #c4c5d5; font-size: 16px; line-height: 1.9; }
.privacy-note { display: inline-flex; align-items: center; gap: 8px; margin-top: 23px; padding: 9px 13px; border: 1px solid rgba(120, 215, 176, 0.16); border-radius: 999px; color: #a9d8c3; background: rgba(120, 215, 176, 0.06); font-size: 11px; }
.privacy-note span { color: var(--mint); font-size: 16px; }

.moon-scene { position: relative; min-height: 320px; }
.moon {
  position: absolute;
  top: 12px;
  right: 15%;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 29%, #fffbe7, #f6d987 62%, #d5a843 100%);
  box-shadow: 0 0 50px rgba(246, 217, 135, 0.22), 0 0 140px rgba(246, 217, 135, 0.11);
}
.moon span, .moon::before, .moon::after { content: ""; position: absolute; border-radius: 50%; background: rgba(190, 148, 67, 0.16); }
.moon span { width: 24px; height: 24px; top: 35px; left: 44px; }
.moon::before { width: 42px; height: 42px; right: 34px; top: 67px; }
.moon::after { width: 18px; height: 18px; left: 70px; bottom: 30px; }
.cloud { position: absolute; height: 35px; border-radius: 40px; background: #20264c; filter: drop-shadow(0 15px 20px rgba(0, 0, 0, 0.18)); }
.cloud::before, .cloud::after { content: ""; position: absolute; bottom: 0; border-radius: 50%; background: inherit; }
.cloud::before { width: 60px; height: 60px; left: 30px; }
.cloud::after { width: 42px; height: 42px; right: 28px; }
.cloud-back { width: 210px; right: 2%; top: 175px; opacity: 0.7; }
.cloud-front { width: 280px; right: 20%; top: 230px; background: #282e58; }
.sleepy-bunny { position: absolute; z-index: 2; right: 39%; top: 176px; width: 100px; height: 76px; padding-top: 39px; border-radius: 48% 48% 42% 42%; text-align: center; color: #463e59; background: #e7dfdb; box-shadow: inset -10px -8px 0 rgba(122, 104, 135, 0.08); }
.sleepy-bunny b { font-size: 15px; letter-spacing: 3px; }
.ear { position: absolute; top: -46px; width: 28px; height: 65px; border-radius: 60% 60% 35% 35%; background: #e7dfdb; transform-origin: bottom; }
.ear::after { content: ""; position: absolute; inset: 9px; border-radius: inherit; background: #cbaebb; }
.ear.left { left: 17px; transform: rotate(-15deg); }
.ear.right { right: 17px; transform: rotate(15deg); }

.workspace { display: grid; grid-template-columns: minmax(0, 1.02fr) minmax(360px, 0.98fr); gap: 24px; align-items: start; }
.card { border: 1px solid var(--line); border-radius: 24px; background: var(--panel); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.creator-card { padding: 30px; }
.card-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 28px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.card-heading > div { display: flex; align-items: center; gap: 12px; }
.card-heading h2 { margin: 0; font-family: Georgia, "STSong", serif; font-size: 24px; font-weight: 500; }
.card-heading p { max-width: 190px; margin: 2px 0 0; color: var(--muted); font-size: 12px; line-height: 1.7; text-align: right; }
.step-label { display: grid; place-items: center; width: 31px; height: 31px; border-radius: 50%; color: var(--gold); background: rgba(245, 200, 106, 0.1); font: 700 10px Georgia, serif; }
.form-grid { display: grid; gap: 16px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field, .field-group { display: block; margin: 0 0 22px; padding: 0; border: 0; }
.form-grid .field { margin-bottom: 22px; }
.field > span, .field-group legend { display: block; margin-bottom: 10px; color: #d9d8e3; font-size: 13px; font-weight: 700; }
.field > span small { color: var(--muted); font-weight: 400; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; outline: none; color: var(--ink); background: rgba(7, 10, 28, 0.44); transition: border-color 160ms, box-shadow 160ms, background 160ms; }
input, select { height: 46px; padding: 0 13px; }
textarea { min-height: 88px; padding: 12px 13px; resize: vertical; line-height: 1.65; }
input:focus, select:focus, textarea:focus { border-color: rgba(245, 200, 106, 0.55); box-shadow: 0 0 0 3px rgba(245, 200, 106, 0.08); background: rgba(7, 10, 28, 0.68); }
option { color: #171a30; background: #f8f5ee; }
::placeholder { color: #777b97; }
.field-hint { display: block; margin-top: 7px; color: #777b97; font-size: 10px; }

.duration-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.duration-options input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.duration-options span { display: flex; flex-direction: column; gap: 4px; padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: rgba(7, 10, 28, 0.3); transition: 160ms; }
.duration-options b { font-size: 12px; }
.duration-options small { color: var(--muted); font-size: 10px; }
.duration-options input:checked + span { border-color: rgba(245, 200, 106, 0.55); color: var(--gold); background: rgba(245, 200, 106, 0.09); box-shadow: inset 0 0 0 1px rgba(245, 200, 106, 0.08); }
.theme-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 9px; }
.theme-chips button { padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: rgba(255, 255, 255, 0.025); font-size: 11px; }
.theme-chips button.active { border-color: rgba(169, 155, 247, 0.5); color: #d9d2ff; background: rgba(169, 155, 247, 0.11); }

.switch-row { display: flex; align-items: center; gap: 14px; margin: 4px 0 22px; cursor: pointer; }
.switch-row > span { flex: 1; }
.switch-row b, .switch-row small { display: block; }
.switch-row b { font-size: 13px; }
.switch-row small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.switch-row input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-row i { position: relative; width: 44px; height: 25px; border-radius: 999px; background: #353957; transition: 160ms; }
.switch-row i::after { content: ""; position: absolute; top: 4px; left: 4px; width: 17px; height: 17px; border-radius: 50%; background: #d8d8df; transition: 160ms; }
.switch-row input:checked + i { background: var(--gold-deep); }
.switch-row input:checked + i::after { transform: translateX(19px); background: #fff8e5; }

.primary-button { width: 100%; min-height: 67px; display: flex; align-items: center; justify-content: center; gap: 13px; border: 0; border-radius: 16px; color: #201a27; background: linear-gradient(135deg, #f8d77f, #eeb956); box-shadow: 0 14px 35px rgba(238, 185, 86, 0.22); transition: transform 160ms, filter 160ms; }
.primary-button:hover { transform: translateY(-2px); filter: brightness(1.04); }
.primary-button:disabled { cursor: wait; filter: grayscale(0.25); opacity: 0.75; transform: none; }
.button-icon { font-size: 21px; }
.button-copy b, .button-copy small { display: block; text-align: left; }
.button-copy b { font-size: 15px; }
.button-copy small { margin-top: 2px; color: rgba(32, 26, 39, 0.68); font-size: 10px; }

.result-column { display: grid; gap: 18px; }
.welcome-card, .loading-card { min-height: 440px; padding: 54px 46px; text-align: center; }
.welcome-card { display: flex; flex-direction: column; align-items: center; justify-content: center; background: linear-gradient(160deg, rgba(32, 37, 75, 0.88), rgba(19, 23, 49, 0.88)); }
.mini-moon { display: grid; place-items: center; width: 78px; height: 78px; margin-bottom: 24px; border-radius: 50%; color: #40384d; background: linear-gradient(145deg, #fff0ae, var(--gold)); box-shadow: 0 0 45px rgba(245, 200, 106, 0.18); font: 45px Georgia, serif; transform: rotate(-16deg); }
.welcome-card h2, .loading-card h2 { margin: 0; font-family: Georgia, "STSong", serif; font-size: 25px; font-weight: 500; }
.welcome-card p, .loading-card p { max-width: 330px; margin: 15px auto 0; color: var(--muted); font-size: 13px; line-height: 1.8; }
.little-shelf { display: flex; align-items: flex-end; gap: 5px; height: 42px; margin-top: 40px; padding: 0 14px 4px; border-bottom: 2px solid #555a78; }
.little-shelf i { display: block; width: 17px; border-radius: 2px 2px 0 0; background: #6f6a96; }
.little-shelf i:nth-child(1) { height: 27px; background: #9d7a6c; }
.little-shelf i:nth-child(2) { height: 35px; background: #7974a3; }
.little-shelf i:nth-child(3) { height: 30px; background: #617d83; }
.little-shelf i:nth-child(4) { height: 39px; background: #987f53; }

.loading-card { padding-top: 100px; }
.dream-loader { position: relative; width: 110px; height: 90px; margin: 0 auto 25px; }
.dream-loader span { position: absolute; inset: 9px 20px auto; font: 58px Georgia, serif; color: var(--gold); filter: drop-shadow(0 0 16px rgba(245, 200, 106, 0.32)); animation: float 2.2s ease-in-out infinite; }
.dream-loader i { position: absolute; width: 5px; height: 5px; border-radius: 50%; background: #fff6cf; animation: twinkle 1.5s ease-in-out infinite; }
.dream-loader i:nth-child(1) { left: 5px; top: 19px; }
.dream-loader i:nth-child(2) { right: 2px; top: 42px; animation-delay: -0.5s; }
.dream-loader i:nth-child(3) { left: 19px; bottom: 2px; animation-delay: -1s; }
.loading-line { width: 220px; height: 3px; margin: 32px auto 0; overflow: hidden; border-radius: 999px; background: rgba(255, 255, 255, 0.07); }
.loading-line i { display: block; width: 42%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, transparent, var(--gold), transparent); animation: loading 1.8s ease-in-out infinite; }

.story-card { padding: 34px; background: linear-gradient(160deg, rgba(31, 36, 72, 0.93), rgba(19, 23, 48, 0.93)); }
.story-meta { display: flex; justify-content: space-between; align-items: center; gap: 16px; color: var(--muted); font-size: 10px; }
.story-meta span { padding: 6px 9px; border-radius: 999px; color: var(--gold); background: rgba(245, 200, 106, 0.08); }
.story-card > h2 { margin: 26px 0 22px; font-family: Georgia, "STSong", serif; font-size: clamp(27px, 4vw, 38px); font-weight: 500; line-height: 1.3; }
.story-content { max-height: 540px; padding-right: 8px; overflow-y: auto; color: #dedde7; font-family: Georgia, "STSong", serif; font-size: 16px; line-height: 2.05; scrollbar-color: #4a4f72 transparent; }
.story-content p { margin: 0 0 1.1em; }
.player { display: flex; align-items: center; gap: 10px; margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line); }
.play-button { flex: 1; min-height: 46px; border: 1px solid rgba(245, 200, 106, 0.3); border-radius: 12px; color: var(--gold); background: rgba(245, 200, 106, 0.08); }
.play-button span { margin-right: 7px; }
.round-button { width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 50%; background: rgba(255, 255, 255, 0.035); }
.round-button:disabled { cursor: default; opacity: 0.35; }
.voice-options { display: flex; align-items: center; gap: 8px; }
.voice-speed { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; }
.voice-speed select { width: auto; min-width: 67px; height: 36px; padding: 0 6px; border-radius: 9px; font-size: 10px; }

.history-card { padding: 22px; box-shadow: none; }
.history-heading { display: flex; align-items: center; justify-content: space-between; }
.history-heading h2 { margin: 0; font-size: 14px; }
.history-heading button { border: 0; color: var(--muted); background: transparent; font-size: 10px; }
.history-list { display: grid; gap: 7px; margin-top: 14px; }
.history-item { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid transparent; border-radius: 10px; text-align: left; background: rgba(255, 255, 255, 0.025); }
.history-item:hover { border-color: var(--line); background: rgba(255, 255, 255, 0.045); }
.history-item b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.history-item small { flex: none; color: var(--muted); font-size: 9px; }

.toast { position: fixed; z-index: 10; left: 50%; bottom: 28px; max-width: min(420px, calc(100% - 32px)); padding: 12px 17px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: #242947; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35); font-size: 12px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: 220ms; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.error { border-color: rgba(255, 157, 157, 0.35); color: #ffd1d1; }

.modal-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 6, 17, 0.82);
  backdrop-filter: blur(12px);
}
.pin-dialog {
  width: min(430px, 100%);
  padding: 34px;
  border: 1px solid rgba(245, 200, 106, 0.22);
  border-radius: 24px;
  text-align: center;
  background: linear-gradient(160deg, #20264c, #12162f);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.5);
}
.pin-moon { display: block; color: var(--gold); font: 48px Georgia, serif; filter: drop-shadow(0 0 15px rgba(245, 200, 106, 0.25)); }
.pin-dialog .eyebrow { margin: 10px 0 8px; }
.pin-dialog h2 { margin: 0; font-family: Georgia, "STSong", serif; font-size: 28px; font-weight: 500; }
.pin-dialog > p:not(.eyebrow) { margin: 13px auto 23px; color: var(--muted); font-size: 12px; line-height: 1.75; }
.pin-field { text-align: left; }
.pin-field input { text-align: center; letter-spacing: 0.16em; }
.pin-actions { display: grid; grid-template-columns: 0.8fr 1.2fr; gap: 10px; }
.pin-actions .quiet-button, .pin-save { min-height: 48px; }
.pin-save { border-radius: 999px; }

[hidden] { display: none !important; }

@keyframes twinkle { 0%, 100% { opacity: 0.25; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.3); } }
@keyframes pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(-14deg); } 50% { transform: translateY(-7px) rotate(-12deg); } }
@keyframes loading { 0% { transform: translateX(-120%); } 100% { transform: translateX(340%); } }

@media (max-width: 900px) {
  .hero { min-height: 330px; grid-template-columns: 1fr 0.58fr; gap: 20px; padding-inline: 10px; }
  .moon-scene { min-height: 260px; transform: scale(0.82); transform-origin: center; }
  .workspace { grid-template-columns: 1fr; }
  .result-column { grid-row: 2; }
  .welcome-card, .loading-card { min-height: 330px; }
}

@media (max-width: 620px) {
  .topbar, main { width: min(100% - 24px, 1180px); }
  .topbar { padding-top: calc(18px + env(safe-area-inset-top)); }
  .brand small, .status { display: none; }
  .quiet-button { padding: 8px 11px; }
  .top-actions { gap: 6px; }
  .top-actions .quiet-button { font-size: 10px; }
  .hero { min-height: auto; grid-template-columns: 1fr; padding: 48px 5px 38px; }
  .hero h1 { font-size: 42px; }
  .hero-text { font-size: 14px; }
  .moon-scene { display: none; }
  .creator-card, .story-card { padding: 21px; border-radius: 19px; }
  .card-heading { display: block; }
  .card-heading p { max-width: none; margin: 10px 0 0 43px; text-align: left; }
  .two-columns { grid-template-columns: 1fr; gap: 0; }
  .duration-options { gap: 7px; }
  .duration-options span { padding: 11px 8px; }
  .duration-options b { font-size: 11px; }
  .welcome-card, .loading-card { min-height: 350px; padding-inline: 28px; }
  .story-content { max-height: none; font-size: 15px; }
  .player { flex-wrap: wrap; }
  .voice-options { width: 100%; justify-content: flex-end; }
  .pin-dialog { padding: 28px 20px; }
}

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