:root {
  color-scheme: light;
  --bg: #f3f5f6;
  --ink: #1f2528;
  --muted: #667077;
  --line: #dbe1e4;
  --panel: #ffffff;
  --accent: #2f6f73;
  --accent-dark: #234f52;
  --accent-hover: #234f52;
  --warm: #b85c38;
  --soft: #e9f0ee;
  --shadow: none;
  --lyric-bg: #f3f8f7;
  --badge-bg: #f4e8df;
  --badge-ink: #7d3f27;
  --note-bg: #edf5f5;
  --note-border: #cfdfdf;
  --note-ink: #355052;
  --note-strong: #235d60;
  --danger: #8b3219;
  --focus: #4ca49e;
  --scene-edge: #8bb7b2;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #181c1d;
  --ink: #ecf0ee;
  --muted: #aebbb7;
  --line: #485451;
  --panel: #222829;
  --accent: #286e67;
  --accent-hover: #327e75;
  --accent-dark: #a1ded2;
  --warm: #edac88;
  --soft: #293532;
  --lyric-bg: #24312f;
  --badge-bg: #3e3027;
  --badge-ink: #f0bf98;
  --note-bg: #243430;
  --note-border: #48625a;
  --note-ink: #c4d8d0;
  --note-strong: #b0e0d0;
  --danger: #ffb09b;
  --focus: #82d4c0;
  --scene-edge: #5c9d8b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    "Yu Gothic UI", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
  line-height: 1.6;
}

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

.app {
  min-height: 100vh;
  padding: 28px;
}

.workspace {
  max-width: 1500px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--warm);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 0;
  border-radius: 0;
  box-shadow: var(--shadow);
}

.input-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
}

label {
  display: grid;
  gap: 7px;
}

label span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 260px;
  padding: 12px;
  resize: vertical;
}

.input-panel textarea#reviewFocus {
  min-height: 92px;
}

input,
select {
  min-height: 42px;
  padding: 8px 10px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 115, 0.16);
}

.grid {
  display: grid;
  gap: 12px;
}

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

.primary-button,
.ghost-button,
.tab {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-hover);
}

.ghost-button {
  background: var(--panel);
  border-color: var(--line);
  color: var(--ink);
  padding: 8px 12px;
}

.ghost-button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.output-panel {
  min-height: 720px;
  padding: 14px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.tab {
  background: var(--soft);
  color: var(--muted);
}

.tab.active {
  background: var(--accent);
  color: #fff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.empty {
  min-height: 260px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 24px;
}

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

.scene-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel);
}

.scene-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.scene-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.tool-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 4px 9px;
}

.tool-button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.tool-button.danger:hover {
  border-color: #b85c38;
  color: var(--danger);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--badge-ink);
  padding: 2px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.lyric {
  margin: 0 0 10px;
  padding-left: 10px;
  border-left: 3px solid var(--accent);
  white-space: pre-wrap;
}

.details {
  display: grid;
  gap: 8px;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.details label {
  gap: 5px;
}

.details textarea {
  min-height: 72px;
  padding: 9px;
  font-size: 0.92rem;
}

.details textarea.tall {
  min-height: 104px;
}

.details p,
.prompt-box p {
  margin: 0;
}

.details strong {
  color: var(--accent-dark);
}

.story-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  font-size: 0.92rem;
}

.story-table th,
.story-table td {
  border: 1px solid var(--line);
  padding: 9px;
  vertical-align: top;
}

.story-table th {
  background: var(--soft);
  text-align: left;
}

.prompt-box {
  min-height: 520px;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

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

.motif-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
}

.motif-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.motif-card p {
  margin: 0;
  color: var(--muted);
}

.motif-card ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.focus-list {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.focus-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
}

.focus-item strong {
  color: var(--accent-dark);
}

.focus-item p {
  margin: 6px 0 0;
}

.note-box {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  border: 1px solid #e0c8b8;
  border-radius: 8px;
  background: #fff7f1;
  padding: 12px;
  color: #573827;
}

.note-box strong {
  color: #7d3f27;
}

.note-box p {
  margin: 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 14px;
}

