:root {
  --forest-950: #071a16;
  --forest-900: #0c2720;
  --forest-800: #14392f;
  --forest-700: #1e4a3c;
  --cream-50: #fffdf7;
  --cream-100: #fbf6e9;
  --cream-200: #f2ead8;
  --cream-300: #e3d5b9;
  --brass-300: #d7b676;
  --brass-500: #b88843;
  --brass-700: #805b26;
  --ink: #18231f;
  --muted: #68766e;
  --danger: #a4382d;
  --success: #27654f;
  --canvas: #ece6d8;
  --panel: rgba(255, 253, 247, 0.94);
  --panel-border: rgba(19, 57, 47, 0.14);
  --shadow: 0 18px 55px rgba(9, 35, 27, 0.13);
  color-scheme: light;
}

body[data-theme="dark"] {
  --ink: #f7f0df;
  --muted: #b4c0b5;
  --canvas: #071713;
  --panel: rgba(14, 43, 34, 0.96);
  --panel-border: rgba(220, 190, 125, 0.2);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  min-width: 320px;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 100% 0%, rgba(193, 153, 86, 0.12), transparent 28rem),
    var(--canvas);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Yu Gothic", YuGothic, Meiryo, sans-serif;
  line-height: 1.6;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
input[type="range"],
input[type="checkbox"] {
  touch-action: manipulation;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

:focus-visible {
  outline: 3px solid var(--brass-300);
  outline-offset: 3px;
}

.site-shell {
  min-height: 100vh;
}

.masthead {
  position: relative;
  isolation: isolate;
  min-height: 148px;
  overflow: hidden;
  color: var(--cream-50);
  background:
    linear-gradient(90deg, rgba(5, 22, 17, 0.94) 0%, rgba(9, 34, 27, 0.82) 53%, rgba(9, 34, 27, 0.62) 100%),
    url("./assets/stage-rehearsal.jpg") center 43% / cover;
  border-bottom: 1px solid rgba(220, 190, 125, 0.32);
}

.masthead::after {
  position: absolute;
  inset: 0;
  z-index: -1;
  content: "";
  background: linear-gradient(125deg, transparent 0 55%, rgba(226, 190, 112, 0.15) 70%, transparent 82%);
  pointer-events: none;
}

.masthead__content {
  width: min(1420px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 1.2rem;
}

.eyebrow,
.section-kicker {
  margin: 0;
  color: var(--brass-300);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.brand-row,
.panel-heading,
.stage-heading,
.control-group__heading,
.field-meta,
.progress-meta,
.button-row,
.toggle-grid {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-row {
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.35rem;
}

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

h1 {
  margin-bottom: 0.05rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 600;
  letter-spacing: -0.05em;
  line-height: 1;
}

h1 span {
  color: var(--brass-300);
  font-style: italic;
}

h2 {
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.4rem, 2vw, 1.85rem);
  font-weight: 600;
  line-height: 1.2;
}

h3 {
  margin-bottom: 0;
  font-size: 1rem;
}

.masthead__lead,
.masthead__privacy {
  margin-bottom: 0;
  color: rgba(255, 253, 247, 0.8);
}

.masthead__lead {
  font-size: 0.9rem;
}

.masthead__privacy {
  margin-top: 0.9rem;
  font-size: 0.76rem;
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.82fr) minmax(0, 1.18fr);
  gap: 1rem;
  width: min(1420px, calc(100% - 2rem));
  margin: 1rem auto 0;
}

.panel {
  min-width: 0;
  padding: clamp(1rem, 2vw, 1.6rem);
  border: 1px solid var(--panel-border);
  border-radius: 1.1rem;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.editor-panel {
  grid-row: span 2;
}

.panel-heading,
.stage-heading {
  justify-content: space-between;
  margin-bottom: 1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.8rem;
  padding: 0.15rem 0.65rem;
  border: 1px solid rgba(128, 91, 38, 0.28);
  border-radius: 999px;
  color: var(--brass-700);
  background: rgba(215, 182, 118, 0.18);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

body[data-theme="dark"] .badge {
  color: var(--brass-300);
}

.field-label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.88rem;
  font-weight: 800;
}

textarea {
  display: block;
  width: 100%;
  min-height: 14rem;
  resize: vertical;
  padding: 0.95rem 1rem;
  border: 1px solid var(--cream-300);
  border-radius: 0.7rem;
  color: var(--ink);
  background: color-mix(in srgb, var(--cream-50) 80%, transparent);
  font-size: 1rem;
  line-height: 1.75;
}

body[data-theme="dark"] textarea {
  border-color: rgba(215, 182, 118, 0.33);
  background: rgba(3, 19, 15, 0.55);
}

textarea::placeholder {
  color: var(--muted);
  opacity: 0.9;
}

.field-meta,
.progress-meta {
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.74rem;
}

.field-meta {
  margin-top: 0.45rem;
}

.field-meta output {
  color: var(--brass-700);
  font-weight: 800;
}

body[data-theme="dark"] .field-meta output {
  color: var(--brass-300);
}

.field-error {
  margin: 0.55rem 0 0;
  padding: 0.55rem 0.7rem;
  border-left: 3px solid var(--danger);
  color: var(--danger);
  background: rgba(164, 56, 45, 0.08);
  font-size: 0.86rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: 0.9rem;
}

.stat-card {
  min-width: 0;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--panel-border);
  border-radius: 0.65rem;
  background: rgba(226, 213, 185, 0.18);
}

.stat-card--wide {
  grid-column: span 2;
}

.stat-card__label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}

.stat-card strong {
  display: block;
  margin-top: 0.15rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.15rem;
  font-weight: 600;
}

.control-group {
  margin-top: 1.3rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--panel-border);
}

