:root {
  --ink: #171a1c;
  --muted: #64706d;
  --line: #d9dedb;
  --soft-line: #ecefed;
  --paper: #ffffff;
  --surface: #f7f8f6;
  --accent: #167c66;
  --accent-dark: #0f5d4d;
  --danger: #b42318;
  --shadow: 0 18px 60px rgba(22, 26, 28, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans KR", sans-serif;
  font-size: 15px;
}

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

button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

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

.app-shell {
  min-height: 100svh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 24px 32px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 248, 246, 0.95);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 25px;
  line-height: 1.25;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions,
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  min-height: calc(100svh - 82px);
}

.setup-pane {
  padding: 24px;
  border-right: 1px solid var(--line);
  background: #fbfcfa;
  overflow-y: auto;
}

.panel {
  padding: 0 0 24px;
  margin: 0 0 24px;
  border-bottom: 1px solid var(--line);
}

.panel:last-child {
  border-bottom: 0;
  margin-bottom: 0;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.section-heading h2,
.preview-toolbar h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--ink);
  font-weight: 700;
}

.field span {
  font-size: 13px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 124, 102, 0.12);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 8px 0 14px;
  font-weight: 700;
}

.check-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.divider::before,
.divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--soft-line);
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.ready {
  border-color: rgba(22, 124, 102, 0.35);
  color: var(--accent-dark);
  background: rgba(22, 124, 102, 0.08);
}