[hidden] { display: none !important; }
.about-tool { margin: 0 0 24px; border-block: 1px solid var(--line); padding: 12px 0; font-size: 13px; }
.about-tool summary { cursor: pointer; color: var(--accent-dark); }
.about-content { max-width: 760px; line-height: 1.9; }
.release-label { display: inline-block; font-size: 11px; font-weight: normal; color: var(--muted); margin-left: 8px; }
.site-footer { padding: 24px 0 4px; margin-top: 32px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.footer-main { display: flex; justify-content: space-between; align-items: start; gap: 24px; flex-wrap: wrap; }
.footer-identity strong { color: var(--ink); font-size: 14px; }
.footer-site { display: block; margin-top: 6px; }
.site-footer a { color: var(--accent-dark); text-decoration: underline; text-underline-offset: 3px; }
.site-footer a:hover { color: var(--ink); }
.site-footer a:focus-visible, summary:focus-visible { outline: 3px solid #4ca49e; outline-offset: 4px; }
.footer-nav { display: flex; flex-wrap: wrap; gap: 10px 20px; }
.footer-nav a { display: inline-flex; align-items: center; min-height: 36px; }
.creator-footer { text-align: center; padding: 26px 0 8px; }
.creator-links { display: flex; justify-content: center; align-items: center; gap: 24px; flex-wrap: wrap; margin-bottom: 4px; }
.creator-links a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; color: var(--ink); font-size: 13px; font-weight: 700; text-decoration: none; }
.creator-links a:hover { text-decoration: underline; }
.creator-credit { font-size: 12px; color: var(--muted); }
.creator-details { margin-top: 8px; font-size: 11px; line-height: 1.9; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.footer-bottom { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 360px); gap: 16px 32px; border-top: 1px solid var(--line); margin-top: 18px; padding-top: 14px; }
.footer-bottom p { margin: 0; line-height: 1.9; }
.footer-privacy summary { cursor: pointer; color: var(--accent-dark); min-height: 28px; }
.footer-privacy p { margin-top: 8px; }
#about-tool, #top { scroll-margin-top: 16px; }
@media (max-width: 600px) {
  .footer-bottom { grid-template-columns: 1fr; }
  .footer-nav { gap: 4px 16px; }
}
.empty { background: var(--panel); }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
.input-panel { border-right: 1px solid var(--line); background: transparent; padding: 0 18px 0 0; }
.input-panel h2 { margin: 0; font-size: 16px; }
.input-panel .grid.two { grid-template-columns: 1fr; }
.input-panel textarea { min-height: 180px; }
.output-panel { background: transparent; padding: 0; min-width: 0; }
.project-actions, .editor-toolbar, .consult-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.project-actions { justify-content: flex-end; }
.editor-toolbar { justify-content: space-between; margin-bottom: 12px; min-height: 42px; }
.consult-controls { padding: 12px 0; margin-bottom: 12px; border-bottom: 1px solid var(--line); justify-content: space-between; }
.consult-controls label { flex: 1; max-width: 320px; }
.consult-controls button { padding: 10px 18px; }
#saveStatus, #sceneCount { font-size: 12px; color: var(--muted); }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible { outline: 3px solid #4ca49e; outline-offset: 3px; }
.tabs { border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.scene-card { padding: 18px; border-left: 3px solid var(--scene-edge); }
.scene-card label { margin-bottom: 8px; }
.scene-card textarea.lyric { min-height: 80px; padding: 10px; background: var(--lyric-bg); }
.scene-card .details textarea { min-height: 64px; }
.scene-card .details textarea.tall { min-height: 84px; }
.scene-tools { justify-content: flex-end; }
.scene-head { align-items: center; flex-wrap: wrap; }
.badge { white-space: normal; border-radius: 4px; }
#tableView { overflow-x: auto; }
.story-table { min-width: 760px; table-layout: fixed; }
.story-table th:first-child { width: 40px; }
.story-table th:nth-child(2) { width: 110px; }
.story-table td, .prompt-box, .focus-item, .motif-card { overflow-wrap: anywhere; }
.prompt-box { line-height: 1.9; font-size: 14px; }
.note-box { background: var(--note-bg); border-color: var(--note-border); color: var(--note-ink); }
.note-box strong { color: var(--note-strong); }
.theme-switch { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 2px; margin: 0; padding: 3px; border: 1px solid var(--line); border-radius: 6px; min-height: 42px; }
.theme-switch label { display: block; position: relative; cursor: pointer; }
.theme-switch input { position: absolute; opacity: 0; width: 1px; min-height: 0; height: 1px; margin: 0; padding: 0; }
.theme-switch span { display: block; padding: 5px 10px; min-width: 60px; text-align: center; border-radius: 3px; font-size: 12px; color: var(--muted); }
.theme-switch input:checked + span { color: #fff; background: var(--accent); }
.theme-switch input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.actions { border-top: 1px solid var(--line); padding-top: 12px; justify-content: flex-start; }
#copyPrompt, #copyMeeting, #copySolo, #copyMotifs, #copyChorus { display: none; }
@media (min-width: 921px) {
  .topbar { align-items: center; }
  .topbar .project-actions { max-width: 55%; }
}

@media (max-width: 920px) {
  .app {
    padding: 18px;
  }

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

  .layout,
  .grid.two {
    grid-template-columns: 1fr;
  }

  .output-panel {
    min-height: auto;
  }

  .actions {
    flex-direction: column;
  }

  .tabs,
  .mini-grid,
  .motif-grid {
    grid-template-columns: 1fr;
  }
  .input-panel { padding: 0 0 20px; border: 0; border-bottom: 1px solid var(--line); }
  .tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tab { padding: 8px 4px; font-size: 12px; overflow-wrap: anywhere; }
  .actions { flex-direction: row; }
  .topbar .project-actions { justify-content: flex-start; }
  h1 { font-size: 21px; }
}