.control-group__heading {
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.8rem;
}

.session-status,
.control-hint {
  color: var(--muted);
  font-size: 0.73rem;
}

.session-status {
  text-align: right;
}

.button-row {
  flex-wrap: wrap;
}

.button {
  min-height: 2.75rem;
  padding: 0.55rem 0.9rem;
  border: 1px solid transparent;
  border-radius: 0.55rem;
  font-size: 0.84rem;
  font-weight: 800;
  line-height: 1.15;
  transition: transform 150ms ease, background-color 150ms ease, border-color 150ms ease;
}

.button:not(:disabled):hover {
  transform: translateY(-1px);
}

.button--brass {
  border-color: var(--brass-500);
  color: #201a10;
  background: var(--brass-300);
}

.button--brass:hover {
  background: #e2c789;
}

.button--secondary {
  border-color: var(--panel-border);
  color: var(--ink);
  background: rgba(255, 253, 247, 0.32);
}

body[data-theme="dark"] .button--secondary {
  background: rgba(3, 19, 15, 0.35);
}

.button--outline {
  border-color: var(--brass-500);
  color: var(--brass-700);
  background: transparent;
}

body[data-theme="dark"] .button--outline {
  color: var(--brass-300);
}

.button--ghost {
  border-color: rgba(255, 253, 247, 0.38);
  color: var(--cream-50);
  background: rgba(3, 19, 15, 0.35);
}

.button--text {
  min-height: 2.2rem;
  padding-inline: 0.3rem;
  color: var(--brass-700);
  background: transparent;
  text-decoration: underline;
  text-decoration-color: rgba(128, 91, 38, 0.35);
  text-underline-offset: 0.18em;
}

body[data-theme="dark"] .button--text {
  color: var(--brass-300);
}

.button--compact {
  min-height: 2.35rem;
  padding: 0.42rem 0.72rem;
  font-size: 0.76rem;
}

.full-width {
  width: 100%;
  margin-top: 0.65rem;
}

.range-control {
  display: block;
  margin-top: 0.85rem;
}

.range-control > span {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.range-control output {
  color: var(--ink);
  font-weight: 800;
}

input[type="range"] {
  display: block;
  width: 100%;
  height: 2rem;
  margin: 0.12rem 0 0;
  accent-color: var(--brass-500);
}

.toggle-grid {
  justify-content: space-between;
  flex-wrap: wrap;
  margin-top: 0.85rem;
}

.toggle-control {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.75rem;
  color: var(--ink);
  font-size: 0.83rem;
  cursor: pointer;
}

.toggle-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.toggle-control__box {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 2.6rem;
  height: 1.5rem;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(104, 118, 110, 0.23);
  transition: background-color 150ms ease;
}

.toggle-control__box::after {
  position: absolute;
  top: 0.18rem;
  left: 0.2rem;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  content: "";
  background: var(--cream-50);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 150ms ease;
}

.toggle-control input:checked + .toggle-control__box {
  border-color: var(--brass-500);
  background: var(--brass-500);
}

.toggle-control input:checked + .toggle-control__box::after {
  transform: translateX(1.05rem);
}

.toggle-control input:focus-visible + .toggle-control__box {
  outline: 3px solid var(--brass-300);
  outline-offset: 3px;
}

.save-status {
  min-height: 1.4rem;
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.save-status[data-state="saving"] {
  color: var(--brass-700);
  font-weight: 800;
}

.save-status[data-state="success"] {
  color: var(--success);
  font-weight: 700;
}

.save-status[data-state="error"] {
  color: var(--danger);
  font-weight: 700;
}

body[data-theme="dark"] .save-status[data-state="saving"] {
  color: var(--brass-300);
}

.stage-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.stage-heading {
  margin-bottom: 0.8rem;
}

.progress-meta {
  margin-bottom: 0.35rem;
}

.progress-track {
  height: 0.38rem;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(104, 118, 110, 0.2);
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--forest-700), var(--brass-500));
  transition: width 100ms linear;
}

