/* The colours of the squares are those of the figures of the Lean project's
   textbook (scripts/figures/proof_figures.py): a stroke and a fill per square,
   and grey for the central square of eight. */
:root {
  color-scheme: light;
  --paper: #f2eee4;
  --card: #fbf9f3;
  --ink: #1f2937;
  --ink-2: #4b5563;
  --ink-3: #8a8e96;
  --rule: #d9d2c1;
  --grid: rgba(31, 41, 55, 0.05);
  --grid-major: rgba(31, 41, 55, 0.1);
  --grid-axis: rgba(31, 41, 55, 0.2);
  --red: #dc2626;
  --red-wash: rgba(220, 38, 38, 0.07);
  --green: #15803d;
  --band: rgba(21, 128, 61, 0.4);
  --grow: rgba(220, 38, 38, 0.3);
  --focus: #2563eb;
  --s0: #2563eb;
  --f0: #dbeafe;
  --s1: #ea580c;
  --f1: #ffedd5;
  --s2: #16a34a;
  --f2: #dcfce7;
  --s3: #9333ea;
  --f3: #f3e8ff;
  --s4: #db2777;
  --f4: #fce7f3;
  --s5: #0891b2;
  --f5: #cffafe;
  --s6: #ca8a04;
  --f6: #fef9c3;
  --sk: #9ca3af;
  --fk: #e5e7eb;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --paper: #131518;
    --card: #1a1d21;
    --ink: #ebe7dc;
    --ink-2: #b8b4a9;
    --ink-3: #7c7f86;
    --rule: #33363c;
    --grid: rgba(235, 231, 220, 0.04);
    --grid-major: rgba(235, 231, 220, 0.08);
    --grid-axis: rgba(235, 231, 220, 0.18);
    --red: #f87171;
    --red-wash: rgba(248, 113, 113, 0.08);
    --green: #4ade80;
    --band: rgba(74, 222, 128, 0.38);
    --grow: rgba(248, 113, 113, 0.32);
    --focus: #60a5fa;
    --s0: #60a5fa;
    --f0: rgba(96, 165, 250, 0.2);
    --s1: #fb923c;
    --f1: rgba(251, 146, 60, 0.2);
    --s2: #4ade80;
    --f2: rgba(74, 222, 128, 0.18);
    --s3: #c084fc;
    --f3: rgba(192, 132, 252, 0.2);
    --s4: #f472b6;
    --f4: rgba(244, 114, 182, 0.2);
    --s5: #22d3ee;
    --f5: rgba(34, 211, 238, 0.18);
    --s6: #facc15;
    --f6: rgba(250, 204, 21, 0.17);
    --sk: #9ca3af;
    --fk: rgba(156, 163, 175, 0.2);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --paper: #131518;
  --card: #1a1d21;
  --ink: #ebe7dc;
  --ink-2: #b8b4a9;
  --ink-3: #7c7f86;
  --rule: #33363c;
  --grid: rgba(235, 231, 220, 0.04);
  --grid-major: rgba(235, 231, 220, 0.08);
  --grid-axis: rgba(235, 231, 220, 0.18);
  --red: #f87171;
  --red-wash: rgba(248, 113, 113, 0.08);
  --green: #4ade80;
  --band: rgba(74, 222, 128, 0.38);
  --grow: rgba(248, 113, 113, 0.32);
  --focus: #60a5fa;
  --s0: #60a5fa;
  --f0: rgba(96, 165, 250, 0.2);
  --s1: #fb923c;
  --f1: rgba(251, 146, 60, 0.2);
  --s2: #4ade80;
  --f2: rgba(74, 222, 128, 0.18);
  --s3: #c084fc;
  --f3: rgba(192, 132, 252, 0.2);
  --s4: #f472b6;
  --f4: rgba(244, 114, 182, 0.2);
  --s5: #22d3ee;
  --f5: rgba(34, 211, 238, 0.18);
  --s6: #facc15;
  --f6: rgba(250, 204, 21, 0.17);
  --sk: #9ca3af;
  --fk: rgba(156, 163, 175, 0.2);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
  font-optical-sizing: auto;
  font-size: 18px;
  line-height: 1.55;
}

