:root {
  color-scheme: light;
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: #eef2f7;
  color: #172033;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 24px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

.controls {
  align-self: start;
  position: sticky;
  top: 24px;
  padding: 24px;
  border-radius: 24px;
  background: #ffffff;
  box-shadow: 0 18px 50px rgb(15 23 42 / 12%);
}

.controls-header {
  display: grid;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #2563eb;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(1.6rem, 2vw, 2.1rem);
  line-height: 1.1;
}

.controls p {
  color: #5f6b7a;
  line-height: 1.6;
}

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

.field,
.operation-fieldset,
.toggle {
  display: grid;
  gap: 8px;
}

.field-wide {
  grid-column: 1 / -1;
}

.field span,
.operation-fieldset legend,
.advanced summary {
  color: #334155;
  font-size: 0.86rem;
  font-weight: 700;
}

input[type="text"],
input[type="number"],
input:not([type]),
select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #f8fafc;
}

.operation-fieldset {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
  padding: 14px;
  border: 1px solid #dbe3ee;
  border-radius: 16px;
}

.operation-fieldset legend {
  padding: 0 6px;
}

.operation-fieldset label,
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #172033;
}

.advanced {
  padding: 14px;
  border: 1px solid #dbe3ee;
  border-radius: 16px;
  background: #f8fafc;
}

.advanced summary {
  cursor: pointer;
  list-style-position: outside;
}

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

.advanced-help {
  margin: 12px 0 0;
  font-size: 0.82rem;
}

.print-button,
.generate-button {
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  color: #ffffff;
  font-weight: 800;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  box-shadow: 0 10px 20px rgb(37 99 235 / 24%);
}

.print-button {
  width: 100%;
  padding: 12px 18px;
}

.generate-button {
  padding: 14px 18px;
}

.sheet {
  --worksheet-columns: 3;
  width: min(100%, 210mm);
  min-height: 297mm;
  margin: 0 auto;
  padding: 12mm 11mm;
  background: #ffffff;
  box-shadow: 0 24px 80px rgb(15 23 42 / 16%);
}

.sheet-header {
  display: grid;
  gap: 8px;
  margin-bottom: 8mm;
  padding-bottom: 5mm;
  border-bottom: 2px solid #172033;
  text-align: center;
}

.sheet-header h2 {
  margin: 0;
  font-size: 22pt;
  letter-spacing: 0.08em;
}

.sheet-header p {
  margin: 0;
  font-size: 10pt;
}

.problem-grid,
.answer-grid {
  display: grid;
  grid-template-columns: repeat(var(--worksheet-columns), minmax(0, 1fr));
  column-gap: 8mm;
  row-gap: 4.4mm;
  margin: 0;
  padding: 0;
  list-style: none;
}

.problem {
  display: grid;
  grid-template-columns: 2.1em 1fr;
  align-items: baseline;
  min-height: 9mm;
  break-inside: avoid;
  page-break-inside: avoid;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 13pt;
  line-height: 1.25;
}

.problem-number {
  color: #64748b;
  font-size: 10pt;
}

.problem-expression {
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.answer-section {
  margin-top: 8mm;
  padding-top: 4mm;
  border-top: 1px dashed #94a3b8;
}

.answer-section h2 {
  margin-bottom: 3mm;
  font-size: 12pt;
}

.answer-grid {
  row-gap: 2mm;
  font-size: 9pt;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .controls {
    position: static;
  }

  .sheet {
    min-height: auto;
    padding: 18px;
  }

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

@page {
  size: A4;
  margin: 10mm;
}

@media print {
  :root,
  body {
    background: #ffffff;
  }

  .app-shell {
    display: block;
    max-width: none;
    padding: 0;
  }

  .controls {
    display: none !important;
  }

  .sheet {
    width: auto;
    min-height: auto;
    margin: 0;
    padding: 0;
    box-shadow: none;
  }

  .sheet-header {
    margin-bottom: 7mm;
  }

  .problem-grid {
    row-gap: 3.8mm;
  }

  .problem {
    min-height: 8.2mm;
    font-size: 12pt;
  }

  .answer-section[hidden] {
    display: none !important;
  }
}
