.materials-main {
  max-width: 1550px;
  padding: 32px;
}

.workspace-intro h1 {
  font-size: 2.3rem;
  margin: 14px 0;
}

.workspace-intro p,
.library-note {
  color: var(--muted);
  font-size: .94rem;
  line-height: 1.75;
}

.workspace-status {
  min-height: 24px;
  color: var(--accent);
  font-size: .9rem;
  line-height: 1.6;
  margin: 18px 0;
}

.builder-layout {
  display: grid;
  grid-template-columns: minmax(300px,.9fr) minmax(0,1.1fr);
  gap: 24px;
  align-items: start;
}

.editor-panel,
.preview-panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: 15px;
  padding: 24px;
  min-width: 0;
}

.editor-panel textarea {
  min-height: 78px;
}

.editor-panel fieldset {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin: 22px 0;
}

.editor-panel legend {
  font-size: .9rem;
  font-weight: 650;
  padding: 0 6px;
}

.editor-panel label {
  line-height: 1.5;
}

.field-hint {
  line-height: 1.6;
}

.editor-actions,
.print-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}

.editor-actions .primary-button {
  margin: 0;
}

.text-button {
  border: 0;
  background: none;
  color: var(--accent);
  font-size: .875rem;
  padding: 10px;
}

.question-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}

.question-footer label {
  margin: 0;
}

.level-fields input {
  margin-bottom: 4px;
}

.preview-toolbar,
.library-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.preview-toolbar h2,
.library-toolbar h2 {
  margin: 0;
}

.preview-note {
  font-size: .8rem;
  color: var(--muted);
  line-height: 1.6;
}

.material-sheet {
  margin-top: 20px;
  background: #fff;
  border: 1px solid #e5e6ef;
  padding: 24px;
  overflow-wrap: anywhere;
  color: #252737;
  font-size: 1rem;
  line-height: 1.7;
}

.material-sheet h1 {
  font-size: 1.5rem;
  letter-spacing: -.5px;
  line-height: 1.3;
  margin: 0 0 18px;
}

.material-sheet p {
  white-space: pre-wrap;
}

.empty-preview {
  color: var(--muted);
}

.sheet-question {
  margin: 24px 0;
  break-inside: avoid;
}

.sheet-question>p {
  font-weight: 600;
}

.answer-lines {
  height: 84px;
  background: repeating-linear-gradient(to bottom,transparent 0,transparent 27px,#ccd0da 27px,#ccd0da 28px);
}

.answer-key-label {
  font-weight: 650;
  color: var(--accent);
}

.rubric-table-wrap {
  overflow-x: auto;
}

.rubric-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: .875rem;
  line-height: 1.6;
  table-layout: fixed;
}

.rubric-table th,
.rubric-table td {
  border: 1px solid #d9d9e7;
  padding: 12px;
  vertical-align: top;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.rubric-table th {
  background: #f2efff;
  text-align: left;
}

.rubric-table th:first-child {
  width: 18%;
}

.sheet-meta {
  font-size: .875rem;
  color: #5f6475;
}

.library-toolbar>div {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.library-note {
  max-width: 750px;
  margin: 20px 0;
}

.library-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin: 12px 0;
}

.library-row h3 {
  font-size: 1rem;
  margin: 0 0 7px;
  overflow-wrap: anywhere;
}

.library-row p {
  margin: 0;
  font-size: .8rem;
  color: var(--muted);
}

.library-row>div:last-child {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.library-empty {
  background: white;
  border: 1px dashed #d6d0ef;
  border-radius: 12px;
  padding: 28px;
  line-height: 1.7;
  color: var(--muted);
}

#material-print {
  display: none;
}

[hidden] {
  display: none !important;
}

@media (max-width:1100px) {
  .builder-layout {
    grid-template-columns: 1fr;
  }
  .materials-main {
    padding: 28px;
  }
  .preview-panel {
    position: static;
  }
}

@media (max-width:600px) {
  .materials-main {
    padding: 24px 18px;
  }
  .editor-panel,
  .preview-panel {
    padding: 18px;
  }
  .material-sheet {
    padding: 16px;
  }
  .library-row {
    flex-direction: column;
    align-items: start;
  }
  .workspace-intro h1 {
    font-size: 2rem;
  }
  .rubric-table th,
  .rubric-table td {
    padding: 9px;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 16mm;
  }
  body {
    background: white;
  }
  body>* {
    display: none !important;
  }
  #material-print {
    display: block !important;
    color: #222;
  }
  #material-print .material-sheet {
    border: 0;
    padding: 0;
    margin: 0;
    font-size: 12pt;
  }
  #material-print .rubric-table-wrap {
    overflow: visible;
  }
  #material-print .rubric-table {
    min-width: 0;
    font-size: 9pt;
  }
  #material-print .rubric-table th,
  #material-print .rubric-table td {
    padding: 7px;
  }
  #material-print .rubric-table tr {
    break-inside: avoid;
  }
  #material-print h1 {
    font-size: 20pt;
  }
  #material-print .answer-key-label {
    color: #222;
  }
  #material-print .sheet-question {
    break-inside: avoid;
  }
  * {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
