:root {
  --ink: #262331;
  --muted: #777384;
  --paper: #fffdfb;
  --cream: #f6f0ea;
  --line: #eadfd8;
  --accent: #b85f68;
  --accent-dark: #8f3f4c;
  --sage: #607d72;
  --shadow: 0 20px 60px rgba(78, 50, 47, .10);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background: #f5efea;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: radial-gradient(circle at top left, #fff8f4 0, #f5efea 48%, #ede5df 100%); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
body.is-busy, body.is-busy button, body.is-busy a, body.is-busy input, body.is-busy textarea, body.is-busy select { cursor: wait !important; }
a { color: var(--accent-dark); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.busy-overlay { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 22px; background: rgba(38,35,49,.28); backdrop-filter: blur(2px); }
.busy-dialog { display: inline-flex; align-items: center; gap: 12px; max-width: min(90vw, 420px); padding: 16px 20px; border: 1px solid rgba(255,255,255,.75); border-radius: 16px; background: rgba(255,253,251,.96); box-shadow: 0 16px 42px rgba(38,35,49,.18); color: var(--ink); font-weight: 800; line-height: 1.5; }
.busy-spinner { width: 22px; height: 22px; flex: 0 0 22px; border: 3px solid #e8c9c5; border-top-color: var(--accent-dark); border-radius: 50%; animation: busy-spin .8s linear infinite; }
@keyframes busy-spin { to { transform: rotate(360deg); } }

.app-shell { width: min(1180px, calc(100% - 36px)); margin: 0 auto; padding: 28px 0 70px; }
.site-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; padding: 18px 4px 32px; }
.eyebrow, .panel-kicker { margin: 0 0 8px; color: var(--accent); font-size: .70rem; font-weight: 800; letter-spacing: .18em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, serif; font-size: clamp(1.7rem, 4vw, 2.5rem); font-weight: 500; letter-spacing: .02em; }
h2 { margin-bottom: 10px; font-family: Georgia, "Noto Serif TC", serif; font-size: clamp(1.45rem, 3vw, 2.1rem); font-weight: 500; }
h3 { margin: 0; font-size: 1.1rem; }
.header-status { color: var(--muted); font-size: .9rem; }

.intro-card, .end-card { padding: 38px clamp(24px, 5vw, 62px); border: 1px solid rgba(255,255,255,.8); border-radius: 28px; background: linear-gradient(135deg, rgba(255,255,255,.86), rgba(250,238,234,.92)); box-shadow: var(--shadow); }
.intro-card p, .end-card p { max-width: 720px; margin-bottom: 0; color: var(--muted); line-height: 1.8; }
.step-badge { display: inline-flex; margin-bottom: 17px; padding: 6px 11px; border-radius: 999px; background: #f7e2dd; color: var(--accent-dark); font-size: .7rem; font-weight: 800; letter-spacing: .12em; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 18px; }
.panel { padding: 25px; border: 1px solid var(--line); border-radius: 22px; background: rgba(255,253,251,.88); box-shadow: 0 10px 30px rgba(78,50,47,.05); }
.full-width { grid-column: 1 / -1; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 20px; }
.privacy-chip { padding: 6px 10px; border-radius: 999px; color: var(--sage); background: #e7f0ec; font-size: .75rem; font-weight: 700; }
.field-grid { display: grid; gap: 14px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.compact { align-items: end; }
.field-stack { display: grid; gap: 14px; }
label { display: grid; gap: 7px; color: #5c5662; font-size: .82rem; font-weight: 700; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 12px; outline: none; background: #fff; color: var(--ink); padding: 11px 13px; transition: border-color .2s, box-shadow .2s; }
textarea { min-height: 74px; resize: vertical; line-height: 1.6; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(184,95,104,.13); }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
.checkbox-label { display: flex; align-items: center; gap: 8px; min-height: 42px; }
.button-row { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.align-end { align-self: end; }
.button { min-height: 40px; border: 1px solid transparent; border-radius: 12px; padding: 9px 15px; font-weight: 800; transition: transform .15s, box-shadow .15s, background .15s; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button.primary { color: white; background: linear-gradient(135deg, var(--accent), var(--accent-dark)); box-shadow: 0 7px 16px rgba(143,63,76,.18); }
.button.secondary { color: var(--accent-dark); border-color: #e8c9c5; background: #fff4f1; }
.button.ghost { color: var(--muted); border-color: var(--line); background: transparent; }
.button.danger { color: #a24848; border-color: #efcaca; background: #fff4f4; }
.button.large { min-height: 50px; padding: 12px 23px; font-size: 1rem; }
.button.small { min-height: 32px; padding: 6px 10px; font-size: .78rem; }
.setup-actions { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 24px 4px 0; }
.form-hint { margin: 0; color: var(--muted); font-size: .85rem; }
.inline-status { min-height: 24px; margin-top: 15px; color: var(--muted); font-size: .86rem; }
.success { color: var(--sage) !important; }
.error { color: #b04754 !important; }
.loading { color: #9a724b !important; }
.notice { margin: 14px 0; padding: 12px 15px; border: 1px solid #eadfd8; border-radius: 13px; background: rgba(255,253,251,.9); color: var(--muted); font-size: .88rem; }

.promo-box { display: grid; gap: 7px; margin-top: 20px; padding: 15px 17px; border: 1px solid #efd2c3; border-radius: 15px; background: linear-gradient(135deg, #fff7ee, #fff1ee); }
.promo-box a { font-weight: 800; line-height: 1.55; }
.promo-label { margin-bottom: 2px; color: #a96b52; font-size: .73rem; font-weight: 900; letter-spacing: .12em; }

.story-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 18px; }
.character-heading { display: flex; align-items: center; gap: 13px; }
.character-heading h2 { margin: 0; }
.avatar { display: grid; width: 52px; height: 52px; place-items: center; border-radius: 18px; color: white; background: linear-gradient(135deg, #d48788, #8b5364); font-family: Georgia, serif; font-size: 1.6rem; box-shadow: 0 8px 18px rgba(143,63,76,.2); }
.turn-counter { padding: 9px 13px; border-radius: 999px; color: var(--accent-dark); background: #f7e2dd; font-weight: 800; font-size: .88rem; white-space: nowrap; }
.story-intro-media { display: grid; gap: 10px; margin: 0 5px 4px; padding: 14px; border: 1px solid #efd2c3; border-radius: 18px; background: rgba(255,247,240,.72); }
.story-intro-heading { color: var(--accent-dark); font-size: .78rem; font-weight: 900; letter-spacing: .1em; }
.story-intro-assets { display: flex; flex-wrap: wrap; gap: 14px; }
.conversation { display: grid; gap: 20px; max-height: 58vh; overflow: auto; padding: 8px 5px 20px; }
.opening-card { padding: 20px; border: 1px dashed #decac1; border-radius: 18px; background: rgba(255,253,251,.65); color: var(--muted); line-height: 1.8; }
.turn-group { display: grid; gap: 10px; }
.turn-number { color: var(--muted); font-size: .72rem; font-weight: 900; letter-spacing: .12em; }
.bubble { max-width: min(760px, 88%); padding: 13px 16px; border-radius: 17px; line-height: 1.75; white-space: pre-wrap; }
.user-bubble { justify-self: end; border-bottom-right-radius: 5px; color: #fff; background: #7d6972; }
.assistant-bubble { justify-self: start; border-bottom-left-radius: 5px; background: #fffdfb; border: 1px solid var(--line); }
.composer { margin-top: 12px; }
.composer textarea { min-height: 78px; border: 0; padding: 0; background: transparent; box-shadow: none; }
.composer textarea:focus { box-shadow: none; }
.composer-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.media-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.video-rule-note { margin: 12px 0 0; color: var(--muted); font-size: .75rem; line-height: 1.6; }
.story-footer-actions { display: flex; justify-content: flex-end; padding: 16px 4px; }

.media-card { display: grid; gap: 9px; width: min(380px, 100%); padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.media-label { color: var(--muted); font-size: .75rem; font-weight: 800; }
.media-preview { display: block; width: 100%; max-height: 480px; border-radius: 11px; background: #f3ece7; object-fit: cover; }
.end-card { margin-bottom: 18px; text-align: center; }
.end-card p { margin: 0 auto 25px; }
.end-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 9px; }
.media-library { margin-top: 18px; }
.end-media-list { display: flex; flex-wrap: wrap; gap: 14px; }
.end-promo { margin-top: 18px; }

@media (max-width: 800px) {
  .app-shell { width: min(100% - 22px, 680px); padding-top: 15px; }
  .site-header, .setup-actions, .story-toolbar, .composer-actions { align-items: flex-start; flex-direction: column; }
  .header-status { align-self: flex-start; }
  .form-grid, .two-columns { grid-template-columns: 1fr; }
  .full-width { grid-column: auto; }
  .setup-actions .button { width: 100%; }
  .turn-counter { align-self: flex-start; }
  .bubble { max-width: 94%; }
  .composer-actions, .media-actions { width: 100%; }
  .composer-actions .button.primary { width: 100%; }
}