a {
  color: inherit;
  text-decoration-color: var(--ink-3);
  text-underline-offset: 0.18em;
}

a:hover {
  text-decoration-color: currentColor;
}

i {
  font-style: italic;
}

sub {
  font-size: 0.7em;
  line-height: 0;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 0;
  font-size: 0.92rem;
  color: var(--ink-2);
}

.top a {
  text-decoration: none;
}

.top a:hover {
  text-decoration: underline;
}

.top-end {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}

.theme {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}

.theme:hover {
  color: var(--ink);
  border-color: var(--ink-3);
}

.theme svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
}

.theme svg .solid {
  fill: currentColor;
  stroke: none;
}

/* ---------------------------------------------------------------- the intro */

.intro {
  max-width: 46rem;
  margin: 40px 0 28px;
}

.kicker {
  margin: 0 0 6px;
  font-size: 0.82rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-3);
}

h1 {
  margin: 0;
  font-weight: 350;
  font-style: italic;
  font-size: clamp(2.6rem, 6.4vw, 4.6rem);
  line-height: 1;
  letter-spacing: -0.015em;
}

.lede {
  margin: 18px 0 0;
  font-size: 1.12rem;
  color: var(--ink-2);
}

.lede i {
  color: var(--ink);
}

/* -------------------------------------------------------------- the choices */

.cases {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 22px;
}

.case {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 6px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.15s ease;
}

.case svg {
  width: 100%;
  max-width: 76px;
  aspect-ratio: 1;
  display: block;
}

.case:hover {
  background: var(--card);
  transform: translateY(-1px);
}

.case[aria-pressed='true'] {
  background: var(--card);
  border-color: var(--ink);
  color: var(--ink);
}

.case:focus-visible,
button:focus-visible,
input:focus-visible,
#board:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

#board:focus:not(:focus-visible),
#board.pointer:focus-visible {
  outline: none;
}

.thumb-circle {
  fill: none;
  stroke: var(--ink);
  stroke-width: 0.9;
  stroke-dasharray: 3 2;
}

.case .sq polygon {
  stroke-width: 0.9;
}

/* ---------------------------------------------------------------- the board */

.play {
  display: grid;
  grid-template-columns: minmax(0, min(78vh, 760px)) minmax(280px, 340px);
  justify-content: space-between;
  gap: 32px;
  align-items: start;
}

.board-wrap {
  min-width: 0;
}

.board-box {
  position: relative;
}

.modes {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--ink);
  border-radius: 999px;
}

.mode {
  padding: 4px 18px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  transition:
    background 0.15s ease,
    color 0.15s ease;
}

.mode[aria-pressed='true'] {
  background: var(--ink);
  color: var(--card);
}

.mode:not([aria-pressed='true']):hover {
  color: var(--ink);
}

.mode-note {
  margin: 0 0 8px;
  color: var(--ink-2);
}

/* On small screens the panel is below the board, so the radius is also shown
   on the board. */
.board-readout {
  display: none;
  position: absolute;
  top: 10px;
  left: 14px;
  margin: 0;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums lining-nums;
  pointer-events: none;
}

.board-readout .extra {
  font-size: 0.9rem;
}

#board {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  touch-action: none;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 16px;
  user-select: none;
  -webkit-user-select: none;
}

.grid line {
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.grid .minor {
  stroke: var(--grid);
}

.grid .major {
  stroke: var(--grid-major);
}

.grid .axis {
  stroke: var(--grid-axis);
}

.hatch-wash {
  fill: var(--red-wash);
}

.hatch-line {
  stroke: var(--red);
  stroke-width: 1.1;
  opacity: 0.5;
}

.excess {
  fill: url(#hatch);
}

.minimum {
  fill: none;
  stroke: var(--ink-3);
  stroke-width: 1.2;
  stroke-dasharray: 6 4;
}

.live {
  fill: none;
  stroke: var(--red);
  stroke-width: 1.6;
  transition: stroke 0.25s ease;
}

#board.optimal .live {
  stroke: var(--ink);
}

.sq polygon {
  fill: var(--fill);
  stroke: var(--stroke);
  stroke-width: 1.5;
  stroke-linejoin: round;
  transition:
    fill 0.4s ease,
    stroke 0.4s ease;
}

#board .sq polygon {
  cursor: grab;
}

