:root {
  --ink: #111827;
  --ink-soft: #374151;
  --muted: #6b7280;
  --line: #d1d5db;
  --line-dark: #9ca3af;
  --blue: #1d4ed8;
  --blue-dark: #1e40af;
  --blue-soft: #eff6ff;
  --red: #b42318;
  --red-soft: #fff1f0;
  --screen: #f3f4f6;
  --white: #fff;
  --font: "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%;
  background: var(--screen);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
select { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

button { color: inherit; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  border-radius: 6px;
  background: var(--ink);
  color: white;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transform: translateY(-150%);
}

.skip-link:focus { transform: translateY(0); }

.appbar {
  position: sticky;
  z-index: 50;
  top: 0;
  min-height: 68px;
  padding: 10px 24px;
  display: grid;
  grid-template-columns: minmax(210px, 1fr) minmax(320px, 520px) minmax(210px, 1fr);
  align-items: center;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: var(--white);
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
}

.brand__mark {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--blue);
  color: white;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: -.03em;
}

.brand strong,
.brand small { display: block; }
.brand strong { font-size: 14px; line-height: 1.3; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 9px; font-weight: 600; }

.record-picker {
  min-width: 0;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
  gap: 7px;
}

.student-select { min-width: 0; }

.student-select select {
  width: 100%;
  height: 38px;
  padding: 0 36px 0 12px;
  border: 1px solid var(--line-dark);
  border-radius: 6px;
  outline: 0;
  background: var(--white);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
}

.student-select select:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgb(29 78 216 / 12%); }

.icon-button,
.button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line-dark);
  border-radius: 6px;
  background: var(--white);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.icon-button { padding: 0; font-size: 17px; }
.icon-button:hover,
.button:hover { background: #f9fafb; }
.button:disabled { opacity: .55; cursor: wait; }
.button--primary { border-color: var(--blue); background: var(--blue); color: white; }
.button--primary:hover { background: var(--blue-dark); }
.button--small { min-height: 31px; padding-inline: 10px; font-size: 10px; }

.appbar__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.save-state { margin-right: 4px; color: var(--muted); font-size: 10px; font-weight: 600; }
.save-state.is-error { color: var(--red); }

.workspace {
  width: min(100%, 1160px);
  margin: 0 auto;
  padding: 34px 28px 64px;
}

.document-toolbar {
  width: 210mm;
  max-width: 100%;
  margin: 0 auto 18px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--blue);
  font-size: 9px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: .16em;
}

.document-toolbar h1 { margin: 0; font-size: 24px; line-height: 1.25; letter-spacing: -.035em; }
.document-toolbar p:not(.eyebrow) { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

.document-tools { display: grid; justify-items: end; gap: 8px; }
.edit-actions { display: flex; gap: 6px; }

.view-switch {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, auto);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--white);
}

.view-switch button {
  min-height: 30px;
  padding: 0 11px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}

.view-switch button.is-active { background: var(--ink); color: white; }

.review-alert {
  width: 210mm;
  max-width: 100%;
  margin: 0 auto 18px;
  padding: 13px 15px;
  border: 1px solid #f3b4ae;
  border-left: 4px solid var(--red);
  border-radius: 6px;
  background: var(--red-soft);
  color: #7a271a;
  font-size: 11px;
  line-height: 1.7;
}

.review-alert strong { display: block; margin-bottom: 2px; font-size: 12px; }

