:root {
  --ink: #24313a;
  --muted: #64737d;
  --paper: #fffdf8;
  --surface: #ffffff;
  --soft: #f3f6f3;
  --line: #d8e0dc;
  --brand: #376858;
  --brand-dark: #244b3f;
  --brand-soft: #e7f1ec;
  --accent: #b46b34;
  --danger: #a33a32;
  --warning: #8a641f;
  --shadow: 0 10px 30px rgba(35, 55, 47, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  font-size: 18px;
  line-height: 1.75;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
a { color: var(--brand-dark); }

.app-shell { min-height: 100vh; }
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-inner {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 24px;
}
.brand strong { display: block; font-size: 1.12rem; }
.brand small { color: var(--muted); display: block; font-size: .72rem; }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.container { width: min(1040px, calc(100% - 32px)); margin: 32px auto 80px; }
.step-nav {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 28px;
}
.step-button {
  min-height: 62px;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: .72rem;
  line-height: 1.35;
}
.step-button span { display: block; font-weight: 800; font-size: .8rem; }
.step-button.active { border-color: var(--brand); background: var(--brand); color: white; }
.step-button.done { border-color: #8db2a4; background: var(--brand-soft); color: var(--brand-dark); }

.screen { display: none; }
.screen.active { display: block; }
.screen-header { margin-bottom: 24px; }
.eyebrow { color: var(--brand); font-size: .75rem; font-weight: 800; letter-spacing: .08em; }
h1, h2, h3, h4 { line-height: 1.4; margin-top: 0; }
h1 { font-size: clamp(1.65rem, 3vw, 2.25rem); }
h2 { font-size: clamp(1.45rem, 2.5vw, 1.9rem); margin-bottom: 8px; }
h3 { font-size: 1.15rem; }
.lead { color: var(--muted); margin: 0; max-width: 760px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(20px, 4vw, 36px);
  margin-bottom: 22px;
}
.panel-flat { padding: 22px 0; border-top: 1px solid var(--line); }
.section-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-title p { margin: 4px 0 0; color: var(--muted); font-size: .88rem; }

.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.choice-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choice-card {
  text-align: left;
  min-height: 104px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  padding: 16px;
  transition: .15s ease;
}
.choice-card:hover { border-color: #91ac9f; background: #fbfdfc; }
.choice-card.selected { border-color: var(--brand); background: var(--brand-soft); }
.choice-card strong { display: block; margin-bottom: 4px; }
.choice-card small { display: block; color: var(--muted); line-height: 1.55; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 750; }
.field-help { color: var(--muted); font-size: .78rem; margin: 0; }
.input, .select, .textarea {
  width: 100%;
  min-height: 52px;
  border: 1px solid #b9c6c0;
  border-radius: 10px;
  padding: 11px 13px;
  background: var(--surface);
  color: var(--ink);
}
.textarea { min-height: 130px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 3px solid rgba(55,104,88,.18); border-color: var(--brand); }
.required-mark { color: var(--danger); font-size: .75rem; }

.button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 16px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 750;
}
.button:hover { background: var(--soft); }
.button.primary { background: var(--brand); border-color: var(--brand); color: white; }
.button.primary:hover { background: var(--brand-dark); }
.button.accent { background: var(--accent); border-color: var(--accent); color: white; }
.button.danger { color: var(--danger); border-color: #e4bbb7; background: #fff9f8; }
.button.ghost { border-color: transparent; background: transparent; }
.button.small { min-height: 40px; padding: 6px 11px; font-size: .78rem; }
.button.block { width: 100%; }
.screen-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 26px; }
.inline-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.notice {
  border-left: 5px solid var(--brand);
  background: var(--brand-soft);
  padding: 14px 16px;
  border-radius: 8px;
  margin-bottom: 18px;
}
.notice.warning { border-left-color: #bc8932; background: #fff6df; }
.notice.error { border-left-color: var(--danger); background: #fff0ee; color: #7f2e28; }
.notice p { margin: 0; }
.status { min-height: 26px; color: var(--muted); font-size: .82rem; }
.status.busy { color: var(--brand-dark); font-weight: 750; }
.empty-state { text-align: center; color: var(--muted); padding: 34px 16px; border: 1px dashed #b7c4be; border-radius: 12px; }

.timeline-list, .card-list, .chapter-list { display: grid; gap: 14px; }
.timeline-item, .memory-card, .episode-card, .chapter-card {
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  padding: 17px;
}
.timeline-item { display: grid; grid-template-columns: 130px 1fr auto; gap: 15px; align-items: start; }
.timeline-time { font-weight: 850; color: var(--brand-dark); }
.timeline-item h4, .memory-card h4, .episode-card h4, .chapter-card h4 { margin: 0 0 6px; }
.timeline-item p, .memory-card p, .episode-card p, .chapter-card p { margin: 4px 0; }
.meta { color: var(--muted); font-size: .76rem; }
.card-tools { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: .7rem;
  font-weight: 750;
}
.badge.private { background: #fff0ee; color: #8b342d; }

.prompt-toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.prompt-box { border: 1px solid var(--line); border-radius: 13px; background: var(--soft); padding: 18px; margin-bottom: 18px; }
.prompt-box strong { display: block; font-size: 1.08rem; }
.prompt-box p { color: var(--muted); margin: 5px 0 0; }

.group-block { margin-top: 28px; }
.group-block > h3 { padding-bottom: 8px; border-bottom: 2px solid var(--brand-soft); }
.accordion { border: 1px solid var(--line); border-radius: 13px; margin-bottom: 12px; overflow: hidden; }
.accordion summary { cursor: pointer; font-weight: 800; padding: 15px 17px; background: var(--soft); }
.accordion-body { padding: 18px; }

.theme-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.theme-card { border: 2px solid var(--line); border-radius: 13px; background: var(--surface); padding: 16px; text-align: left; }
.theme-card.selected { border-color: var(--brand); background: var(--brand-soft); }
.theme-card p { color: var(--muted); font-size: .82rem; }
.theme-evidence { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: .75rem; }

.chapter-card { display: grid; grid-template-columns: 54px 1fr auto; gap: 12px; align-items: start; }
.chapter-number { width: 44px; height: 44px; border-radius: 50%; background: var(--brand-soft); display: grid; place-items: center; font-weight: 850; color: var(--brand-dark); }

.story-paper {
  max-width: 780px;
  margin: 0 auto;
  background: white;
  border: 1px solid #e1ded6;
  box-shadow: 0 12px 36px rgba(50,45,35,.09);
  padding: clamp(24px, 6vw, 64px);
  color: #242321;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  line-height: 2;
}
.story-paper h1 { text-align: center; margin-bottom: 2em; }
.story-paper h2 { margin-top: 2.4em; border-bottom: 1px solid #aaa; padding-bottom: .35em; }
.story-paper p { text-indent: 1em; margin: 1em 0; }
.story-paper:empty::before { content: "自分史を作成すると、ここに原稿が表示されます。"; color: var(--muted); font-family: sans-serif; }

.quality-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 16px 0; }
.quality-cell { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.quality-cell strong { display: block; font-size: 1.25rem; color: var(--brand-dark); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(18,26,23,.55); display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-backdrop.open { display: flex; }
.modal { width: min(850px, 100%); max-height: 90vh; overflow: auto; background: var(--surface); border-radius: 16px; padding: 26px; }
.modal-header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }

.admin-links { text-align: center; margin-top: 36px; color: var(--muted); font-size: .78rem; }
.admin-links a { margin: 0 8px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

@media (max-width: 820px) {
  body { font-size: 17px; }
  .site-header { position: static; }
  .header-inner { padding: 12px 0; align-items: flex-start; }
  .step-nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .choice-grid.three, .theme-grid { grid-template-columns: 1fr 1fr; }
  .timeline-item { grid-template-columns: 105px 1fr; }
  .timeline-item .card-tools { grid-column: 1 / -1; justify-content: flex-start; }
  .chapter-card { grid-template-columns: 48px 1fr; }
  .chapter-card .card-tools { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 600px) {
  .container, .header-inner { width: min(100% - 20px, 1040px); }
  .brand small { display: none; }
  .header-actions .button:not(.always) { display: none; }
  .step-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .step-button { min-height: 50px; }
  .choice-grid, .choice-grid.three, .form-grid, .form-grid.three, .theme-grid, .quality-grid, .prompt-toolbar { grid-template-columns: 1fr; }
  .panel { padding: 19px 16px; }
  .timeline-item { grid-template-columns: 1fr; }
  .screen-nav { flex-direction: column-reverse; }
  .screen-nav .button { width: 100%; }
  .story-paper { margin-inline: -6px; }
}

@media print {
  body { background: white; }
  .site-header, .step-nav, .screen-header, .screen-nav, .no-print, .admin-links, .notice, .quality-grid { display: none !important; }
  .container { width: 100%; margin: 0; }
  .screen { display: none !important; }
  #screen-7 { display: block !important; }
  .panel { border: 0; box-shadow: none; padding: 0; }
  .story-paper { max-width: none; border: 0; box-shadow: none; padding: 0; }
  @page { size: A4; margin: 20mm; }
}
