:root {
  color-scheme: light;
  --bg: #eef3f9;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #ccd5df;
  --blue: #2f63d8;
  --green: #249c68;
  --red: #d43e55;
  --shadow: 0 16px 40px rgba(25, 40, 70, 0.09);
}

* {
  box-sizing: border-box;
}

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

button,
select {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: inherit;
  font: inherit;
  font-weight: 700;
  padding: 9px 14px;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(47, 99, 216, 0.3);
  outline-offset: 2px;
}

a {
  color: var(--blue);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px clamp(18px, 3vw, 42px);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.eyebrow {
  margin: 0;
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 3px 0 0;
  font-size: clamp(1.7rem, 3vw, 2.35rem);
  letter-spacing: -0.04em;
}

.header-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 10px;
}

label {
  display: grid;
  gap: 5px;
  color: #344054;
  font-size: 0.76rem;
  font-weight: 750;
}

.brand-note {
  display: grid;
  align-self: center;
  gap: 1px;
  color: var(--muted);
  text-align: right;
  font-size: 0.68rem;
  font-weight: 750;
}

.about-panel {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 24px;
  max-width: 1040px;
  margin: 16px auto 0;
  padding: 20px;
  border: 1px solid #b8cae8;
  border-radius: 14px;
  background: #f8fbff;
  box-shadow: var(--shadow);
}

.about-panel[hidden] {
  display: none;
}

.about-panel h2 {
  margin: 0 0 10px;
}

.about-panel p {
  margin: 8px 0;
  line-height: 1.65;
}

.about-panel small {
  display: block;
  margin-top: 14px;
  color: var(--muted);
  line-height: 1.55;
}

main {
  display: grid;
  gap: 18px;
  width: min(1040px, calc(100% - 28px));
  margin: 14px auto 36px;
}

.controls,
.maze-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.controls {
  display: grid;
  grid-template-columns: minmax(190px, 0.35fr) minmax(500px, 1fr);
  gap: 14px 18px;
  padding: 18px;
}

.buttons {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 10px;
  align-items: end;
}

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

.busy {
  grid-column: 1 / -1;
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #eef4ff;
  color: #344d7b;
  font-weight: 750;
}

.maze-card {
  min-height: 64vh;
  padding: 20px;
}

.maze-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.maze-heading p {
  margin: 0;
  font-weight: 750;
}

.legend {
  display: flex;
  gap: 12px;
  color: var(--muted);
  font-size: 0.84rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.start-dot {
  background: var(--green);
}

.goal-dot {
  background: var(--red);
}

.canvas-frame {
  display: grid;
  min-height: 340px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f9fbfd;
  place-items: center;
  touch-action: none;
}

canvas {
  display: block;
  max-width: 100%;
}

.play-message {
  margin: 14px 0 0;
  padding: 12px;
  border-radius: 9px;
  background: #ecf8f2;
  color: #176744;
  font-weight: 800;
  text-align: center;
}

.print-sheet {
  display: none;
}

@media (max-width: 760px) {
  .site-header,
  .header-actions,
  .about-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .site-header {
    gap: 12px;
    padding-block: 12px;
  }

  .header-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .brand-note {
    grid-column: 1 / -1;
    text-align: left;
  }

  .about-panel {
    margin-inline: 14px;
  }

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

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

  .maze-card {
    padding: 14px;
  }

  .maze-heading {
    align-items: start;
    flex-direction: column;
  }
}

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

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

@media print {
  html,
  body {
    width: 210mm;
    min-width: 0;
    min-height: 297mm;
    margin: 0;
    padding: 0;
    background: #fff;
  }

  .site-header,
  .about-panel,
  main {
    display: none !important;
  }

  .print-sheet {
    display: grid;
    grid-template-rows: auto 1fr auto;
    width: 190mm;
    height: 277mm;
    padding: 8mm;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .print-sheet header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    padding-bottom: 5mm;
    border-bottom: 1.5px solid #17202a;
  }

  .print-sheet header p,
  .print-sheet footer {
    margin: 0;
    color: #5d6675;
    font-size: 9pt;
  }

  .print-sheet h1 {
    font-size: 20pt;
  }

  .print-sheet canvas {
    width: 174mm;
    max-width: 174mm;
    max-height: 220mm;
    align-self: center;
    justify-self: center;
  }

  .print-sheet footer {
    padding-top: 4mm;
    border-top: 1px solid #ccd5df;
    text-align: center;
  }
}
