:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #d8e1f0;
  --text: #1f2937;
  --muted: #667085;
  --primary: #2563eb;
  --primary-soft: #dbeafe;
  --teacher: #7c3aed;
  --teacher-soft: #ede9fe;
  --student: #059669;
  --student-soft: #d1fae5;
  --danger: #dc2626;
  --warn: #d97706;
  --warn-soft: #fff7ed;
  --radius: 18px;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
}

.topbar, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.topbar {
  padding: 20px;
  margin-bottom: 20px;
  display: grid;
  gap: 16px;
}

.title-block h1 {
  margin: 0 0 8px;
  font-size: 28px;
  line-height: 1.2;
}

.title-block p,
.panel-head p,
.muted,
.tip-box,
.file-drop,
.paste-zone,
.book-preview-list,
.print-note,
.field-meta,
.nav-sub,
.preview-caption,
.teacher-card-sub,
.issue-sub {
  color: var(--muted);
}

.top-controls,
.mode-switch,
.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.top-print-offset-box {
  width: min(100%, 760px);
  padding: 10px 12px;
  border: 1px solid #bfdbfe;
  border-radius: 14px;
  background: #eff6ff;
}

.top-print-offset-head {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: baseline;
  margin-bottom: 8px;
}

.top-print-offset-head strong {
  font-size: 14px;
}

.top-print-offset-head span {
  color: var(--muted);
  font-size: 12px;
}

.top-print-offset-fields {
  display: grid;
  grid-template-columns: repeat(5, minmax(104px, 1fr));
  gap: 8px;
  align-items: end;
}

.top-print-offset-fields .field {
  margin-bottom: 0;
}

.mode-btn,
.primary-btn,
.ghost-btn,
.file-btn,
.nav-btn,
.toolbar-btn,
.book-preview-btn,
.issue-jump-btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  transition: .2s ease;
}

.mode-btn:hover,
.primary-btn:hover,
.ghost-btn:hover,
.file-btn:hover,
.nav-btn:hover,
.toolbar-btn:hover,
.book-preview-btn:hover,
.issue-jump-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.mode-btn.active {
  background: var(--student-soft);
  border-color: #86efac;
  color: #065f46;
  font-weight: 700;
}

body.teacher-mode .mode-btn.active {
  background: var(--teacher-soft);
  border-color: #c4b5fd;
  color: #5b21b6;
}

.primary-btn {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 700;
}

.accent-btn {
  background: #0f766e;
  border-color: #0f766e;
}

.ghost-btn.block {
  width: 100%;
}

.file-btn,
.file-drop {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.file-btn input,
.file-drop input {
  display: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
}

.badge.student {
  background: var(--student-soft);
  color: #065f46;
}

.badge.teacher {
  background: var(--teacher-soft);
  color: #5b21b6;
}

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 430px;
  gap: 20px;
  align-items: start;
}

.panel {
  overflow: hidden;
}

.panel-head {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.sidebar-panel,
.editor-panel,
.preview-panel {
  min-height: 760px;
}

.mini-section {
  padding: 16px 18px;
  border-bottom: 1px solid #eef2f7;
}

.mini-section:last-child {
  border-bottom: 0;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 12px;
}

.field:last-child {
  margin-bottom: 0;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 12px 14px;
  color: var(--text);
}

.field textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.6;
}

.field-meta {
  margin-top: -4px;
  margin-bottom: 12px;
  font-size: 12px;
  line-height: 1.6;
}

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

.nav-btn {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
}

.nav-btn.active {
  background: var(--primary-soft);
  border-color: #93c5fd;
  font-weight: 800;
}

.nav-main {
  display: block;
  font-weight: 800;
  color: var(--text);
}

.nav-sub {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.5;
}

.tip-box {
  border: 1px dashed #cbd5e1;
  background: #f8fafc;
  border-radius: 14px;
  padding: 12px;
  line-height: 1.7;
}

.book-concept-guide,
.spread-concept-note {
  border: 1px solid #bae6fd;
  background: #f0f9ff;
  color: #0f3f5f;
  border-radius: 14px;
  padding: 12px;
  line-height: 1.65;
}

.book-concept-guide {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.book-concept-guide strong {
  font-size: 13px;
}

.book-concept-guide p,
.spread-concept-note {
  margin: 0;
  font-size: 12px;
}

.spread-concept-note {
  margin: -2px 0 14px;
}

.teacher-readiness-math {
  display: block;
  margin-top: 8px;
  font-size: 12px;
}

.teacher-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
  margin-bottom: 12px;
}

.teacher-stat-card {
  border: 1px solid #ddd6fe;
  background: #faf5ff;
  border-radius: 14px;
  padding: 12px;
}

