:root {
  color-scheme: light;
  --ink: #16181d;
  --muted: #626976;
  --line: #d9dde5;
  --panel: #ffffff;
  --paper: #ffffff;
  --surface: #eef1f5;
  --accent: #12615c;
  --accent-dark: #0d4844;
  --focus: #d09422;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

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

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 22px;
  min-height: 100vh;
  padding: 22px;
}

.controls {
  align-self: start;
  position: sticky;
  top: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 16px 38px rgb(22 24 29 / 10%);
}

.brand {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0 0 4px;
  font-size: 1.2rem;
  line-height: 1.2;
  letter-spacing: 0;
}

p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 18px 0;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #c7ced8;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

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

input:focus,
select:focus,
button:focus {
  outline: 3px solid color-mix(in srgb, var(--focus), transparent 58%);
  outline-offset: 2px;
}

.toggle {
  grid-template-columns: auto 1fr;
  align-items: center;
  grid-column: span 2;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
}

.toggle input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.toggle span {
  color: var(--ink);
  font-size: 0.9rem;
  text-transform: none;
}

.actions {
  display: flex;
  gap: 10px;
}

button {
  border: 1px solid #b9c1cc;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 42px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  border-color: #8d98a8;
}

.actions button {
  flex: 1;
}

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

.primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.preview-wrap {
  display: grid;
  place-items: start center;
  overflow: auto;
  padding: 0 0 22px;
}

.paper {
  display: flex;
  flex-direction: column;
  gap: 12mm;
  background: var(--paper);
  box-shadow: 0 18px 44px rgb(22 24 29 / 16%);
  padding: 12mm;
  color: #000;
}

.paper.letter.portrait {
  width: 8.5in;
  min-height: 11in;
}

.paper.letter.landscape {
  width: 11in;
  min-height: 8.5in;
}

.paper.a4.portrait {
  width: 210mm;
  min-height: 297mm;
}

.paper.a4.landscape {
  width: 297mm;
  min-height: 210mm;
}

.worksheet-header {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16mm;
  font-size: 12pt;
}

.worksheet-header span {
  border-bottom: 1.5pt solid #000;
  padding-bottom: 5mm;
}

.maze-mount {
  flex: 1;
  display: grid;
  min-height: 0;
}

.maze-mount svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 6in;
}

.solution-path {
  opacity: 0.9;
}

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

  .controls {
    position: static;
  }

  .preview-wrap {
    place-items: start;
  }

  .paper {
    transform-origin: top left;
    max-width: 100%;
  }
}

@media (max-width: 560px) {
  .brand,
  .actions {
    flex-direction: column;
  }

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

  .toggle {
    grid-column: span 1;
  }
}

@page {
  size: letter portrait;
  margin: 0;
}

@media print {
  :root {
    --paper: #fff;
  }

  body {
    background: #fff;
  }

  .app-shell {
    display: block;
    min-height: auto;
    padding: 0;
  }

  .controls {
    display: none;
  }

  .preview-wrap {
    display: block;
    padding: 0;
    overflow: visible;
  }

  .paper {
    width: auto;
    min-height: auto;
    box-shadow: none;
    margin: 0;
    page-break-after: avoid;
  }

  .paper.letter.portrait {
    width: 8.5in;
    min-height: 11in;
  }

  .paper.letter.landscape {
    width: 11in;
    min-height: 8.5in;
  }

  .paper.a4.portrait {
    width: 210mm;
    min-height: 297mm;
  }

  .paper.a4.landscape {
    width: 297mm;
    min-height: 210mm;
  }
}