.loading-state,
.error-state {
  width: 210mm;
  max-width: 100%;
  min-height: 240px;
  margin: 0 auto;
  display: grid;
  place-content: center;
  justify-items: center;
  border: 1px solid var(--line);
  background: white;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

.error-state h2 { margin: 0; color: var(--ink); font-size: 18px; }
.error-state p { margin: 8px 0 16px; }

.portfolio-document {
  width: 210mm;
  max-width: 100%;
  margin: 0 auto;
}

.portfolio-document[data-view="original"] .sheet--revised,
.portfolio-document[data-view="revised"] .sheet--original { display: none; }

.sheet {
  width: 210mm;
  height: 297mm;
  margin: 0 0 18px;
  padding: 11mm 13mm 9mm;
  display: flex;
  flex-direction: column;
  border: 1px solid #cfd4dc;
  background: var(--white);
  overflow: hidden;
}

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

.sheet-header__top {
  display: flex;
  align-items: center;
  gap: 2.4mm;
  margin-bottom: 2mm;
}

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

.version-label {
  padding: 1.1mm 2mm;
  border: .25mm solid currentColor;
  border-radius: 1mm;
  color: var(--blue);
  font-size: 7px;
  line-height: 1;
  font-weight: 800;
}

.sheet--original .version-label { color: var(--ink-soft); }

.form-title { margin: 0; font-size: 27px; line-height: 1; font-weight: 800; letter-spacing: -.055em; }
.form-title span { margin-left: 2mm; font-size: 18px; letter-spacing: 0; }

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

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

.line-value {
  min-width: 0;
  min-height: 6.5mm;
  padding: 0 .8mm .7mm;
  border-bottom: .25mm solid var(--line-dark);
  color: var(--ink);
  font-size: 9.2px;
  line-height: 1.45;
  font-weight: 500;
  overflow-wrap: anywhere;
  word-break: keep-all;
}

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

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

.info-field { min-width: 0; display: block; }
.info-field .field-label { display: block; min-height: 4mm; padding: 0 0 1mm; }
.info-field .line-value { display: block; width: 100%; }
.info-field--genre { display: grid; grid-template-columns: 13mm minmax(0, 1fr); align-items: center; gap: 2mm; }
.info-field--genre .field-label { min-height: 0; padding: 0; }

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

.period-values .line-value { min-height: 6.5mm; }

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

.genre-row { min-height: 6mm; display: flex; align-items: center; gap: 3.5mm; }
.genre-option { display: inline-flex; align-items: center; gap: 1mm; color: var(--ink-soft); font-size: 7.8px; font-weight: 600; white-space: nowrap; }
.genre-check { width: 3.2mm; height: 3.2mm; display: grid; place-items: center; border: .25mm solid var(--line-dark); border-radius: 50%; }
.genre-option.is-selected .genre-check { border-color: var(--blue); }
.genre-option.is-selected .genre-check::after { content: ""; width: 1.7mm; height: 1.7mm; border-radius: 50%; background: var(--blue); }

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

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

.form-section:first-child { padding-top: 0; }
.form-section--last { padding-bottom: 0; border-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(--blue);
  color: white;
  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.6px; line-height: 1.3; }

.writing-area {
  position: relative;
  width: 100%;
  height: calc(var(--lines) * var(--writing-line));
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--writing-line) - .25mm), var(--line-dark) calc(var(--writing-line) - .25mm), var(--line-dark) var(--writing-line));
}

.writing-value {
  width: 100%;
  height: 100%;
  padding: 0 1.2mm;
  outline: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 10px;
  line-height: var(--writing-line);
  font-weight: 500;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: keep-all;
  caret-color: var(--blue);
}