.prompt-stage {
  position: relative;
  height: min(64vh, 690px);
  min-height: 24rem;
  margin-top: 0.85rem;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid rgba(128, 91, 38, 0.28);
  border-radius: 0.8rem;
  color: var(--forest-950);
  background:
    linear-gradient(90deg, rgba(255, 252, 239, 0.96), rgba(248, 238, 211, 0.96)),
    repeating-linear-gradient(0deg, rgba(128, 91, 38, 0.07) 0 1px, transparent 1px 2.2rem);
  scrollbar-color: var(--brass-500) rgba(128, 91, 38, 0.12);
}

body[data-theme="dark"] .prompt-stage {
  color: #f7f0df;
  background:
    linear-gradient(90deg, rgba(17, 47, 37, 0.98), rgba(13, 39, 31, 0.98)),
    repeating-linear-gradient(0deg, rgba(215, 182, 118, 0.07) 0 1px, transparent 1px 2.2rem);
}

.prompt-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(25rem, calc(100% - 3rem));
  transform: translate(-50%, -50%);
  color: var(--forest-700);
  text-align: center;
}

body[data-theme="dark"] .prompt-empty {
  color: var(--brass-300);
}

.prompt-empty__mark {
  display: block;
  margin-bottom: 0.7rem;
  color: var(--brass-500);
  font-size: 2.2rem;
}

.prompt-empty strong {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.55rem;
  font-weight: 600;
}

