:root {
  color-scheme: light;
  --ink: #3e3b52;
  --muted: #77738a;
  --cream: #fff7e8;
  --paper: #fffdf8;
  --line: #f1e7d4;
  --coral: #ef766b;
  --coral-dark: #d85c57;
  --yellow: #ffd972;
  --mint: #d8f0e5;
  --lavender: #e5e1fa;
  --shadow: 0 16px 44px rgb(113 87 61 / 10%);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 5%, rgb(255 217 114 / 35%), transparent 17rem),
    radial-gradient(circle at 96% 42%, rgb(216 240 229 / 70%), transparent 19rem),
    var(--cream);
}

button,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgb(92 155 217 / 60%);
  outline-offset: 2px;
}

.app-shell {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 48px 0 32px;
}

.hero {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 8px 8px 30px;
}

.hero-badge {
  display: grid;
  flex: 0 0 88px;
  width: 88px;
  height: 88px;
  place-items: center;
  color: #936a32;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  background: var(--yellow);
  border-radius: 30px 30px 30px 8px;
  box-shadow: 8px 8px 0 rgb(239 118 107 / 16%);
  transform: rotate(-4deg);
}

.eyebrow,
.section-kicker {
  margin: 0 0 5px;
  color: var(--coral-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(1.85rem, 5vw, 3rem);
  letter-spacing: 0.02em;
  line-height: 1.2;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.2rem, 3vw, 1.55rem);
}

.hero-copy {
  max-width: 620px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.8;
}

