:root {
  --ink: #263449;
  --muted: #617087;
  --quiet: #8a98aa;
  --paper: #fffdf8;
  --surface: #ffffff;
  --surface-soft: #f5f7fb;
  --line: #d9e1ed;
  --line-strong: #b9c7da;
  --accent: #1769e0;
  --accent-soft: #e7f0ff;
  --warm: #e8794f;
  --warm-soft: #fff0e8;
  --success: #167a52;
  --success-soft: #e7f5ee;
  --danger: #b6463d;
  --danger-soft: #fff0ef;
  --shadow: 0 12px 30px rgba(38, 52, 73, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--surface-soft); }

body {
  margin: 0;
  color: var(--ink);
  background: var(--surface-soft);
  font-family: "Nunito", "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  line-height: 1.5;
}

button, input, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(23, 105, 224, 0.32); outline-offset: 2px; }

.app-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 26px 0 64px; }
.app-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding: 4px 0 24px; border-bottom: 1px solid var(--line); }
.eyebrow, .section-kicker { margin: 0 0 6px; color: var(--accent); font-size: .78rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.brand-title { margin: 0; font-size: 2.45rem; line-height: 1.12; font-weight: 950; letter-spacing: 0; }
.brand-copy { max-width: 620px; margin: 10px 0 0; color: var(--muted); font-size: 1rem; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.release-label { color: var(--quiet); font-size: .82rem; font-weight: 800; }
.text-button { border: 0; padding: 6px 0; color: var(--accent); background: transparent; font-weight: 850; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.orientation-band { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(250px, .9fr); gap: 24px; margin: 24px 0; padding: 24px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.orientation-band h2 { margin: 0; font-size: 1.5rem; line-height: 1.25; }
.orientation-band p { margin: 8px 0 0; color: var(--muted); }
.activity-meta { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; align-self: start; }
.meta-cell { padding: 12px; background: var(--surface-soft); border-left: 3px solid var(--accent); }
.meta-cell span, .meta-cell strong { display: block; }
.meta-cell span { color: var(--muted); font-size: .78rem; }
.meta-cell strong { margin-top: 4px; font-size: 1.05rem; }
.progress-area { grid-column: 1 / -1; display: grid; gap: 8px; }
.progress-line { height: 8px; overflow: hidden; background: #e7edf5; border-radius: 99px; }
.progress-line > span { display: block; width: 20%; height: 100%; background: var(--accent); border-radius: inherit; transition: width .25s ease; }
.progress-copy { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: .84rem; }

.workspace-section { margin: 20px 0; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.section-heading h2, .panel-title { margin: 0; font-size: 1.24rem; line-height: 1.25; }
.section-heading p { margin: 0; }
.privacy-note { color: var(--success); font-size: .83rem; font-weight: 850; }
.setup-grid { display: grid; grid-template-columns: minmax(180px, .8fr) minmax(260px, 1fr) minmax(230px, 1fr); gap: 16px; align-items: end; }
.field-label, .mode-label { display: grid; gap: 7px; color: var(--muted); font-size: .82rem; font-weight: 850; }
.text-input, .reflection-input, .sentence-input { width: 100%; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--paper); color: var(--ink); }
.text-input { min-height: 44px; padding: 9px 11px; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 12px; }
.mode-button { min-height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 850; cursor: pointer; }
.mode-button[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: 0 2px 7px rgba(38, 52, 73, .1); }
.mode-note { margin: 0; color: var(--muted); font-size: .86rem; }

.story-section { margin: 20px 0; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.story-heading { align-items: center; }
.story-count { color: var(--muted); font-size: .85rem; font-weight: 850; }
.story-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.story-empty { min-height: 132px; display: grid; place-items: center; padding: 20px; border: 1px dashed var(--line-strong); border-radius: 12px; color: var(--muted); background: var(--surface-soft); text-align: center; }
.story-card { display: grid; overflow: hidden; border: 1px solid var(--line); border-top: 4px solid var(--line-strong); border-radius: 12px; background: var(--paper); cursor: pointer; transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease; }
.story-card:hover, .story-card.is-active { transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 8px 18px rgba(38, 52, 73, .1); }
.story-card[data-status="ready"] { border-top-color: var(--success); }
.story-card[data-status="fallback"] { border-top-color: var(--warm); }
.story-card[data-status="failed"] { border-top-color: var(--danger); }
.story-card__media { display: grid; place-items: center; min-height: 116px; background: #eaf1fa; color: var(--muted); }
.story-card__media img { width: 100%; height: 116px; object-fit: cover; }
.story-card__body { padding: 12px; }
.story-card__topline, .timeline-topline { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.story-card__number { color: var(--accent); font-size: .78rem; font-weight: 900; }
.status-badge { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 7px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); color: var(--muted); font-size: .72rem; font-weight: 900; }
.status-badge--ready { border-color: #a6d8c0; background: var(--success-soft); color: var(--success); }
.status-badge--fallback { border-color: #f3c7af; background: var(--warm-soft); color: #a65331; }
.status-badge--failed { border-color: #efb4b0; background: var(--danger-soft); color: var(--danger); }
.story-card__text { margin: 10px 0 0; line-height: 1.55; word-break: keep-all; }
.story-card__actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

.workspace-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(320px, .95fr); gap: 20px; margin: 20px 0; }
.panel { padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-copy { margin: 7px 0 0; color: var(--muted); font-size: .9rem; }
.sentence-input { min-height: 144px; resize: vertical; padding: 13px; line-height: 1.6; }
.compose-panel { display: grid; align-content: start; gap: 12px; }
.writing-support { padding: 2px 0 0; }
.writing-support__header h3 { margin: 0; font-size: .98rem; }
.writing-support__header p { margin: 4px 0 0; color: var(--muted); font-size: .82rem; }
.support-groups { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 11px; }
.support-group { min-width: 0; margin: 0; padding: 9px; border: 1px solid var(--line); border-radius: 10px; }
.support-group legend { padding: 0 4px; color: var(--muted); font-size: .76rem; font-weight: 900; }
.support-options { display: grid; gap: 5px; }
.support-option { min-height: 34px; padding: 6px 8px; border: 1px solid transparent; border-radius: 8px; background: var(--surface-soft); color: var(--ink); font-size: .78rem; font-weight: 850; cursor: pointer; text-align: left; }
.support-option[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.support-status { min-height: 20px; margin: 8px 0 0; color: var(--muted); font-size: .78rem; }
.input-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .78rem; }
.input-meta.is-warning, .input-help.is-warning { color: var(--danger); }
.input-help { min-height: 21px; margin: 0; color: var(--muted); font-size: .82rem; }
.continuity-fieldset { margin: 0; padding: 11px; border: 1px solid var(--line); border-radius: 10px; }
.continuity-fieldset legend { padding: 0 4px; font-size: .86rem; font-weight: 900; }
.continuity-fieldset p { margin: 0 0 8px; color: var(--muted); font-size: .78rem; }
.continuity-list { display: grid; gap: 6px; }
.continuity-item { display: flex; align-items: flex-start; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); color: var(--ink); font-size: .8rem; cursor: pointer; }
.continuity-item input { margin-top: 3px; accent-color: var(--accent); }
.checklist-status { min-height: 20px; margin: 8px 0 0 !important; color: var(--muted); font-size: .78rem !important; }
.check-line { display: flex; align-items: flex-start; gap: 9px; padding: 11px 12px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: .84rem; cursor: pointer; }
.check-line input { margin-top: 3px; accent-color: var(--accent); }
.compose-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.primary-button, .secondary-button, .small-button { min-height: 42px; border: 1px solid transparent; border-radius: 10px; font-weight: 900; cursor: pointer; transition: transform .16s ease, box-shadow .16s ease, background .16s ease; }
.primary-button { padding: 9px 15px; background: var(--accent); color: white; box-shadow: 0 6px 14px rgba(23, 105, 224, .2); }
.secondary-button { padding: 8px 12px; border-color: var(--line-strong); background: var(--surface); color: var(--ink); }
.small-button { min-height: 32px; padding: 5px 9px; border-color: var(--line); background: var(--surface); color: var(--accent); font-size: .76rem; }
.primary-button:hover, .secondary-button:hover, .small-button:hover { transform: translateY(-1px); }
.primary-button:disabled, .secondary-button:disabled, .small-button:disabled { transform: none; cursor: not-allowed; opacity: .55; }
.status-text { color: var(--muted); font-size: .82rem; font-weight: 850; }
.status-text[data-tone="success"] { color: var(--success); }
.status-text[data-tone="danger"] { color: var(--danger); }
.status-text[data-tone="busy"] { color: var(--accent); }
.gi-pulse { animation: gi-pulse 2.2s ease-in-out infinite; }
@keyframes gi-pulse { 0%, 100% { box-shadow: 0 6px 14px rgba(23, 105, 224, .2); } 50% { box-shadow: 0 0 0 7px rgba(23, 105, 224, .12), 0 8px 18px rgba(23, 105, 224, .28); } }

.visual-panel { display: grid; align-content: start; gap: 10px; }
.scene-stage { min-height: 290px; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: #eaf1fa; text-align: center; }
.scene-stage__image { width: 100%; height: 290px; object-fit: cover; }
.scene-state { max-width: 270px; padding: 20px; color: var(--muted); }
.scene-state strong, .scene-state span { display: block; }
.scene-state strong { color: var(--ink); font-size: 1.05rem; }
.scene-state span { margin-top: 7px; font-size: .84rem; line-height: 1.55; }
.scene-state--loading::before { content: ""; display: block; width: 28px; height: 28px; margin: 0 auto 14px; border: 3px solid #c8d8ef; border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.scene-state--failed { color: var(--danger); }
.scene-state--failed strong { color: var(--danger); }
.scene-actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.scene-caption { margin: 0; color: var(--muted); font-size: .78rem; }

.teacher-panel { margin: 20px 0; }
.teacher-panel[hidden], .workspace-grid[hidden] { display: none; }
.review-list, .timeline-list, .book-preview-list { display: grid; gap: 10px; margin: 14px 0 0; padding: 0; list-style: none; }
.review-item, .timeline-item { padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.review-item p, .timeline-item p { margin: 8px 0 0; line-height: 1.55; word-break: keep-all; }
.review-item__actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; }
.review-empty { margin: 14px 0 0; padding: 16px; color: var(--muted); background: var(--success-soft); border-radius: 10px; }

.timeline-layout { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(280px, .95fr); gap: 20px; margin-top: 20px; }
.timeline-item { display: grid; grid-template-columns: 70px 1fr; gap: 12px; }
.timeline-stamp { color: var(--accent); font-size: .76rem; font-weight: 900; }
.timeline-copy { min-width: 0; }
.timeline-copy .status-badge { margin-top: 8px; }
.reflection-panel { padding: 16px; background: var(--success-soft); border-radius: 12px; }
.reflection-panel h3 { margin: 0; font-size: 1rem; }
.reflection-panel p { margin: 6px 0 12px; color: var(--muted); font-size: .83rem; }
.reflection-input { min-height: 106px; padding: 11px; resize: vertical; background: var(--surface); }
.book-preview { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); }
.book-preview-list { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.book-preview-item { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.book-preview-item img { width: 100%; height: 110px; object-fit: cover; border-radius: 8px; background: #eaf1fa; }
.book-preview-item p { margin: 8px 0 0; font-size: .88rem; line-height: 1.5; }
.export-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

dialog { width: min(620px, calc(100% - 32px)); border: 1px solid var(--line-strong); border-radius: 16px; padding: 0; color: var(--ink); box-shadow: 0 24px 70px rgba(38, 52, 73, .25); }
dialog::backdrop { background: rgba(38, 52, 73, .32); }
.dialog-content { padding: 24px; }
.dialog-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.dialog-header h2 { margin: 0; font-size: 1.25rem; }
.dialog-close { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-weight: 900; }
.history-list { display: grid; gap: 12px; margin: 20px 0 0; padding: 0; list-style: none; }
.history-list li { padding-left: 14px; border-left: 3px solid var(--accent); }
.history-list strong, .history-list span { display: block; }
.history-list strong { font-size: .92rem; }
.history-list span { margin-top: 3px; color: var(--muted); font-size: .84rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  .setup-grid, .workspace-grid, .timeline-layout { grid-template-columns: 1fr; }
  .setup-grid { align-items: stretch; }
}

@media (max-width: 640px) {
  .app-shell { width: min(100% - 20px, 560px); padding-top: 14px; }
  .app-header { display: block; }
  .header-actions { justify-content: flex-start; margin-top: 14px; }
  .brand-title { font-size: 1.9rem; }
  .orientation-band { display: block; padding: 18px; }
  .activity-meta { margin-top: 18px; }
  .progress-area { margin-top: 18px; }
  .progress-copy { display: block; }
  .progress-copy span { display: block; }
  .progress-copy span + span { margin-top: 4px; }
  .workspace-section, .story-section, .panel { padding: 16px; }
  .story-grid { grid-template-columns: 1fr; }
  .story-card__media, .story-card__media img { min-height: 170px; height: 170px; }
  .support-groups { grid-template-columns: 1fr; }
  .scene-stage, .scene-stage__image { min-height: 230px; height: 230px; }
  .timeline-item { grid-template-columns: 54px 1fr; }
  .primary-button { width: 100%; }
  .compose-actions { align-items: stretch; }
}

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