:root {
  --ink: #1a1a2e;
  --muted: #5b5f76;
  --line: #d7dae3;
  --accent: #a61b1b;
  --accent-soft: #fbe6e6;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --danger: #b91c1c;
  --checkbox-color: #7a1f1f;
  --topbar-height: 56px;
}

input[type="checkbox"] {
  accent-color: var(--checkbox-color);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Quicksand", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.app {
  min-height: 100vh;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 30;
}

.topbar h1 {
  font-size: 19px;
  margin: 0;
}

.brand-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.panel {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  width: 340px;
  height: calc(100vh - var(--topbar-height));
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 24px;
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 10;
  transition: width 0.2s ease, padding 0.2s ease;
}

.sidebar-toggle {
  position: fixed;
  top: calc(var(--topbar-height) + 20px);
  left: 340px;
  transform: translateX(-50%);
  z-index: 20;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  transition: left 0.2s ease;
}

.sidebar-toggle:hover {
  filter: brightness(0.97);
}

.sidebar-toggle-logo {
  width: 20px;
  height: 20px;
}

body.sidebar-collapsed .panel {
  width: 0;
  padding: 24px 0;
  border-right: none;
}

body.sidebar-collapsed .sidebar-toggle {
  left: 15px;
  transform: translateX(0);
}

body.sidebar-collapsed .viewer {
  margin-left: 0;
}

.panel .subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 20px;
}

.term-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 14px;
  overflow: hidden;
}

.term-header {
  background: var(--accent-soft);
  padding: 10px 14px;
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
}

.topic-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}

.topic-row label {
  flex: 1;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.topic-row input[type="number"] {
  width: 52px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
}

.topic-row input[type="number"]:disabled {
  background: var(--bg);
  color: var(--muted);
  cursor: not-allowed;
}

.field-group {
  margin: 16px 0;
}

.field-group label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}

.field-group input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13.5px;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  margin: 10px 0;
}

.btn {
  width: 100%;
  padding: 11px 14px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: filter 0.15s ease;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-secondary {
  background: #111827;
  color: white;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status-line {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
  min-height: 16px;
}

.viewer {
  margin-left: 340px;
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
  padding: 32px;
  display: flex;
  justify-content: center;
  overflow: auto;
  background: var(--bg);
  transition: margin-left 0.2s ease;
}

.sheet {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  width: 100%;
}

/* Sized to a fixed, print-accurate 794px (A4 at 96dpi) always — never reflowed
   to fit the viewport. On a narrow window app.js scales this down visually with
   a CSS transform and sizes .page-frame to match, so the layout inside always
   stays print-accurate while the on-screen footprint still fits. */
.page-card {
  background: white;
  width: 794px;
  min-height: 1123px;
  padding: 48px 50px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  font-family: "Arial Narrow", Arial, "Helvetica Neue", sans-serif;
  display: flex;
  flex-direction: column;
  transform-origin: top left;
}

.page-frame {
  overflow: visible;
}

.page-footer {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}

.sheet-header {
  border-bottom: 2px solid var(--ink);
  padding-bottom: 12px;
  margin-bottom: 20px;
}

.sheet-header h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.sheet-header .meta {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  margin-top: 10px;
}

.name-line {
  display: flex;
  gap: 24px;
  font-size: 13px;
  margin-top: 14px;
}

.name-line span {
  border-bottom: 1px solid var(--ink);
  padding-bottom: 2px;
  flex: 1;
}

.problem-columns {
  display: flex;
  gap: 22px;
  align-items: flex-start;
}

.problem-col {
  flex: 1;
  min-width: 0;
}

.section-header h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
  margin: 0 0 14px;
}

/* True 2-column grid: rows auto-align to equal height regardless of cell content.
   Leftover page space is filled by growing each .solution-area's own inline height
   (computed in app.js), not by CSS alignment — html2canvas (used for PDF export)
   doesn't reliably replicate grid/flex stretching, so an explicit pixel height is
   used instead to keep the on-screen preview and the exported PDF identical. */
.problem-grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 22px;
}

/* Reserves 2 lines of text so a graph starts at the same offset in every cell,
   regardless of whether its lead sentence happens to wrap to 1 line or 2. */
.problem-lead-text {
  min-height: 44px;
}

.problem-stack {
  display: flex;
  flex-direction: column;
}

.problem {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  font-size: 14.5px;
  line-height: 1.5;
  border-bottom: 1px dashed var(--line);
  break-inside: avoid;
  page-break-inside: avoid;
}

.problem .num {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
  width: 44px;
}

.problem .num-value {
  font-weight: 700;
  color: var(--accent);
}

.time-tag {
  font-weight: 400;
  color: var(--muted);
  font-size: 10.5px;
  white-space: nowrap;
}

.problem-body {
  min-width: 0;
}

.problem-text {
  display: inline;
}

.value-table {
  border-collapse: collapse;
  margin: 8px 0;
}

.value-table th,
.value-table td {
  border: 1px solid var(--ink);
  padding: 4px 12px;
  text-align: center;
  font-size: 13px;
}

.value-table th {
  background: var(--accent-soft);
}

.solution-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-top: 10px;
}

/* Base height only — app.js sets an explicit inline height on top of this to fill
   a topic's leftover page space (kept in sync via SOLUTION_BOX_BASE_HEIGHT). */
.solution-area {
  height: 92px;
  margin: 4px 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.answer-box {
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  flex-shrink: 0;
}

.answer-box .answer-label {
  font-weight: 700;
  font-size: 12.5px;
  color: var(--ink);
  white-space: nowrap;
}

.answer-box .answer-blank {
  display: inline-block;
  min-width: 160px;
  height: 30px;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
}

.answer-box + .answer-box {
  margin-top: 6px;
}

.page-break {
  page-break-before: always;
  break-before: page;
}

.answer-key-header h2 {
  font-size: 18px;
  margin: 0 0 14px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 10px;
}

.answer-row {
  display: flex;
  gap: 10px;
  padding: 6px 0;
  font-size: 13.5px;
}

.answer-row .num {
  font-weight: 700;
  color: var(--accent);
  min-width: 22px;
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  margin-top: 120px;
}

@media print {
  .panel,
  .sidebar-toggle,
  .topbar {
    display: none;
  }
  .viewer {
    margin-left: 0;
    margin-top: 0;
    padding: 0;
  }
  .page-card {
    box-shadow: none;
    width: auto;
    transform: none !important;
  }
  .page-frame {
    width: auto !important;
    height: auto !important;
  }
}
