:root {
  --ink: #172033;
  --ink-soft: #40506a;
  --muted: #718096;
  --rule: #9eacbd;
  --accent: #235a91;
  --accent-dark: #17456f;
  --accent-soft: #eef4fa;
  --paper: #fff;
  --screen: #e9edf2;
  --font: "Asta", "Noto Sans KR", "Noto Sans CJK KR", "Malgun Gothic", sans-serif;
  --writing-line: 6.6mm;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--screen);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { padding: 18px; }
button, input, textarea { font: inherit; }

.toolbar {
  position: sticky;
  top: 12px;
  z-index: 10;
  width: min(210mm, 100%);
  margin: 0 auto 14px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255,255,255,.96);
  border: 1px solid #d5dce5;
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(16,24,40,.09);
  backdrop-filter: blur(8px);
}

.toolbar__status { font-size: 12px; line-height: 1.4; color: var(--muted); }
.toolbar__actions { display: flex; gap: 8px; flex: 0 0 auto; }

.toolbar button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid #aeb9c7;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.toolbar button:hover { background: #f6f8fb; }
.toolbar button:disabled { opacity: .55; cursor: wait; }
.toolbar button.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.toolbar button.primary:hover { background: var(--accent-dark); }

.document { width: 210mm; margin: 0 auto; }

.sheet {
  width: 210mm;
  height: 297mm;
  margin: 0 0 18px;
  padding: 11mm 13mm 9mm;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  box-shadow: 0 12px 36px rgba(16,24,40,.16);
  overflow: hidden;
}

.header,
.continuation-header {
  display: grid;
  grid-template-columns: minmax(0,1fr) 66mm;
  align-items: end;
  gap: 10mm;
  padding-bottom: 4mm;
  border-bottom: .45mm solid var(--ink);
}

.kicker {
  margin: 0 0 2mm;
  color: var(--accent);
  font-size: 8.5px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: .22em;
}

.document-title {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 2.2mm;
  font-size: 27px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: -.055em;
}

.record-no {
  width: 18mm;
  height: 9mm;
  padding: 0 1mm .5mm;
  border: 0;
  border-bottom: .35mm solid var(--ink);
  outline: none;
  background: transparent;
  color: inherit;
  text-align: center;
  font-size: 22px;
  font-weight: 800;
}

.writer-block {
  display: grid;
  grid-template-columns: 14mm minmax(0,1fr);
  align-items: end;
  gap: 2mm;
}

.writer-block label,
.field label,
.field-label {
  padding-bottom: 1mm;
  color: var(--ink-soft);
  font-size: 8.8px;
  line-height: 1;
  font-weight: 800;
  white-space: nowrap;
}

.writer-block input,
.line-input {
  width: 100%;
  min-width: 0;
  height: 6.5mm;
  padding: 0 .8mm .6mm;
  border: 0;
  border-bottom: .25mm solid #8d99a9;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 10px;
  font-weight: 500;
}

.book-info {
  margin-top: 4mm;
  padding: 3.5mm 4mm 3.3mm;
  border-left: 1.2mm solid var(--accent);
  background: var(--accent-soft);
}

.info-title { margin: 0 0 2.8mm; font-size: 10.5px; line-height: 1; font-weight: 800; }
.info-grid { display: grid; gap: 2.4mm; }
.info-row { display: grid; align-items: end; gap: 4mm; min-width: 0; }
.info-row--three { grid-template-columns: 1.55fr 1fr 1fr; }
.info-row--two { grid-template-columns: 2.55fr 1fr; }

.field {
  display: grid;
  grid-template-columns: 13mm minmax(0,1fr);
  align-items: end;
  gap: 2mm;
  min-width: 0;
}

.field--period { grid-template-columns: 16mm minmax(0,1fr); }
.field--genre { grid-template-columns: 13mm minmax(0,1fr); align-items: center; }

.period-inputs {
  display: grid;
  grid-template-columns: minmax(0,1fr) 7mm minmax(0,1fr);
  align-items: end;
  gap: 1.6mm;
}

.period-inputs span { padding-bottom: 1mm; text-align: center; font-size: 7.8px; color: var(--muted); }

.genre-row { display: flex; align-items: center; gap: 3.5mm; min-height: 6mm; }
.genre-option { display: inline-flex; align-items: center; gap: 1mm; color: var(--ink-soft); font-size: 8px; font-weight: 600; white-space: nowrap; }
.genre-option input { width: 3.2mm; height: 3.2mm; margin: 0; accent-color: var(--accent); }

.sections { margin-top: 3.4mm; }
.sections--continuation { margin-top: 4mm; }

.section {
  padding: 2.5mm 0 2.8mm;
  border-bottom: .2mm solid #d4dbe4;
  break-inside: avoid;
}

.section:first-child { padding-top: 0; }
.section--last { border-bottom: 0; padding-bottom: 0; }

