:root {
  color-scheme: light;
  --bg: #f5f7f3;
  --panel: #ffffff;
  --ink: #213038;
  --muted: #5e6d75;
  --line: #d8e1df;
  --green: #2f7766;
  --green-dark: #225b4e;
  --blue: #306c9a;
  --coral: #d77b5f;
  --yellow: #f1c65d;
  --paper: #fffdf7;
  --shadow: 0 14px 30px rgb(33 48 56 / 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgb(47 119 102 / 0.13), transparent 32%),
    linear-gradient(315deg, rgb(215 123 95 / 0.14), transparent 36%),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
}

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

button {
  touch-action: manipulation;
}

textarea {
  resize: vertical;
}

.app-shell {
  width: min(1220px, 100%);
  margin: 0 auto;
  padding: 18px clamp(12px, 2.8vw, 28px) 28px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.eyebrow,
h1,
h2,
h3,
p {
  margin: 0;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--green-dark);
  font-size: clamp(0.9rem, 1.2vw, 1rem);
  font-weight: 800;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.3rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: clamp(1.12rem, 2vw, 1.42rem);
  letter-spacing: 0;
}

h3 {
  font-size: clamp(1.5rem, 3vw, 2.4rem);
  line-height: 1.2;
  letter-spacing: 0;
}

.header-actions,
.insert-row,
.story-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.header-actions {
  justify-content: flex-end;
}

.small-button,
.action-button,
.insert-button {
  min-height: 48px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.small-button {
  min-width: 112px;
  padding: 0 14px;
}

.small-button.accent {
  border-color: #c78f22;
  background: var(--yellow);
  color: #3b2b08;
}

.action-button {
  min-width: 128px;
  padding: 0 18px;
  font-size: 1.02rem;
}

.action-button.primary,
.action-button.wide {
  border-color: var(--green-dark);
  background: var(--green);
  color: #fff;
}

.action-button.wide {
  width: 100%;
}

.insert-button {
  min-width: 76px;
  padding: 0 12px;
}

.privacy-note {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid #e5d1ba;
  border-radius: 8px;
  background: #fff8ec;
  color: #624923;
  font-size: 0.95rem;
  font-weight: 700;
}

.workspace,
.note-grid {
  display: grid;
  gap: 14px;
}

.workspace {
  grid-template-columns: minmax(320px, 0.82fr) minmax(420px, 1.18fr);
  align-items: start;
}

.note-grid {
  grid-template-columns: minmax(320px, 0.76fr) minmax(420px, 1.24fr);
  margin-top: 14px;
}

.panel {
  min-width: 0;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgb(255 255 255 / 0.96);
  box-shadow: var(--shadow);
  padding: 16px;
}

.section-head,
.story-toolbar {
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 800;
}

.field input,
.field select,
.field textarea,
.db-input input,
.check-row textarea {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.field input,
.field select,
.db-input input {
  min-height: 48px;
  padding: 0 12px;
}

.field textarea,
.check-row textarea {
  padding: 10px 12px;
  line-height: 1.65;
}

.insert-row {
  margin: 4px 0 12px;
}

.story-toolbar {
  margin-bottom: 12px;
}

.db-input {
  display: grid;
  grid-template-columns: auto 88px auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 900;
}

.db-input input {
  text-align: right;
}

.story-sheet {
  min-height: 520px;
  border: 2px solid #e8dfcb;
  border-radius: 8px;
  background: var(--paper);
  padding: clamp(16px, 3vw, 28px);
}

.story-sheet-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  align-items: start;
  gap: 12px;
  margin-bottom: 20px;
}

.db-badge {
  display: grid;
  place-items: center;
  min-height: 104px;
  border: 2px solid var(--blue);
  border-radius: 8px;
  background: #eef7ff;
  color: var(--blue);
  font-weight: 900;
  text-align: center;
}

.db-badge strong {
  color: var(--ink);
  font-size: 2rem;
  line-height: 1;
}

.story-output {
  display: grid;
  gap: 14px;
  font-size: clamp(1.24rem, 2vw, 1.68rem);
  line-height: 2;
}

.story-line {
  display: block;
}

.breath-mark,
.note-mark {
  display: inline-flex;
  align-items: center;
  min-height: 1.4em;
  margin: 0 0.12em;
  padding: 0 0.28em;
  border-radius: 6px;
  font-weight: 900;
}

.breath-mark {
  background: #e3f3ef;
  color: var(--green-dark);
}

.note-mark {
  background: #fff0da;
  color: #87520f;
  font-size: 0.82em;
}

.check-list {
  display: grid;
  gap: 10px;
}

.check-row {
  display: grid;
  grid-template-columns: 30px minmax(140px, 220px) minmax(180px, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 78px;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 900;
}

.check-row input {
  width: 24px;
  height: 24px;
  accent-color: var(--green);
}

.status-text {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
  min-height: 1.4em;
  text-align: right;
}

@media (max-width: 880px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .workspace,
  .note-grid {
    grid-template-columns: 1fr;
  }

  .story-sheet {
    min-height: 420px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding-top: 14px;
  }

  .small-button,
  .action-button {
    flex: 1 1 130px;
  }

  .story-sheet-head,
  .check-row {
    grid-template-columns: 1fr;
  }

  .db-badge {
    min-height: 92px;
  }

  .db-input {
    grid-template-columns: auto minmax(80px, 1fr) auto;
    width: 100%;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .header-actions,
  .privacy-note,
  .editor-panel,
  .story-toolbar,
  .status-text {
    display: none;
  }

  .workspace,
  .note-grid {
    display: block;
  }

  .panel,
  .story-sheet {
    box-shadow: none;
    break-inside: avoid;
  }

  .story-panel {
    border: 0;
    padding: 0;
  }

  .story-sheet {
    min-height: auto;
    margin-bottom: 12px;
  }

  .note-grid .panel {
    margin-bottom: 12px;
  }
}

/* LiNest v3: 印刷面と訓練マーカーを保ち、編集画面の外枠を統一する。 */
body.linest-themed {
  --bg: var(--linest-bg);
  --panel: var(--linest-surface);
  --ink: var(--linest-text);
  --muted: var(--linest-muted);
  --line: var(--linest-border);
  --green: var(--linest-green);
  --green-dark: var(--linest-green-dark);
  --coral: var(--linest-warm);
  --shadow: var(--linest-shadow);
}

body.linest-themed .app-header {
  padding: 16px 18px;
  border: 1px solid var(--linest-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--linest-shadow);
}

body.linest-themed .panel {
  border-color: var(--linest-border);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--linest-shadow);
}

body.linest-themed :where(.small-button, .action-button, .insert-button, .field input, .field select, .field textarea, .db-input input, .check-row textarea, .check-row) {
  border-color: var(--linest-border);
  background-color: #ffffff;
  color: var(--linest-text);
}

body.linest-themed .privacy-note {
  border-color: #eadcc7;
  background: #fffaf1;
  color: #6a4c2d;
}

body.linest-themed .small-button.accent {
  border-color: var(--linest-terracotta);
  background: #f7e9df;
  color: var(--linest-terracotta-dark);
}

@media (max-width: 560px) {
  body.linest-themed :where(.small-button, .action-button, .insert-button) {
    min-width: 0;
    white-space: normal;
    word-break: keep-all;
  }

  body.linest-themed .insert-button {
    flex: 1 1 92px;
  }
}

@media print {
  body.linest-themed .app-header,
  body.linest-themed .panel {
    border-color: #d8d8d8;
    background: #ffffff;
    box-shadow: none;
  }
}