#board.dragging,
#board.dragging .sq polygon,
#board.dragging .knob {
  cursor: grabbing;
}

#board.restricted .sq.locked polygon {
  fill-opacity: 0.35;
  stroke-opacity: 0.45;
  cursor: default;
}

#board.restricted .sq.locked .label {
  opacity: 0.45;
}

#board.gliding .tracks {
  display: none;
}

.track polygon,
.track path {
  fill: var(--fill);
  fill-opacity: 0.45;
  stroke: var(--stroke);
  stroke-width: 1.2;
  stroke-dasharray: 4 3;
  pointer-events: none;
}

#board .sq polygon.selected {
  stroke-width: 3;
  filter: drop-shadow(0 3px 5px rgba(31, 41, 55, 0.22));
}

.c0 {
  --fill: var(--f0);
  --stroke: var(--s0);
}
.c1 {
  --fill: var(--f1);
  --stroke: var(--s1);
}
.c2 {
  --fill: var(--f2);
  --stroke: var(--s2);
}
.c3 {
  --fill: var(--f3);
  --stroke: var(--s3);
}
.c4 {
  --fill: var(--f4);
  --stroke: var(--s4);
}
.c5 {
  --fill: var(--f5);
  --stroke: var(--s5);
}
.c6 {
  --fill: var(--f6);
  --stroke: var(--s6);
}
.ck {
  --fill: var(--fk);
  --stroke: var(--sk);
}

.label {
  fill: var(--stroke);
  font-family: 'Newsreader', Georgia, serif;
  font-style: italic;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.ck .label {
  fill: var(--ink-2);
}

.marks circle {
  fill: var(--ink);
  pointer-events: none;
}

.handle line {
  stroke: var(--ink-2);
  stroke-width: 1.2;
  pointer-events: none;
}

.knob {
  fill: var(--card);
  stroke: var(--ink);
  stroke-width: 1.6;
  cursor: grab;
}

.knob:hover {
  fill: var(--paper);
}

.sq.enter {
  animation: drop 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: calc(var(--i) * 45ms);
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes drop {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
}

.hint {
  margin: 12px 2px 0;
  font-size: 0.92rem;
  color: var(--ink-3);
}

.hint.keys {
  margin-top: 4px;
}

kbd {
  font-family: inherit;
  font-size: 0.9em;
  padding: 0 0.3em;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--card);
}

/* ---------------------------------------------------------------- the panel */

.panel > section {
  padding: 16px 0;
  border-top: 1px solid var(--rule);
}

.panel > section:first-child {
  border-top: 0;
  padding-top: 0;
}

.panel p {
  margin: 0;
}

.cap {
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.big {
  margin: 2px 0 4px !important;
  font-size: clamp(2.3rem, 4vw, 2.9rem);
  font-weight: 350;
  line-height: 1.15;
  font-variant-numeric: tabular-nums lining-nums;
  white-space: nowrap;
}

.least {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums lining-nums;
}

.formula {
  white-space: nowrap;
}

.extra {
  color: var(--red);
  white-space: nowrap;
}

.status {
  margin-top: 6px !important;
  font-style: italic;
  color: var(--ink-2);
}

.status.good {
  color: var(--green);
}

h2,
h3 {
  margin: 0 0 6px;
  font-weight: 500;
  line-height: 1.2;
}

h2 {
  font-size: 1.45rem;
  font-style: italic;
}

h3 {
  font-size: 1.05rem;
}

.case-info p {
  color: var(--ink-2);
}

.note {
  font-size: 0.95rem;
  color: var(--ink-3);
}

.more {
  margin-top: 10px;
  font-size: 0.95rem;
  color: var(--ink-2);
}

.more summary {
  cursor: pointer;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--ink-3);
  text-underline-offset: 0.18em;
}

.more summary:hover {
  text-decoration-color: currentColor;
}

.more p {
  margin: 8px 0 0 !important;
}

.more .nw {
  white-space: nowrap;
}

.more .eq {
  padding-left: 1.2em;
  font-variant-numeric: lining-nums;
  color: var(--ink);
}

/* the sliders */

.slider {
  display: grid;
  grid-template-columns: 6.6em minmax(0, 1fr) 4.2em;
  align-items: center;
  column-gap: 10px;
  margin: 4px 0 2px;
  font-size: 0.98rem;
}

.slider .ends {
  grid-column: 2;
  display: flex;
  justify-content: space-between;
  margin-top: -5px;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--ink-3);
}