.teacher-card-title {
  font-size: 12px;
  font-weight: 800;
  color: #6b21a8;
  margin-bottom: 6px;
}

.teacher-card-value {
  font-size: 22px;
  font-weight: 900;
  line-height: 1.2;
}

.teacher-card-sub {
  font-size: 12px;
  margin-top: 4px;
}

.teacher-readiness-box {
  margin-bottom: 12px;
}

.teacher-readiness-box.good {
  border-style: solid;
  border-color: #a7f3d0;
  background: #ecfdf5;
  color: #065f46;
}

.teacher-readiness-box.warn {
  border-style: solid;
  border-color: #fdba74;
  background: var(--warn-soft);
  color: #9a3412;
}

.teacher-tools {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.teacher-issue-box {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
}

.teacher-issue-box h4 {
  margin: 0 0 10px;
  font-size: 15px;
}

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

.issue-item {
  border: 1px solid #fed7aa;
  background: #fffaf5;
  border-radius: 12px;
  padding: 10px;
}

.issue-title {
  font-size: 13px;
  font-weight: 800;
  color: #9a3412;
  margin-bottom: 4px;
}

.issue-sub {
  font-size: 12px;
  line-height: 1.6;
  margin-bottom: 8px;
}

.issue-jump-btn {
  width: 100%;
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
  text-align: left;
}

.issue-empty {
  border: 1px dashed #bbf7d0;
  background: #f0fdf4;
  color: #166534;
  border-radius: 12px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.6;
}

.editor-root {
  padding: 18px;
}

.editor-grid {
  display: grid;
  gap: 16px;
}

.editor-grid.single {
  grid-template-columns: 1fr;
}

.editor-grid.double {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.card-block {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  background: #fff;
}

.card-block h3 {
  margin: 0 0 14px;
  font-size: 18px;
}

.editor-toolbar,
.quick-adjust {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar-btn {
  min-height: 38px;
  padding: 0 12px;
  font-size: 13px;
}

.toolbar-btn.danger {
  border-color: #fecaca;
  color: #991b1b;
  background: #fff5f5;
}

.toolbar-btn:disabled,
.book-preview-btn:disabled,
.issue-jump-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

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

.file-drop,
.paste-zone {
  width: 100%;
  min-height: 56px;
  border: 1px dashed #94a3b8;
  border-radius: 14px;
  background: #f8fafc;
  padding: 14px;
  margin-bottom: 12px;
  line-height: 1.6;
}

.paste-zone:focus {
  outline: 2px solid #93c5fd;
  border-color: #60a5fa;
}

.preview-root {
  padding: 18px;
  display: grid;
  gap: 18px;
}

.current-preview {
  display: grid;
  gap: 16px;
}

.preview-spread,
.preview-cover {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  padding: 16px;
}

.preview-caption {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 10px;
}

.preview-cover-page {
  aspect-ratio: 210 / 297;
  border: 1px solid #dbe5f2;
  border-radius: 14px;
  background: #fff;
  overflow: hidden;
  display: grid;
  grid-template-rows: 1fr auto;
}

.preview-cover-image {
  background: #f1f5f9 center / cover no-repeat;
  min-height: 220px;
}

.preview-cover-text {
  padding: 18px;
}

.preview-cover-text h3 {
  margin: 0 0 8px;
  font-size: 28px;
}

.preview-spread-pages {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.preview-page {
  aspect-ratio: 210 / 297;
  border: 1px solid #dbe5f2;
  border-radius: 14px;
  background: #fff;
  overflow: hidden;
  position: relative;
}

.preview-left-inner {
  padding: 20px;
  height: 100%;
}

.preview-left-inner h3 {
  margin: 0 0 12px;
}

.preview-left-inner p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.7;
}

.preview-image-stage {
  position: absolute;
  inset: 0;
  background: #f8fafc;
  overflow: hidden;
}

.preview-image-stage img {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: 100%;
  max-height: 100%;
  transform-origin: center center;
}

.preview-empty {
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
}

.teacher-preview-report {
  border: 1px solid #ddd6fe;
  border-radius: 18px;
  padding: 16px;
  background: linear-gradient(180deg, #faf5ff, #ffffff);
}

.teacher-preview-report h3 {
  margin: 0 0 10px;
}

.teacher-preview-report ul {
  margin: 0;
  padding-left: 18px;
  line-height: 1.8;
}

.booklet-box {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  background: #fff;
}

.booklet-box h3 {
  margin: 0 0 12px;
}

.book-preview-list {
  margin: 0;
  padding-left: 20px;
  line-height: 1.8;
  display: grid;
  gap: 10px;
}

.book-preview-item {
  padding-left: 4px;
}

.book-preview-btn {
  width: 100%;
  min-height: 54px;
  text-align: left;
  padding: 10px 12px;
}

.book-preview-btn.active {
  background: #eff6ff;
  border-color: #93c5fd;
}

.print-sheet {
  break-after: page;
  page-break-after: always;
  margin-bottom: 24px;
}

.print-face {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.print-page {
  border: 1px solid #cbd5e1;
  min-height: 420px;
  background: #fff;
  padding: 16px;
  overflow: hidden;
}

.print-page.image-page {
  position: relative;
}

.print-page.image-page img {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: 100%;
  max-height: 100%;
  transform-origin: center center;
}

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar-panel,
  .editor-panel,
  .preview-panel {
    min-height: auto;
  }
}

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

  .editor-grid.double,
  .preview-spread-pages,
  .inline-fields,
  .top-print-offset-fields,
  .print-face,
  .teacher-summary-grid {
    grid-template-columns: 1fr;
  }

  .editor-toolbar,
  .quick-adjust,
  .teacher-tools {
    flex-direction: column;
  }

  .title-block h1 {
    font-size: 22px;
  }
}

body.student-mode .teacher-only-control,
body.student-mode .teacher-only {
  display: none !important;
}

.text-format-toolbar {
  display: grid;
  grid-template-columns: minmax(150px, 1.2fr) minmax(150px, 0.85fr) auto auto minmax(210px, 1fr);
  gap: 10px;
  align-items: end;
  margin: 16px 0 20px;
  padding: 14px;
  border: 1px solid #b9d9ce;
  border-radius: 18px;
  background: #f2faf6;
  box-shadow: 0 8px 20px rgba(15, 118, 93, 0.08);
}

.format-field {
  display: grid;
  gap: 6px;
  color: #315047;
  font-size: 12px;
  font-weight: 800;
}

.format-field select,
.format-field input[type="number"] {
  min-height: 44px;
  width: 100%;
  border: 1px solid #b9c9c2;
  border-radius: 11px;
  color: #17352d;
  background: #fff;
  font: inherit;
  font-size: 14px;
}

.format-size-controls,
.format-button-group,
.format-align-group {
  display: flex;
  gap: 6px;
}

.format-size-controls input {
  min-width: 62px;
  text-align: center;
}

.format-icon-btn,
.format-toggle-btn,
.format-align-btn {
  min-height: 44px;
  border: 1px solid #b9c9c2;
  border-radius: 11px;
  color: #29473e;
  background: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
}

.format-icon-btn {
  flex: 0 0 44px;
  padding: 0;
  font-size: 21px;
}

.format-toggle-btn {
  min-width: 62px;
  padding: 0 12px;
}

.format-align-group {
  padding: 5px;
  border-radius: 13px;
  background: #e3eee9;
}

.format-align-btn {
  flex: 1 1 auto;
  padding: 0 10px;
  border-color: transparent;
  background: transparent;
}

.format-toggle-btn[aria-pressed="true"],
.format-align-btn[aria-pressed="true"] {
  border-color: #0f765d;
  color: #fff;
  background: #0f765d;
  box-shadow: 0 3px 0 #095744;
}

.format-color-field input[type="color"] {
  width: 54px;
  height: 44px;
  padding: 4px;
  border: 1px solid #b9c9c2;
  border-radius: 11px;
  background: #fff;
  cursor: pointer;
}

.replaced-by-format-toolbar {
  display: none !important;
}

@media (max-width: 1180px) {
  .text-format-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .format-align-group {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .text-format-toolbar {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .format-align-group {
    grid-column: auto;
  }

  .format-button-group,
  .format-align-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .format-toggle-btn,
  .format-align-btn {
    min-height: 48px;
    min-width: 0;
    padding: 0 6px;
  }
}

.submit-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.submit-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.56);
}

.submit-dialog {
  position: relative;
  z-index: 1;
  width: min(720px, calc(100vw - 32px));
  margin: 5vh auto 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
  padding: 22px;
  display: grid;
  gap: 14px;
}

.submit-dialog-head,
.submit-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.submit-dialog-head h3 {
  margin: 0;
  font-size: 22px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 24px;
  line-height: 1;
}

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

.submit-status-box {
  min-height: 48px;
  border-radius: 16px;
  border: 1px dashed var(--line);
  background: #f8fbff;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--muted);
}

.submit-status-box.pending {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1d4ed8;
}

.submit-status-box.success {
  border-color: #86efac;
  background: #ecfdf5;
  color: #065f46;
}

.submit-status-box.error {
  border-color: #fca5a5;
  background: #fef2f2;
  color: #991b1b;
}

@media (max-width: 768px) {
  .submit-grid {
    grid-template-columns: 1fr;
  }

  .submit-dialog {
    margin-top: 2vh;
    padding: 18px;
  }

  .submit-actions,
  .submit-dialog-head {
    align-items: flex-start;
  }
}
