:root {
  --surface: #D8D6CF;
  --ink: #171716;
  --tape: #1D1D1B;
  --tape-ink: #EFEBDD;
  --metal: #B9BAB4;
  --accent: #1438C4;
  --rule: rgba(23, 23, 22, 0.38);
  --gutter: clamp(1rem, 2.4vw, 2.25rem);
  --sans: Arial, Helvetica, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

[data-section="loop"] {
  --surface: #D8D6CF;
  --ink: #171716;
  --tape: #1D1D1B;
  --tape-ink: #EFEBDD;
  --metal: #B9BAB4;
  --accent: #1438C4;
  --rule: rgba(23, 23, 22, 0.38);
}

[data-section="work"] {
  --surface: #D9562F;
  --ink: #171716;
  --tape: #171716;
  --tape-ink: #EFEBDD;
  --metal: #E5D9C5;
  --accent: #171716;
  --rule: rgba(23, 23, 22, 0.42);
}

[data-section="lab"] {
  --surface: #2946E8;
  --ink: #F1EDDF;
  --tape: #F1EDDF;
  --tape-ink: #171716;
  --metal: #1732C4;
  --accent: #F1EDDF;
  --rule: rgba(241, 237, 223, 0.44);
}

[data-section="mail"] {
  --surface: #DCD63A;
  --ink: #171716;
  --tape: #171716;
  --tape-ink: #F1EDDF;
  --metal: #C2BC29;
  --accent: #171716;
  --rule: rgba(23, 23, 22, 0.38);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100dvh;
  overflow: hidden;
}

html {
  background: var(--surface);
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.35;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body::before {
  position: fixed;
  z-index: 20;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' viewBox='0 0 4 4'%3E%3Ccircle cx='1' cy='1' r='.4' fill='%23000' fill-opacity='.26'/%3E%3C/svg%3E");
  background-size: 4px 4px;
  content: "";
  opacity: 0.055;
  pointer-events: none;
}

button,
a,
output {
  color: inherit;
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  border-radius: 0;
  background: transparent;
}

a {
  text-underline-offset: 0.2em;
}

p,
h1 {
  margin: 0;
}

::selection {
  background: var(--accent);
  color: var(--surface);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.7rem 0.9rem;
  background: var(--ink);
  color: var(--surface);
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  transform: translateY(-180%);
}

.skip-link:focus {
  transform: translateY(0);
}

#loop-canvas {
  position: fixed;
  z-index: 0;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#loop-canvas.is-dragging {
  cursor: grabbing;
}

.loop-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100dvh;
  overflow: hidden;
  pointer-events: none;
}

.machine-header {
  position: absolute;
  top: var(--gutter);
  right: var(--gutter);
  left: var(--gutter);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2rem;
  border-top: 1px solid var(--rule);
  padding-top: 0.65rem;
  font-family: var(--mono);
  font-size: clamp(0.57rem, 0.68vw, 0.68rem);
  font-weight: 650;
  letter-spacing: 0.08em;
  line-height: 1.25;
  text-transform: uppercase;
}