.slider output {
  text-align: right;
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--ink-2);
}

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type='range']::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: var(--track, var(--rule));
}

input[type='range']::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--track, var(--rule));
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--ink);
}

input[type='range']::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--ink);
}

input[type='range']:disabled {
  cursor: default;
  opacity: 0.4;
}

.family.unique,
.family.unique #sliders {
  display: none;
}

.family .note {
  margin-top: 8px;
}

.key {
  display: inline-block;
  width: 1.4em;
  height: 6px;
  margin: 0 0.35em 0.15em 0;
  border-radius: 3px;
  vertical-align: middle;
}

.key.band {
  background: var(--band);
}

.key.grow {
  margin-left: 0.6em;
  background: var(--grow);
}


/* buttons and fields */

button {
  font: inherit;
  color: var(--ink);
}

.toggle,
.actions button {
  padding: 6px 16px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  transition:
    background 0.15s ease,
    color 0.15s ease;
}

.toggle {
  margin-top: 8px;
  font-size: 0.95rem;
}

.toggle[aria-pressed='true'] {
  background: var(--ink);
  color: var(--card);
}

.toggle[hidden] {
  display: none;
}

.toggle:disabled {
  opacity: 0.45;
  cursor: default;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.legend {
  margin: 4px 0 12px !important;
}

.legend:empty {
  display: none;
}

#animate[aria-pressed='true'] {
  background: var(--ink);
  color: var(--card);
}

.actions button:disabled {
  opacity: 0.45;
  cursor: default;
}

.actions button:not(:disabled):hover,
.toggle:not(:disabled):hover {
  background: var(--ink);
  color: var(--card);
}

.fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 6px;
}

.fields label {
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 0.92rem;
  color: var(--ink-3);
}

.fields input {
  width: 100%;
  min-width: 0;
  padding: 3px 6px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-variant-numeric: tabular-nums lining-nums;
}

.fields input:focus {
  border-bottom-color: var(--ink);
}

.blocked {
  margin-top: 8px !important;
  color: var(--red);
}

.selected.none .when-some,
.selected:not(.none) .when-none {
  display: none;
}

/* ---------------------------------------------------------------- the notes */

.notes {
  display: grid;
  grid-template-columns: minmax(0, min(78vh, 760px)) minmax(280px, 340px);
  justify-content: space-between;
  gap: 32px;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
}

.notes p {
  margin: 0 0 8px;
}

.notes .hint {
  margin: 8px 0 0;
}

.notes .hint.keys {
  margin-top: 4px;
}

footer {
  margin-top: 48px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  font-size: 0.92rem;
  color: var(--ink-3);
  max-width: 46rem;
}

footer p {
  margin: 0;
}

/* --------------------------------------------------------------- small screens */

@media (max-width: 900px) {
  .play,
  .notes {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
  }

  .board-wrap {
    max-width: 640px;
    width: 100%;
    margin: 0 auto;
  }

  .board-readout {
    display: block;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 17px;
  }

  .intro {
    margin: 28px 0 22px;
  }

  .cases {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .case svg {
    max-width: 64px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sq.enter {
    animation: none;
  }

  .case,
  .live {
    transition: none;
  }
}