.section-head {
  display: grid;
  grid-template-columns: 7.4mm minmax(0,1fr);
  align-items: center;
  gap: 2.2mm;
  margin-bottom: 1.8mm;
}

.section-no {
  width: 7.4mm;
  height: 7.4mm;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  line-height: 1;
  font-weight: 800;
}

.section-title { margin: 0; font-size: 11px; line-height: 1.2; font-weight: 800; letter-spacing: -.02em; }
.section-guide { margin: .6mm 0 0; color: var(--muted); font-size: 7.8px; line-height: 1.3; }

.lined-textarea,
.plain-textarea {
  width: 100%;
  display: block;
  resize: none;
  outline: none;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font);
  font-size: 10px;
  font-weight: 500;
  caret-color: var(--accent);
}

.ruled-field {
  position: relative;
  width: 100%;
  --line-count: 2;
}

.rule-lines {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  grid-template-rows: repeat(var(--line-count), minmax(0, 1fr));
  pointer-events: none;
}

.rule-lines span {
  display: block;
  border-bottom: .25mm solid var(--rule);
}

.lined-textarea {
  position: relative;
  z-index: 1;
  height: 100%;
  padding: 0 1.2mm;
  border: 0;
  line-height: var(--writing-line);
  background: transparent;
}

.lines-2 { --line-count: 2; height: calc(var(--writing-line) * 2); }
.lines-3 { --line-count: 3; height: calc(var(--writing-line) * 3); }
.lines-4 { --line-count: 4; height: calc(var(--writing-line) * 4); }
.lines-5 { --line-count: 5; height: calc(var(--writing-line) * 5); }

.takeaway-list { display: grid; gap: 1mm; }
.takeaway-row { display: grid; grid-template-columns: 5mm minmax(0,1fr); align-items: start; }
.takeaway-row > span { padding-top: 1.2mm; color: var(--accent); font-size: 8.8px; font-weight: 800; }

.prompt-stack { display: grid; gap: 2.2mm; }
.mini-prompt { min-width: 0; }
.mini-prompt label { display: block; margin: 0 0 .8mm 1.2mm; color: var(--ink-soft); font-size: 8.2px; line-height: 1.2; font-weight: 800; }

.plain-textarea {
  height: 16mm;
  padding: 2.2mm 2.5mm;
  border: .22mm solid var(--rule);
  background: #fbfcfe;
  line-height: 1.55;
}

.continuation-header h1 { margin: 0; font-size: 22px; line-height: 1; font-weight: 800; letter-spacing: -.04em; }
.continuation-meta { display: flex; justify-content: flex-end; gap: 5mm; padding-bottom: 1mm; color: var(--ink-soft); font-size: 9px; font-weight: 700; }
.continuation-meta strong { display: inline-block; min-width: 17mm; padding: 0 1mm 1mm; border-bottom: .25mm solid var(--ink); color: var(--ink); font-size: 10px; text-align: center; }

.page-footer {
  margin-top: auto;
  padding-top: 2mm;
  border-top: .2mm solid #d4dbe4;
  display: flex;
  justify-content: space-between;
  gap: 8mm;
  color: var(--muted);
  font-size: 7px;
  line-height: 1.3;
}

input::placeholder, textarea::placeholder { color: #a7b0bc; opacity: 1; }
input:focus, textarea:focus { background-color: rgba(35,90,145,.045); }

@page { size: A4 portrait; margin: 0; }

@media print {
  html, body { width: 210mm; min-height: 0; background: #fff; }
  body { padding: 0; }
  .toolbar { display: none !important; }
  .document { width: 210mm; margin: 0; }
  .sheet {
    width: 210mm;
    height: 297mm;
    margin: 0;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .sheet:last-child { break-after: auto; page-break-after: auto; }
}

@media (max-width: 840px) {
  body { padding: 0; background: #fff; }
  .toolbar { position: static; width: 100%; margin: 0; border-radius: 0; }
  .toolbar__status { display: none; }
  .toolbar__actions { width: 100%; }
  .toolbar button { flex: 1 1 0; padding: 0 8px; }
  .document { width: 100%; }
  .sheet { width: 100%; height: auto; min-height: 100vh; margin: 0; padding: 24px 18px 28px; box-shadow: none; overflow: visible; }
  .header, .continuation-header, .info-row--three, .info-row--two { grid-template-columns: minmax(0,1fr); gap: 16px; }
  .writer-block { width: 100%; }
  .book-info { padding: 18px 16px; }
  .field { grid-template-columns: 76px minmax(0,1fr); }
  .field--period { grid-template-columns: 76px minmax(0,1fr); }
  .genre-row { flex-wrap: wrap; gap: 10px 18px; }
  .continuation-meta { justify-content: flex-start; }
  .page-footer { margin-top: 24px; }
}
