:root {
  color-scheme: light;
  --paper: #f4f0e4;
  --ink: #11100e;
  --faint-ink: rgba(17, 16, 14, .6);
  --screen: #090909;
  --screen-ink: #f8f8ed;
}

* { box-sizing: border-box; }
html, body { min-width: 320px; min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(32, 68, 103, .075) 1px, transparent 1px),
    linear-gradient(90deg, rgba(32, 68, 103, .075) 1px, transparent 1px),
    radial-gradient(circle at 22% 18%, rgba(80, 63, 34, .06), transparent 32rem);
  background-size: 24px 24px, 24px 24px, auto;
  font-family: "Courier New", ui-monospace, monospace;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .2;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 140 140' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.26'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

.app {
  position: relative;
  min-height: 100dvh;
  display: grid;
  place-content: center;
  gap: 12px;
  padding: max(18px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.masthead,
footer,
.machine-shell { width: min(96vw, 1040px); }

.masthead,
footer {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
}

.home-link {
  display: grid;
  color: inherit;
  line-height: 1;
  text-decoration: none;
  text-transform: uppercase;
  transform: rotate(-.35deg);
}

.home-link span,
.model-number {
  color: var(--faint-ink);
  font-size: clamp(8px, 1.25vw, 11px);
  letter-spacing: .13em;
}

.home-link span { margin-bottom: 5px; }
.home-link strong { font-size: clamp(27px, 5vw, 47px); letter-spacing: -.07em; }
.home-link:hover strong { text-decoration: underline 2px wavy; text-underline-offset: 5px; }
.home-link:focus-visible { outline: 3px solid var(--ink); outline-offset: 5px; }
.model-number { margin: 0 0 4px; text-align: right; }

.machine-shell {
  padding: clamp(7px, 1.4vw, 13px);
  border: 2px solid var(--ink);
  border-radius: 3px 8px 4px 7px;
  background: rgba(244, 240, 228, .82);
  box-shadow: 5px 6px 0 var(--ink);
  transform: rotate(.08deg);
}

.machine {
  position: relative;
  width: 100%;
  aspect-ratio: 20 / 13;
  overflow: hidden;
  background: rgba(255, 254, 247, .56);
  isolation: isolate;
}

.computer-art { display: block; width: 100%; height: 100%; color: var(--ink); }
.ink { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.paper-fill { fill: var(--paper); }
.shadow-fill { fill: var(--ink); opacity: .12; stroke: none; }
.screen-bezel { fill: url("#hatch"); stroke-width: 4; }
.screen-glass { fill: var(--screen); stroke-width: 4; }
.button-shadow { fill: var(--ink); stroke-width: 3; }
.button-top { fill: var(--paper); stroke-width: 4; transform-origin: center; }
.button-drawing text { fill: var(--ink); stroke: none; font: 700 32px "Courier New", monospace; letter-spacing: .06em; }
.meters text, .left-bank text, .right-bank text { fill: var(--ink); stroke: none; font: 700 11px "Courier New", monospace; }
.lamp { fill: var(--paper); stroke-width: 2.5; }
.lamp:nth-child(odd) { fill: var(--ink); }
.scribble { stroke-width: 1.2; opacity: .72; }
.hatching { stroke-width: 1; opacity: .45; stroke-dasharray: 3 6; }
.electricity { opacity: 0; }
.spark { fill: none; stroke-width: 3.4; stroke-linecap: square; }

.setting-panel {
  position: absolute;
  z-index: 3;
  top: 57.7%;
  width: 11.4%;
  height: 10.2%;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto 1fr auto;
  align-items: center;
  column-gap: 2px;
  color: var(--ink);
  font-size: clamp(4px, .82vw, 9px);
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

.moral-panel { left: 9.4%; }
.ambition-panel { left: 79.2%; }
.setting-panel label { white-space: nowrap; }
.setting-panel output { font-size: .9em; white-space: nowrap; }
.setting-panel input {
  grid-column: 1 / -1;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  appearance: none;
  background: transparent;
  cursor: ew-resize;
  accent-color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
.setting-panel input::-webkit-slider-runnable-track {
  height: 2px;
  border: 0;
  background: var(--ink);
  box-shadow: 0 2px 0 rgba(17, 16, 14, .2);
}
.setting-panel input::-webkit-slider-thumb {
  width: clamp(8px, 1.45vw, 15px);
  height: clamp(10px, 1.8vw, 19px);
  margin-top: calc(clamp(10px, 1.8vw, 19px) / -2 + 1px);
  border: 2px solid var(--ink);
  border-radius: 1px 3px 2px 4px;
  appearance: none;
  background: var(--paper);
  box-shadow: 2px 1px 0 var(--ink);
}
.setting-panel input::-moz-range-track { height: 2px; border: 0; background: var(--ink); }
.setting-panel input::-moz-range-thumb {
  width: clamp(8px, 1.45vw, 15px);
  height: clamp(10px, 1.8vw, 19px);
  border: 2px solid var(--ink);
  border-radius: 1px 3px 2px 4px;
  background: var(--paper);
  box-shadow: 2px 1px 0 var(--ink);
}
.setting-panel input:focus-visible { outline: 2px dashed var(--ink); outline-offset: 3px; }
.setting-panel input:disabled { cursor: wait; opacity: .5; }
.scale {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 2px;
  color: var(--faint-ink);
  font-size: .72em;
  letter-spacing: -.04em;
}

.screen {
  position: absolute;
  z-index: 2;
  left: 27%;
  top: 28.2%;
  width: 46%;
  height: 29.4%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  overflow: hidden;
  padding: 2.1% 2.5%;
  color: var(--screen-ink);
  background: transparent;
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 700;
  letter-spacing: .045em;
  text-transform: uppercase;
  -webkit-font-smoothing: none;
  text-rendering: geometricPrecision;
  transform: perspective(600px) rotateX(.7deg);
}

.screen p { margin: 0; }
.screen-brand { font-size: clamp(5px, 1.15vw, 12px); opacity: .68; white-space: nowrap; }
.screen-main { margin: auto 0 !important; font-size: clamp(14px, 4.8vw, 49px); line-height: 1; }
.cursor { animation: cursor-blink .72s steps(1) infinite; }
.diagnostics { margin: auto 0; font-size: clamp(6px, 1.45vw, 15px); line-height: 1.25; }
.diagnostics[hidden], .phrase[hidden], .screen-main[hidden] { display: none; }
.progress-track { width: 100%; height: clamp(7px, 1.25vw, 13px); margin: .55em 0; border: 1px solid var(--screen-ink); padding: 2px; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--screen-ink); }
.memory { opacity: .72; }
.phrase { margin: auto 0 !important; font-size: clamp(12px, 3.25vw, 34px); line-height: 1.03; overflow-wrap: anywhere; text-wrap: balance; }

.motivate-button {
  position: absolute;
  z-index: 4;
  left: 33%;
  top: 79.5%;
  width: 34%;
  height: 12.5%;
  padding: 0;
  border: 0;
  border-radius: 8% 8% 4% 4% / 15% 15% 7% 7%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.motivate-button:active:not(:disabled) { transform: translateY(3px); }
.motivate-button:focus-visible { outline: 4px double var(--ink); outline-offset: 5px; }
.motivate-button:disabled { cursor: wait; }

.live-status {
  min-height: 1.4em;
  margin: 6px 4px 0;
  color: var(--faint-ink);
  font-size: clamp(9px, 1.5vw, 12px);
  text-align: center;
  text-transform: uppercase;
}

.machine.is-working .reel-left { animation: reel-spin .78s steps(6) infinite; transform-origin: 158px 244px; }
.machine.is-working .reel-right { animation: reel-spin-reverse .91s steps(7) infinite; transform-origin: 842px 244px; }
.machine.is-working .needle-left { animation: needle-panic .32s steps(2) infinite; transform-origin: 146px 162px; }
.machine.is-working .needle-right { animation: needle-panic .41s steps(2) infinite reverse; transform-origin: 847px 162px; }
.machine.is-working .lamp { animation: lamp-flash .45s steps(1) infinite; }
.machine.is-working .lamp-2, .machine.is-working .lamp-5 { animation-delay: -.15s; }
.machine.is-working .lamp-3, .machine.is-working .lamp-6 { animation-delay: -.3s; }
.machine.is-working .button-top { transform: translateY(3px); }
.machine.is-working .electricity { opacity: 1; }
.machine.is-working .spark-a { animation: spark-a .18s steps(2) infinite; }
.machine.is-working .spark-b { animation: spark-b .23s steps(2) infinite; }
.machine.is-working .spark-c { animation: spark-c .31s steps(2) infinite; }

footer { color: var(--faint-ink); font-size: clamp(8px, 1.25vw, 10px); }
footer p { margin: 0; }
footer p:last-child { text-align: right; }
kbd { padding: 1px 4px; border: 1px solid var(--ink); border-radius: 2px; background: rgba(255,255,255,.45); font: inherit; }

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

@keyframes cursor-blink { 50% { opacity: 0; } }
@keyframes reel-spin { to { transform: rotate(360deg); } }
@keyframes reel-spin-reverse { to { transform: rotate(-360deg); } }
@keyframes needle-panic { 50% { transform: rotate(36deg); } }
@keyframes lamp-flash { 50% { fill: var(--paper); } }
@keyframes spark-a { 50% { opacity: .05; transform: translateY(2px); } }
@keyframes spark-b { 0%, 45% { opacity: 0; } 46%, 100% { opacity: 1; transform: translateY(-1px); } }
@keyframes spark-c { 0%, 60% { opacity: 0; } 61%, 100% { opacity: .8; } }

@media (max-width: 560px) {
  .app { align-content: start; padding: max(10px, env(safe-area-inset-top)) 0 max(12px, env(safe-area-inset-bottom)); }
  .masthead, footer { width: 100%; padding-inline: 12px; }
  .machine-shell { width: 100%; padding: 3px 0 6px; border-inline: 0; border-radius: 0; box-shadow: 0 4px 0 var(--ink); }
  .home-link strong { font-size: 27px; }
  .model-number { max-width: 130px; }
  .screen { padding-top: 1.5%; }
  footer p:last-child { display: none; }
}

@media (max-height: 580px) and (orientation: landscape) {
  .app { display: flex; justify-content: center; align-items: center; padding: 3px; }
  .masthead, footer { display: none; }
  .machine-shell { width: min(98vw, 900px); padding: 3px; }
  .live-status { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}
