:root {
  color-scheme: light;
  --ink: #21313a;
  --muted: #61727b;
  --paper: #fffaf1;
  --panel: #fffdf8;
  --line: #dfe8df;
  --blue: #8fc7df;
  --blue-strong: #397e96;
  --green: #95bd76;
  --green-strong: #4f7a3e;
  --coral: #ef7e68;
  --coral-dark: #bb5545;
  --shadow: 0 24px 70px rgba(54, 78, 84, 0.18);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    linear-gradient(180deg, rgba(143, 199, 223, 0.3), transparent 38%),
    radial-gradient(circle at 12% 18%, rgba(149, 189, 118, 0.16), transparent 24rem),
    var(--paper);
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.app-shell {
  min-height: 100vh;
  padding: 28px;
  display: grid;
  place-items: center;
}

.workspace {
  width: min(1160px, 100%);
  min-height: min(760px, calc(100vh - 56px));
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
}

.control-panel,
.reader-panel {
  border: 1px solid rgba(97, 114, 123, 0.16);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

.control-panel {
  padding: 22px;
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: #e7f4f7;
  color: var(--blue-strong);
}

.brand-mark svg,
.generate-button svg,
.icon-button svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-mark svg {
  width: 34px;
  height: 34px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.12;
  font-weight: 780;
}

.brand-header p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.story-form {
  display: grid;
  gap: 20px;
  margin-top: 22px;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend,
.field span {
  display: block;
  margin-bottom: 9px;
  color: #334952;
  font-size: 14px;
  font-weight: 720;
}

.segmented,
.choice-grid {
  display: grid;
  gap: 8px;
}

.segmented {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented label,
.choice-grid label {
  min-width: 0;
}

.segmented input,
.choice-grid input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span,
.choice-grid span {
  min-height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffefa;
  color: #415860;
  font-size: 14px;
  font-weight: 700;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.segmented input:checked + span,
.choice-grid input:checked + span {
  border-color: rgba(57, 126, 150, 0.36);
  background: #dff1f7;
  color: #205d72;
}

.segmented span:hover,
.choice-grid span:hover {
  transform: translateY(-1px);
}

textarea {
  width: 100%;
  min-height: 104px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  color: var(--ink);
  background: #fffefa;
  outline: none;
  line-height: 1.55;
}

textarea:focus,
.segmented input:focus-visible + span,
.choice-grid input:focus-visible + span,
button:focus-visible {
  outline: 3px solid rgba(239, 126, 104, 0.26);
  outline-offset: 2px;
}

.generate-button {
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: var(--radius);
  background: var(--coral);
  color: #fffdfa;
  font-weight: 780;
  box-shadow: 0 16px 28px rgba(239, 126, 104, 0.28);
}

.generate-button:hover:not(:disabled) {
  background: var(--coral-dark);
}

.generate-button:disabled {
  opacity: 0.78;
}

.reader-panel {
  position: relative;
  overflow: hidden;
  padding: 28px;
  display: flex;
  flex-direction: column;
}

.reader-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(149, 189, 118, 0.1), transparent 18%),
    linear-gradient(180deg, rgba(143, 199, 223, 0.12), transparent 28%);
}

.reader-top,
.meta-row,
.story-body {
  position: relative;
}

.reader-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.status-label {
  color: var(--green-strong);
  font-size: 13px;
  font-weight: 760;
}

h2 {
  max-width: 680px;
  margin-top: 5px;
  font-size: clamp(30px, 4vw, 52px);
  line-height: 1.08;
  font-weight: 820;
}

.reader-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffefa;
  color: var(--blue-strong);
}

.icon-button:hover:not(:disabled) {
  border-color: rgba(57, 126, 150, 0.3);
  background: #edf8fb;
}

.icon-button:disabled {
  opacity: 0.42;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 22px 0 18px;
}

.meta-row span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: #edf5e6;
  color: #466b38;
  font-size: 13px;
  font-weight: 720;
}

.story-body {
  flex: 1;
  min-height: 420px;
  overflow: auto;
  border: 1px solid rgba(97, 114, 123, 0.14);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(57, 126, 150, 0.05) 1px, transparent 1px),
    #fffefa;
  background-size: 34px 34px;
  padding: 26px;
  color: #283c44;
  font-size: 18px;
  line-height: 1.88;
}

.story-body p + p {
  margin-top: 18px;
}

.story-summary {
  padding: 14px 16px;
  margin-bottom: 20px;
  border-left: 4px solid var(--green);
  background: #f4faef;
  border-radius: var(--radius);
  color: #415c38;
  line-height: 1.65;
}

.story-moral {
  margin-top: 24px;
  padding: 14px 16px;
  border: 1px solid #f3d4c9;
  border-radius: var(--radius);
  background: #fff1ec;
  color: #714238;
}

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

.storybook-art {
  width: min(310px, 86%);
}

.storybook-art svg {
  width: 100%;
  height: auto;
}

.sun {
  fill: #ffd36d;
}

.hill-left {
  fill: #bcd89e;
}

.hill-right {
  fill: #95bd76;
}

.book-page {
  fill: #fff3d6;
  stroke: #d7aa63;
  stroke-width: 3;
  stroke-linejoin: round;
}

.book-fold {
  stroke: #d7aa63;
  stroke-width: 3;
  stroke-linecap: round;
}

.star {
  fill: #ef7e68;
}

.loading .generate-button svg {
  animation: spin 1s linear infinite;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 10;
  transform: translateX(-50%);
  border-radius: var(--radius);
  background: #21313a;
  color: white;
  padding: 10px 14px;
  font-size: 14px;
  box-shadow: 0 18px 40px rgba(33, 49, 58, 0.24);
}

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

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

@media (max-width: 860px) {
  .app-shell {
    padding: 14px;
    place-items: stretch;
  }

  .workspace {
    min-height: auto;
    grid-template-columns: 1fr;
  }

  .control-panel,
  .reader-panel {
    box-shadow: 0 16px 42px rgba(54, 78, 84, 0.14);
  }

  .reader-panel {
    padding: 20px;
  }

  .reader-top {
    flex-direction: column;
  }

  .reader-actions {
    align-self: flex-end;
  }

  h2 {
    font-size: 32px;
  }

  .story-body {
    min-height: 360px;
    padding: 20px;
    font-size: 17px;
  }
}

@media (max-width: 460px) {
  .app-shell {
    padding: 10px;
  }

  .control-panel,
  .reader-panel {
    padding: 16px;
  }

  .brand-header {
    align-items: flex-start;
  }

  h1 {
    font-size: 23px;
  }

  .segmented,
  .choice-grid {
    grid-template-columns: 1fr;
  }
}