.prompt-empty p {
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.prompt-copy {
  display: none;
  min-height: 100%;
  padding: 4.5rem var(--prompt-margin, 4.5rem);
}

.prompt-copy.has-script {
  display: block;
}

.prompt-paragraph {
  position: relative;
  margin: 0 auto 5rem;
  max-width: 52rem;
}

.paragraph-time {
  display: block;
  margin-bottom: 1rem;
  color: var(--brass-700);
  font-size: 0.77rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

body[data-theme="dark"] .paragraph-time {
  color: var(--brass-300);
}

.paragraph-text {
  margin: 0;
  font-family: Georgia, "Hiragino Mincho ProN", "Yu Mincho", YuMincho, serif;
  font-size: var(--prompt-size, 56px);
  line-height: var(--prompt-leading, 1.65);
  letter-spacing: 0.015em;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
  transform-origin: center;
}

.paragraph-text.is-mirrored {
  transform: scaleX(-1);
}

.stage-note {
  margin: 0.65rem 0 0;
  color: var(--muted);
  font-size: 0.73rem;
}

.history-panel {
  grid-column: 2;
}

.history-intro {
  margin: -0.35rem 0 0.9rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.history-list {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-item,
.history-empty {
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--panel-border);
  border-radius: 0.55rem;
  background: rgba(226, 213, 185, 0.12);
}

.history-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
}

.history-item strong {
  font-size: 0.82rem;
}

.history-item span,
.history-empty {
  color: var(--muted);
  font-size: 0.76rem;
}

.history-empty {
  text-align: center;
}

.site-footer {
  width: min(1420px, calc(100% - 2rem));
  margin: 1rem auto 0;
  padding: 0.4rem 0 1.6rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.site-footer details {
  padding: 0.8rem 0;
  border-top: 1px solid var(--panel-border);
}

.site-footer summary {
  color: var(--brass-700);
  cursor: pointer;
  font-weight: 800;
}

body[data-theme="dark"] .site-footer summary {
  color: var(--brass-300);
}

.footer-details {
  max-width: 70rem;
  padding-top: 0.75rem;
}

.footer-details p {
  margin-bottom: 0.55rem;
}

.site-footer > p {
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
}

.print-sheet {
  display: none;
}

@media (max-width: 900px) {
  .button--compact,
  .button--text {
    min-height: 2.75rem;
  }

  .app-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .editor-panel,
  .history-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .stage-panel {
    order: 2;
  }

  .history-panel {
    order: 3;
  }
}

@media (max-width: 520px) {
  .masthead__content,
  .app-layout,
  .site-footer {
    width: min(100% - 1rem, 1420px);
  }

  .masthead {
    min-height: 154px;
  }

  .masthead__content {
    padding-top: 1.1rem;
  }

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

  .brand-row .button {
    max-width: 7.4rem;
    white-space: normal;
  }

  .masthead__privacy {
    max-width: 32rem;
    margin-top: 0.7rem;
  }

  .panel {
    padding: 0.9rem;
    border-radius: 0.85rem;
  }

  .control-group__heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.15rem;
  }

  .session-status {
    text-align: left;
  }

  .prompt-stage {
    height: 54vh;
    min-height: 20rem;
  }

  .prompt-copy {
    padding-right: max(1.25rem, var(--prompt-margin, 4.5rem));
    padding-left: max(1.25rem, var(--prompt-margin, 4.5rem));
  }

  .prompt-paragraph {
    margin-bottom: 3.5rem;
  }

  .paragraph-text {
    font-size: max(32px, var(--prompt-size, 56px));
  }

  .history-item {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.15rem;
  }
}

@media (max-width: 350px) {
  .brand-row {
    gap: 0.45rem;
  }

  h1 {
    font-size: 1.85rem;
  }

  .button-row--primary .button {
    flex: 1 1 100%;
  }

  .prompt-copy {
    padding-inline: 1.25rem;
  }
}

@media print {
  @page {
    margin: 16mm;
  }

  body {
    min-width: 0;
    background: #fff;
    color: #111;
  }

  .site-shell {
    display: none !important;
  }

  .print-sheet {
    display: block;
    color: #111;
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Yu Gothic", YuGothic, Meiryo, sans-serif;
  }

  .print-sheet h1 {
    margin: 0 0 0.3rem;
    color: #111;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 24pt;
  }

  .print-summary {
    margin-bottom: 1.8rem;
    color: #555;
    font-size: 9pt;
  }

  .print-paragraph {
    margin: 0 0 1.3rem;
    break-inside: avoid;
  }

  .print-paragraph__time {
    margin-bottom: 0.25rem;
    color: #805b26;
    font-size: 9pt;
    font-weight: 700;
  }

  .print-paragraph__text {
    margin: 0;
    font-family: Georgia, "Hiragino Mincho ProN", "Yu Mincho", YuMincho, serif;
    font-size: 15pt;
    line-height: 1.8;
    white-space: pre-wrap;
  }
}

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


/* SOU100 Stage A: compact first view */
.masthead h1 { word-break: auto-phrase; }
ol.firstview-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin: 12px 0; padding: 0; list-style: none; counter-reset: fv-step; }
.firstview-steps li { min-width: 0; display: flex; align-items: center; gap: 8px; padding: 7px 9px; border: 1px solid rgba(220, 190, 125, .28); border-radius: 9px; color: var(--cream-50); background: rgba(5, 22, 17, .28); font-size: 12px; line-height: 1.35; }
.firstview-steps li::before { counter-increment: fv-step; content: counter(fv-step); display: grid; flex: 0 0 20px; height: 20px; place-items: center; border-radius: 50%; color: #1d241f; background: #f7e3ad; font-size: 11px; font-weight: 800; }
.firstview-cta { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; padding: 9px 14px; border: 1px solid rgba(25, 35, 28, .25); border-radius: 8px; color: #1d241f; background: #f7e3ad; font-size: 14px; font-weight: 800; text-decoration: none; }
.firstview-cta:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
@media (max-width: 640px) {
  .masthead { min-height: 0; background: linear-gradient(90deg, #051611, #09221b); }
  .masthead__content { padding: 14px 0 12px; }
  .brand-row { gap: .65rem; }
  .brand-row > div { min-width: 0; flex: 1; }
  .brand-row h1 { margin-bottom: 6px; font-size: clamp(1.2rem, 5.6vw, 1.45rem); line-height: 1.1; letter-spacing: -.03em; }
  .masthead__lead { font-size: .82rem; line-height: 1.4; }
  ol.firstview-steps { grid-template-columns: 1fr; gap: 3px; margin: 8px 0; }
  .firstview-steps li { padding: 3px 0; border: 0; background: transparent; font-size: 12px; }
  .firstview-steps li::before { flex-basis: 18px; height: 18px; font-size: 10px; }
  .firstview-cta { min-height: 40px; padding: 8px 12px; font-size: 13px; }
  .masthead__privacy { margin-top: 8px; font-size: .68rem; line-height: 1.4; }
  .editor-panel { padding: 14px; }
  .editor-panel > .panel-heading { gap: 8px; margin-bottom: 12px; }
  .editor-panel > .panel-heading .section-kicker { display: none; }
  .editor-panel > .panel-heading h2 { margin: 0; font-size: 1.15rem; }
}