.helper-text {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.source-title-meta {
  margin: -6px 0 12px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.error-text {
  min-height: 21px;
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 40px;
  padding: 0 14px;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

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

.primary-button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.secondary-button:hover,
.ghost-button:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.ghost-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
}

.full-width {
  width: 100%;
}

.preview-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.preview-toolbar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.preview-stage {
  overflow: auto;
  padding: 28px;
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 24px;
}

.empty-state {
  width: min(100%, 680px);
  margin-top: 70px;
  padding: 34px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 8px;
  font-size: 22px;
  letter-spacing: 0;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.print-root {
  display: grid;
  gap: 24px;
  justify-items: center;
}

.print-only {
  display: none;
}

.sheet-page {
  width: 210mm;
  min-height: 297mm;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 14mm 13mm 12mm;
  display: flex;
  flex-direction: column;
  color: #111;
}

.sheet-header {
  border-bottom: 1px solid #111;
  padding-bottom: 7mm;
  margin-bottom: 6mm;
}

.sheet-title-row {
  display: grid;
  grid-template-columns: 45mm minmax(45mm, 1fr) 64mm;
  align-items: flex-start;
  gap: 7mm;
}

.sheet-title-block {
  text-align: center;
}

.sheet-title {
  margin: 0;
  font-size: 18pt;
  line-height: 1.2;
  letter-spacing: 0;
}

.sheet-signature {
  margin: 2mm 0 0;
  font-size: 10pt;
  font-weight: 700;
}

.sheet-date-block {
  padding-top: 1.2mm;
  text-align: center;
}

.sheet-date {
  font-size: 10pt;
  font-weight: 800;
  line-height: 1.3;
  white-space: nowrap;
}

.sheet-emoji {
  margin-top: 4mm;
  font-size: 12pt;
  line-height: 1;
}

.student-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3mm 5mm;
  width: 64mm;
  font-size: 9.5pt;
}

.student-field {
  border-bottom: 1px solid #111;
  min-height: 7.5mm;
  display: flex;
  align-items: flex-start;
  gap: 2mm;
  font-weight: 800;
  white-space: nowrap;
}

.name-field {
  grid-column: 1 / -1;
  min-height: 9mm;
}

.instructions {
  margin: 5mm 0 0;
  min-height: 0;
  white-space: pre-wrap;
  font-size: 9.5pt;
  line-height: 1.45;
}

.sheet-body {
  flex: 1;
  display: grid;
  align-content: start;
  gap: 3mm 8mm;
}

.sheet-body.columns-2 {
  grid-template-columns: 1fr 1fr;
}

.sheet-body.columns-1 {
  grid-template-columns: 1fr;
}

.sheet-column {
  display: grid;
  align-content: start;
  gap: 3mm;
}

.quiz-item {
  break-inside: avoid;
  padding-bottom: 2.2mm;
  border-bottom: 1px dotted #b9b9b9;
  font-size: 10pt;
  line-height: 1.35;
}

.question-line {
  display: grid;
  grid-template-columns: 8mm minmax(0, 1fr);
  gap: 2mm;
  align-items: baseline;
}

.question-number {
  font-weight: 800;
}

.question-main {
  overflow-wrap: anywhere;
}

.multiple-question {
  font-size: 10.8pt;
  font-weight: 800;
}

.short-answer-wrap {
  display: grid;
  grid-template-columns: minmax(0, var(--question-text-width, 35mm)) var(--answer-line-width, 38mm);
  column-gap: 5mm;
  row-gap: 0.8mm;
  align-items: start;
}

.sheet-body.columns-1 .short-answer-wrap {
  --question-text-width: 100mm;
  --answer-line-width: 55mm;
}

.sheet-body.columns-2 .short-answer-wrap {
  --question-text-width: 35mm;
  --answer-line-width: 38mm;
}

.question-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

.short-answer-line {
  display: block;
  width: var(--answer-line-width, 38mm);
  height: 1.55em;
  border-bottom: 1px solid #111;
}

.example-line {
  margin: 3mm 0 0 10mm;
  color: #333;
  font-size: 8.7pt;
  line-height: 1.35;
}

.choices {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1mm;
  margin: 3.2mm 0 0 10mm;
  padding: 0;
  list-style: none;
}

.choice {
  display: grid;
  grid-template-columns: 6mm minmax(0, 1fr);
  gap: 1mm;
}

.answer-body {
  flex: 1;
  display: grid;
  gap: 1.3mm 8mm;
  align-content: start;
}

.answer-body.columns-2 {
  grid-template-columns: 1fr 1fr;
}

.answer-body.columns-1 {
  grid-template-columns: 1fr;
}

.answer-column {
  display: grid;
  align-content: start;
  gap: 1.3mm;
}

.answer-sections {
  flex: 1;
  display: grid;
  align-content: start;
  gap: 4mm;
}

.answer-section + .answer-section {
  border-top: 1px solid #111;
  padding-top: 3mm;
}

.answer-section-title {
  margin: 0 0 2mm;
  font-size: 9.5pt;
  font-weight: 800;
  line-height: 1.2;
}

.answer-row {
  display: grid;
  grid-template-columns: 10mm minmax(0, 1fr);
  gap: 2mm;
  border-bottom: 1px dotted #c7c7c7;
  padding-bottom: 1mm;
  font-size: 9.5pt;
  line-height: 1.3;
}

.answer-index {
  font-weight: 800;
}

.sheet-footer {
  margin-top: 8mm;
  padding-top: 4mm;
  border-top: 1px solid #111;
  display: flex;
  justify-content: space-between;
  color: #333;
  font-size: 8.5pt;
}

@media (max-width: 980px) {
  .topbar,
  .preview-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .setup-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sheet-page {
    transform: scale(0.58);
    transform-origin: top center;
    margin-bottom: -120mm;
  }
}

@media (max-width: 560px) {
  .topbar,
  .setup-pane,
  .preview-toolbar,
  .preview-stage {
    padding-left: 16px;
    padding-right: 16px;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .toolbar-actions {
    width: 100%;
  }

  .topbar-actions button,
  .toolbar-actions button {
    flex: 1;
  }

  .sheet-page {
    transform: scale(0.46);
    margin-bottom: -160mm;
  }
}

@media print {
  @page {
    size: A4;
    margin: 0;
  }

  html,
  body {
    width: 210mm;
    background: #fff;
  }

  .no-print,
  .app-shell {
    display: none !important;
  }

  .print-only {
    display: block;
  }

  .sheet-page {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    padding: 14mm 13mm 12mm;
    box-shadow: none;
    page-break-after: always;
  }

  .sheet-page:last-child {
    page-break-after: auto;
  }

  .quiz-item {
    break-inside: avoid;
  }
}