.panel {
  margin-bottom: 22px;
  padding: clamp(22px, 4vw, 36px);
  background: rgb(255 253 248 / 92%);
  border: 1px solid rgb(241 231 212 / 90%);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.character-count {
  color: var(--muted);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

textarea {
  display: block;
  width: 100%;
  min-height: 128px;
  padding: 17px 18px;
  color: var(--ink);
  line-height: 1.8;
  resize: vertical;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 18px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

textarea:focus {
  border-color: var(--yellow);
  box-shadow: 0 0 0 4px rgb(255 217 114 / 20%);
  outline: none;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
}

.toolbar-fields {
  display: flex;
  align-items: end;
  gap: 12px;
}

.select-label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.number-label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

select {
  min-width: 170px;
  padding: 11px 34px 11px 13px;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 12px;
}

.number-label input {
  width: 92px;
  padding: 11px 13px;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 12px;
}

.primary-button,
.secondary-button,
.mode-button {
  border: 0;
  transition: transform 160ms ease, background-color 160ms ease, opacity 160ms ease;
}

.primary-button {
  padding: 13px 21px;
  color: #fff;
  font-weight: 800;
  background: var(--coral);
  border-radius: 13px;
  box-shadow: 0 6px 0 var(--coral-dark);
}

.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled) {
  transform: translateY(-2px);
}

.primary-button:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 3px 0 var(--coral-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.helper-text {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.6;
}

.planning-badge {
  padding: 7px 10px;
  color: #687b71;
  font-size: 0.74rem;
  font-weight: 800;
  background: var(--mint);
  border-radius: 999px;
}

.planning-intro {
  margin-top: -8px;
  margin-bottom: 20px;
}

.outline-editor,
.script-editor {
  display: grid;
  gap: 16px;
}

.plan-section {
  display: grid;
  gap: 12px;
  padding: 18px;
  background: rgb(255 255 255 / 78%);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.plan-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.plan-section-heading h3 {
  margin: 0;
  font-size: 1rem;
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.plan-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.plan-field.full-width {
  grid-column: 1 / -1;
}

.plan-field input,
.plan-field textarea,
.plan-field select {
  width: 100%;
  min-height: auto;
  padding: 10px 12px;
  color: var(--ink);
  line-height: 1.55;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.plan-field textarea {
  min-height: 74px;
}

.plan-list {
  display: grid;
  gap: 12px;
}

.plan-item,
.script-page {
  display: grid;
  gap: 12px;
  padding: 15px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 15px;
}

.plan-item-heading,
.script-page-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.plan-item-heading strong,
.script-page-heading strong {
  font-size: 0.9rem;
}

.subtle-button,
.remove-plan-button {
  padding: 6px 9px;
  color: var(--coral-dark);
  font-size: 0.75rem;
  font-weight: 800;
  background: transparent;
  border: 1px solid rgb(216 92 87 / 30%);
  border-radius: 9px;
}

.subtle-button:hover,
.remove-plan-button:hover {
  background: rgb(239 118 107 / 9%);
}

.planning-toolbar {
  align-items: center;
  margin-top: 20px;
}

.planning-toolbar .script-lock-note {
  margin: 0;
}

.script-page + .script-page {
  margin-top: 2px;
}

.script-character-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 2px;
}

.script-character-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 9px;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.script-character-option input {
  accent-color: var(--coral);
}

.story-heading {
  align-items: flex-end;
}

.mode-switch {
  display: flex;
  padding: 4px;
  background: var(--lavender);
  border-radius: 12px;
}

.mode-button {
  padding: 8px 12px;
  color: #68627d;
  font-size: 0.8rem;
  background: transparent;
  border-radius: 9px;
}

.mode-button.is-active {
  color: var(--ink);
  font-weight: 800;
  background: #fff;
  box-shadow: 0 2px 8px rgb(71 59 108 / 12%);
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 0.9rem;
}

.status.is-loading {
  color: var(--coral-dark);
}

.status.is-error {
  color: #b44e4b;
}

.status-dot {
  width: 9px;
  height: 9px;
  background: var(--mint);
  border-radius: 50%;
}

.is-loading .status-dot {
  background: var(--yellow);
  animation: pulse 900ms ease-in-out infinite alternate;
}

.is-error .status-dot {
  background: var(--coral);
}

.storybook-grid {
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(0, 1.1fr);
  gap: 22px;
}

.illustration-card,
.story-card {
  min-height: 330px;
  overflow: hidden;
  border-radius: 22px;
}

.illustration-card {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 70% 22%, rgb(255 255 255 / 80%) 0 9%, transparent 10%),
    linear-gradient(160deg, #d6f0e4, #b9dce3);
}

.illustration-card img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 330px;
  object-fit: cover;
}

.illustration-placeholder {
  display: grid;
  place-items: center;
  gap: 14px;
  padding: 30px;
  color: #4f8176;
  font-size: 0.9rem;
  text-align: center;
}

.placeholder-sun {
  color: #f2b84b;
  font-size: 3.6rem;
}

.illustration-progress {
  width: min(100%, 260px);
}

.progress-spinner {
  width: 42px;
  height: 42px;
  border: 5px solid rgb(255 255 255 / 65%);
  border-top-color: #70a89b;
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

.progress-track {
  display: block;
  width: min(100%, 210px);
  height: 8px;
  overflow: hidden;
  background: rgb(255 255 255 / 65%);
  border-radius: 999px;
}

.progress-track::after {
  display: block;
  width: 42%;
  height: 100%;
  content: "";
  background: #70a89b;
  border-radius: inherit;
  animation: progress-slide 1.4s ease-in-out infinite;
}

.story-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(22px, 4vw, 34px);
  background: #fff;
  border: 1px solid var(--line);
}

.empty-story {
  display: grid;
  place-items: center;
  gap: 13px;
  color: var(--muted);
  text-align: center;
}

.empty-story p {
  margin-bottom: 0;
  line-height: 1.7;
}

.empty-icon {
  font-size: 2.8rem;
}

.story-content {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  align-items: center;
  gap: 0.7em 0.35em;
  min-height: 200px;
  padding: 15px 5px;
  color: var(--ink);
  font-size: clamp(1.35rem, 3.2vw, 2rem);
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}

.story-content .word-pair {
  display: inline-flex;
  align-items: center;
  gap: 0.14em;
  min-height: 1.5em;
}

.story-content .word-char {
  line-height: 1.1;
}

.story-content .word-zhuyin {
  display: inline-flex;
  align-items: center;
  gap: 0.08em;
  color: var(--coral-dark);
  font-size: 0.46em;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.story-content .word-zhuyin-base {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  writing-mode: horizontal-tb;
}

.story-content .word-zhuyin-symbol {
  display: block;
  line-height: 1;
}

.story-content .word-zhuyin-tone {
  display: inline-block;
  align-self: center;
  font-size: 0.9em;
  line-height: 1;
  writing-mode: horizontal-tb;
}

.story-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
  margin-top: 18px;
}

.page-navigation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 18px;
}

.page-button {
  padding: 9px 14px;
  color: #68627d;
  font-size: 0.84rem;
  font-weight: 700;
  background: var(--lavender);
  border: 0;
  border-radius: 10px;
}

.page-button:hover:not(:disabled) {
  background: #dcd5f7;
}

.page-indicator {
  min-width: 92px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.secondary-button {
  padding: 9px 13px;
  color: #68627d;
  font-size: 0.84rem;
  font-weight: 700;
  background: var(--lavender);
  border-radius: 10px;
}

.text-button {
  padding: 8px 0;
  color: var(--coral-dark);
  font-size: 0.82rem;
  font-weight: 700;
  background: transparent;
  border: 0;
}

.text-button:hover {
  text-decoration: underline;
}

.history-note {
  margin-top: -8px;
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.history-empty {
  margin: 0;
  padding: 22px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 14px;
}

.history-entry {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.history-load-button {
  display: grid;
  flex: 1;
  gap: 5px;
  padding: 13px 15px;
  color: var(--ink);
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.history-load-button:hover {
  border-color: var(--yellow);
  box-shadow: 0 5px 16px rgb(113 87 61 / 8%);
  transform: translateY(-1px);
}

.history-title {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  color: var(--muted);
  font-size: 0.76rem;
}

.history-delete-button {
  align-self: center;
  padding: 8px;
  color: var(--muted);
  font-size: 0.76rem;
  background: transparent;
  border: 0;
}

.history-delete-button:hover {
  color: var(--coral-dark);
}

.footer-note {
  padding: 10px 8px;
  color: var(--muted);
  font-size: 0.83rem;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes pulse {
  from {
    transform: scale(0.8);
    opacity: 0.6;
  }
  to {
    transform: scale(1.2);
    opacity: 1;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes progress-slide {
  from {
    transform: translateX(-130%);
  }
  to {
    transform: translateX(250%);
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 22px, 620px);
    padding-top: 28px;
  }

  .hero {
    align-items: flex-start;
    gap: 16px;
    padding-inline: 4px;
  }

  .hero-badge {
    flex-basis: 64px;
    width: 64px;
    height: 64px;
    font-size: 0.9rem;
    border-radius: 21px 21px 21px 6px;
  }

  .toolbar,
  .storybook-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-fields {
    align-items: stretch;
    flex-direction: column;
  }

  .plan-grid {
    grid-template-columns: 1fr;
  }

  .plan-field.full-width {
    grid-column: auto;
  }

  .select-label,
  .number-label,
  select,
  .number-label input,
  .primary-button {
    width: 100%;
  }

  .story-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .mode-switch {
    width: 100%;
  }

  .mode-button {
    flex: 1;
  }

  .illustration-card,
  .story-card,
  .illustration-card img {
    min-height: 260px;
  }
}