.machine-name,
.machine-readout {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.machine-readout {
  justify-content: flex-end;
  text-align: right;
}

.machine-readout output {
  min-width: 7.5ch;
}

.read-head-label {
  position: absolute;
  top: clamp(5.3rem, 12.5vh, 7.5rem);
  left: 50%;
  display: grid;
  justify-items: center;
  gap: 0.2rem;
  color: var(--accent);
  font-family: var(--mono);
  font-size: clamp(0.54rem, 0.65vw, 0.66rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  transform: translateX(-50%);
}

.loop-copy {
  position: absolute;
  bottom: var(--gutter);
  left: var(--gutter);
  width: min(62vw, 800px);
  pointer-events: auto;
}

.section-number,
.machine-instruction,
.loop-index {
  font-family: var(--mono);
  font-size: clamp(0.58rem, 0.7vw, 0.7rem);
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-number {
  margin-bottom: 0.45rem;
  color: var(--accent);
}

.loop-copy h1 {
  max-width: 13ch;
  font-size: clamp(2.7rem, 6.5vw, 7.2rem);
  font-weight: 800;
  letter-spacing: -0.066em;
  line-height: 0.86;
  text-wrap: balance;
}

.section-deck {
  max-width: 50ch;
  margin-top: 0.8rem;
  font-size: clamp(0.82rem, 1vw, 1rem);
  letter-spacing: -0.015em;
}

.section-actions {
  min-height: 1.5rem;
  margin-top: 0.75rem;
  font-family: var(--mono);
  font-size: clamp(0.62rem, 0.72vw, 0.72rem);
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.section-actions a {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration-thickness: 1px;
}

.section-actions a[hidden] {
  display: none;
}

.machine-instruction {
  position: absolute;
  top: clamp(5.3rem, 12.5vh, 7.5rem);
  left: var(--gutter);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.machine-instruction button {
  min-height: 44px;
  margin-block: -0.8rem;
  padding: 0 0.25rem;
  cursor: pointer;
  pointer-events: auto;
}

.machine-instruction button:hover,
.machine-instruction button:focus-visible {
  color: var(--accent);
}

.loop-index {
  position: absolute;
  right: var(--gutter);
  bottom: var(--gutter);
  width: clamp(220px, 19vw, 285px);
  border-top: 1px solid var(--rule);
  padding-top: 0.55rem;
  pointer-events: auto;
}

.loop-index > p {
  margin-bottom: 0.45rem;
  color: var(--accent);
}

.index-items {
  display: grid;
}

.index-items button {
  display: grid;
  grid-template-columns: 3.3ch 1fr;
  width: 100%;
  min-height: 44px;
  border-top: 1px solid var(--rule);
  padding: 0.42rem 0.2rem;
  cursor: pointer;
  text-align: left;
}

.index-items button:last-child {
  border-bottom: 1px solid var(--rule);
}

.index-items button:hover,
.index-items button:focus-visible {
  padding-left: 0.55rem;
  color: var(--accent);
}

.index-items button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--surface);
}

.loop-shell noscript {
  position: fixed;
  z-index: 50;
  right: 1rem;
  bottom: 1rem;
  left: 1rem;
  padding: 1rem;
  background: var(--ink);
  color: var(--surface);
  font-family: var(--mono);
  font-size: 0.75rem;
  pointer-events: auto;
}

.error-page {
  min-height: 100dvh;
}

.error-shell {
  display: grid;
  min-height: 100dvh;
  align-content: center;
  padding: var(--gutter);
}

.error-code {
  margin-bottom: 1rem;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
}

.error-shell h1 {
  max-width: 12ch;
  font-size: clamp(3rem, 8vw, 8rem);
  letter-spacing: -0.065em;
  line-height: 0.9;
}

.error-shell > p:not(.error-code) {
  margin-top: 1rem;
}

.error-shell a {
  width: max-content;
  margin-top: 2rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
}

@media (max-width: 700px) {
  :root {
    --gutter: 1rem;
  }

  .machine-header {
    gap: 1rem;
  }

  .machine-readout > :not(#section-readout) {
    display: none;
  }

  .read-head-label {
    top: 12.5vh;
  }

  .loop-copy {
    top: 55%;
    right: var(--gutter);
    bottom: auto;
    width: auto;
  }

  .loop-copy h1 {
    max-width: 11ch;
    font-size: clamp(2.25rem, 11vw, 3.5rem);
    line-height: 0.9;
  }

  .section-deck {
    max-width: 38ch;
    margin-top: 0.55rem;
    font-size: 0.78rem;
  }

  .section-actions {
    margin-top: 0.55rem;
  }

  .loop-index {
    right: var(--gutter);
    bottom: var(--gutter);
    left: var(--gutter);
    width: auto;
    padding-top: 0.4rem;
  }

  .loop-index > p {
    display: none;
  }

  .index-items {
    grid-template-columns: repeat(4, 1fr);
  }

  .index-items button {
    display: flex;
    justify-content: center;
    gap: 0.35rem;
    border-right: 1px solid var(--rule);
    padding: 0.65rem 0.2rem;
    text-align: center;
  }

  .index-items button:first-child {
    border-left: 1px solid var(--rule);
  }

  .index-items button:hover,
  .index-items button:focus-visible {
    padding-left: 0.2rem;
  }
}

@media (max-width: 700px) and (max-height: 520px) {
  .machine-instruction {
    top: 3.8rem;
  }

  .loop-copy {
    top: auto;
    right: auto;
    bottom: var(--gutter);
    width: 55%;
  }

  .loop-copy h1 {
    max-width: 10ch;
    font-size: clamp(1.85rem, 7vw, 2.65rem);
  }

  .section-number {
    margin-bottom: 0.25rem;
  }

  .section-deck,
  .section-actions {
    margin-top: 0.35rem;
    font-size: 0.62rem;
  }

  .loop-index {
    right: var(--gutter);
    bottom: var(--gutter);
    left: auto;
    width: 39%;
  }

  .index-items {
    grid-template-columns: repeat(2, 1fr);
  }

  .index-items button {
    min-height: 42px;
  }
}

@media (max-height: 660px) and (min-width: 701px) {
  .loop-copy h1 {
    font-size: clamp(2.6rem, 6vw, 4.8rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }

  #loop-canvas {
    cursor: default;
  }
}