.writing-value[contenteditable="true"]:focus {
  background: rgb(239 246 255 / 65%);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.writing-value[contenteditable="true"]:empty::before { content: "첨삭 내용을 입력하세요."; color: #9ca3af; }
.writing-value.has-overflow { box-shadow: inset 0 0 0 1.5px var(--red); }

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

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

.boxed-writing {
  height: calc(var(--lines) * var(--writing-line));
  border: .22mm solid var(--line-dark);
  background: #fbfcfe;
}

.boxed-writing .writing-value { padding: 2mm 2.5mm; line-height: 1.55; }

.continuation-header h2 { margin: 0; font-size: 22px; line-height: 1; letter-spacing: -.04em; }
.continuation-meta { display: flex; align-items: center; justify-content: flex-end; gap: 4mm; color: var(--ink-soft); font-size: 8.5px; font-weight: 700; }
.continuation-meta strong { min-width: 16mm; padding: 0 1mm 1mm; border-bottom: .25mm solid var(--ink); color: var(--ink); font-size: 9.5px; text-align: center; }

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

.page-footer__version { font-style: normal; }

.screen-footer {
  width: 210mm;
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.screen-footer p { margin: 0; }

.toast {
  position: fixed;
  z-index: 100;
  right: 20px;
  bottom: 20px;
  padding: 11px 14px;
  border-radius: 6px;
  background: var(--ink);
  color: white;
  font-size: 11px;
  font-weight: 700;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { background: var(--red); }

.record-dialog {
  width: min(680px, calc(100vw - 28px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 1px solid var(--line-dark);
  border-radius: 10px;
  background: white;
  color: var(--ink);
}

.record-dialog::backdrop { background: rgb(17 24 39 / 46%); }
.record-form { padding: 0; }

.record-form__header {
  padding: 22px 24px 17px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
}

.record-form__header h2 { margin: 0; font-size: 20px; letter-spacing: -.03em; }
.dialog-close { width: 34px; height: 34px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; }
.dialog-close:hover { background: #f3f4f6; color: var(--ink); }
.record-form__guide { margin: 0; padding: 15px 24px 0; color: var(--muted); font-size: 11px; line-height: 1.6; }

.record-form__grid {
  padding: 18px 24px 24px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px;
}

.record-form__grid label { min-width: 0; display: grid; gap: 6px; }
.record-form__grid label > span { color: var(--ink-soft); font-size: 10px; font-weight: 700; }
.record-form__grid input,
.record-form__grid select {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line-dark);
  border-radius: 5px;
  outline: 0;
  background: white;
  color: var(--ink);
  font-size: 12px;
}

.record-form__grid input:focus,
.record-form__grid select:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgb(29 78 216 / 12%); }
.record-form__grid .form-field--wide { grid-column: 1 / -1; }

.record-form__footer {
  padding: 14px 24px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--line);
  background: #f9fafb;
}

@media (max-width: 1020px) {
  .appbar { grid-template-columns: 1fr minmax(300px, 1.4fr); }
  .appbar__actions { grid-column: 1 / -1; justify-content: center; padding-top: 2px; }
}

@media (max-width: 760px) {
  .appbar { position: static; padding: 12px; grid-template-columns: 1fr; gap: 10px; }
  .brand small { display: none; }
  .record-picker { grid-row: 2; }
  .appbar__actions { grid-column: auto; justify-content: stretch; }
  .appbar__actions .button { flex: 1 1 0; }
  .save-state { display: none; }
  .workspace { padding: 24px 12px 48px; }
  .document-toolbar { align-items: flex-start; flex-direction: column; }
  .document-tools { width: 100%; justify-items: stretch; }
  .edit-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .edit-actions .button { padding-inline: 6px; }
  .view-switch { width: 100%; grid-template-columns: repeat(3, 1fr); }
  .portfolio-document { max-width: none; overflow-x: auto; padding-bottom: 8px; }
  .sheet { margin-inline: auto; }
  .screen-footer { flex-direction: column; }
  .record-form__grid { grid-template-columns: 1fr; }
  .record-form__grid .form-field--wide { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

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

@media print {
  html,
  body { width: 210mm; min-height: 0; background: white; }
  body { padding: 0; }
  .appbar,
  .skip-link,
  .document-toolbar,
  .review-alert,
  .loading-state,
  .error-state,
  .screen-footer,
  .toast { display: none !important; }
  .workspace { width: 210mm; margin: 0; padding: 0; }
  .portfolio-document { width: 210mm; max-width: none; margin: 0; overflow: visible; }
  .portfolio-document .sheet {
    display: flex;
    width: 210mm;
    height: 294mm;
    margin: 0;
    border: 0;
    break-after: auto;
    page-break-after: auto;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .portfolio-document[data-view="original"] .sheet--revised,
  .portfolio-document[data-view="revised"] .sheet--original { display: none !important; }
  .portfolio-document .sheet[data-page="2"],
  .portfolio-document[data-view="all"] .sheet--revised[data-page="1"] { break-before: page; page-break-before: always; }
  .version-label,
  .page-footer__version { display: none !important; }
  .writing-value.has-overflow { box-shadow: none; }
}
