:root {
  color: #faf4f4;
  background: #000;
  font-family: system-ui, sans-serif;
  line-height: 1.45;
}

* { box-sizing: border-box; }

body { margin: 0; }

.workspace {
  width: min(68rem, calc(100% - 3rem));
  margin: 0 auto;
  padding: clamp(1.5rem, 5vw, 3.5rem) 0;
}

.masthead {
  padding-bottom: 1.25rem;
  border-bottom: 2px solid currentColor;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: 1rem;
}

.breadcrumbs a { color: inherit; }

h1, h2 {
  font-family: Georgia, serif;
  font-weight: 400;
}

h1 {
  margin: 0;
  font-size: clamp(3rem, 8vw, 5.75rem);
  line-height: 1;
  letter-spacing: -.065em;
}

.controls {
  display: grid;
  grid-template-columns: minmax(9rem, 1fr) minmax(14rem, 1fr) auto;
  gap: 1rem clamp(1rem, 3vw, 2.75rem);
  align-items: end;
  padding: 1.15rem 0;
  margin-bottom: .65rem;
}

.size-heading {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
}

.size-heading label, legend {
  padding: 0;
  font-size: .875rem;
  font-weight: 700;
}

output { font-variant-numeric: tabular-nums; }

input[type="range"] {
  display: block;
  width: 100%;
  height: 2.65rem;
  margin: .35rem 0 0;
  accent-color: #faf4f4;
  cursor: pointer;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.levels {
  display: flex;
  margin-top: .35rem;
}

.levels input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.levels label, button {
  display: grid;
  place-items: center;
  min-height: 2.65rem;
  padding: .5rem .9rem;
  border: 1px solid #aaa;
  background: #000;
  color: inherit;
  font: inherit;
  font-size: .875rem;
  font-weight: 650;
  cursor: pointer;
}

.levels label { flex: 1; }
.levels label:not(:last-child) { border-right: 0; }
.levels label:first-of-type { border-radius: .4rem 0 0 .4rem; }
.levels label:last-of-type { border-radius: 0 .4rem .4rem 0; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

button { border-radius: .4rem; }
.levels label:hover, button:hover { background: purple; }

.levels input:checked + label, .primary {
  border-color: #faf4f4;
  background: #faf4f4;
  color: #202020;
}

.primary:hover { background: #e7e7e7; }

.breadcrumbs a:focus-visible,
.controls :focus-visible,
.levels input:focus-visible + label,
.image-tools button:focus-visible {
  outline: 2px solid #faf4f4;
  outline-offset: 3px;
}

.levels input:focus-visible + label {
  position: relative;
  z-index: 1;
}

.worksheet {
  position: relative;
  width: min(100%, 44rem, max(24rem, 70vh));
  aspect-ratio: 3 / 4;
  margin: 0 auto;
  box-shadow: 0 0 0 1px #d2d2d2;
  background: white;
  color: black;
}

.worksheet h2, .puzzle {
  position: absolute;
  z-index: 1;
  margin: 0;
  pointer-events: none;
}

.worksheet h2 {
  inset: 8% 0 auto;
  text-align: center;
  font-size: clamp(1.25rem, 4vw, 1.75rem);
}

.puzzle {
  display: grid;
  inset: 19% 12% auto;
  gap: .35rem;
  font-size: clamp(.75rem, 2.5vw, 1rem);
  font-weight: 650;
}

.finish { justify-self: end; }

#maze {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  overflow: visible;
}

#walls {
  fill: none;
  stroke: black;
  stroke-width: .8px;
  stroke-linecap: square;
  vector-effect: non-scaling-stroke;
}

@media (max-width: 54rem) {
  .controls { grid-template-columns: 1fr 1fr; }
  .actions { grid-column: 1 / -1; }
}

@media (max-width: 34rem) {
  .workspace { width: calc(100% - 1.5rem); }
  .controls { grid-template-columns: 1fr; }
  .actions > button { flex: 1; }
}

@page { margin: 12mm; }

@media print {
  :root { background: white; }
  .masthead, .controls { display: none; }

  .workspace {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .worksheet {
    width: min(100%, 180mm);
    box-shadow: none;
    break-inside: avoid;
  }

  .worksheet h2 { font-size: 22pt; }

  .puzzle { font-size: 10pt; }

  #walls { stroke-width: .5pt; }
}

.image-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  padding: 0 0 1rem;
}

.image-tools p {
  margin: 0;
  font-size: .875rem;
}

.image-tools button:disabled {
  color: #666;
  background: #eaeaea;
  border-color: #aaa;
  cursor: default;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

#image-status[data-error] {
  position: static;
  width: auto;
  height: auto;
  clip-path: none;
  white-space: normal;
}

.worksheet.is-drop-target {
  outline: 2px dashed #222;
  outline-offset: 6px;
}

.artwork {
  position: absolute;
  z-index: 0;
  inset: 0;
  pointer-events: none;
}

.placed-image {
  position: absolute;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
}

.placed-image[data-selected] {
  outline: 1px dashed #333;
  outline-offset: 1px;
  z-index: 1;
}

.placed-image:focus-visible, .resize-image:focus-visible {
  outline: 2px solid #202020;
  outline-offset: 3px;
}

.placed-image img {
  display: block;
  width: 100%;
  height: 100%;
  filter: grayscale(1);
  pointer-events: none;
}

.placed-image .resize-image {
  position: absolute;
  right: 0;
  bottom: 0;
  transform: translate(40%, 40%);
  width: 1.35rem;
  height: 1.35rem;
  min-height: 0;
  padding: 0;
  border: 1px solid #333;
  border-radius: .25rem;
  background: white;
  cursor: nwse-resize;
}

.resize-image[hidden] { display: none; }

.resize-image::before {
  content: "";
  width: .42rem;
  height: .42rem;
  border-right: 2px solid #222;
  border-bottom: 2px solid #222;
}

@media print {
  .image-tools, .resize-image { display: none; }
  .worksheet.is-drop-target, .placed-image[data-selected], .placed-image:focus-visible {
    outline: none;
  }
}
