:root {
  color-scheme: light;
  --paper: #f4f0e4;
  --ink: #11100e;
  --faint-ink: rgba(17, 16, 14, .62);
  --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 25% 15%, rgba(80, 63, 34, .06), transparent 30rem);
  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;
  width: min(100%, 520px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
}

.masthead,
footer {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 10px;
  padding: 0 5px;
  color: var(--faint-ink);
  font-size: clamp(8px, 2.4vw, 11px);
  text-transform: uppercase;
}

.masthead { min-height: 43px; padding-bottom: 7px; }
.masthead a, footer a { color: inherit; text-decoration: none; }
.masthead a:first-child { display: grid; }
.masthead span { font-size: .72em; letter-spacing: .08em; }
.masthead strong { color: var(--ink); font-size: clamp(13px, 4vw, 18px); }
.edition-link, footer a { text-decoration: underline; text-underline-offset: 3px; }
a:focus-visible { outline: 2px dashed var(--ink); outline-offset: 3px; }

.machine-shell {
  padding: 3px;
  border: 2px solid var(--ink);
  border-radius: 5px 9px 4px 7px;
  background: rgba(244, 240, 228, .82);
  box-shadow: 4px 5px 0 var(--ink);
}

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

.computer-art { display: block; width: 100%; height: 100%; color: var(--ink); }
.ink { fill: none; stroke: currentColor; stroke-width: 2.7; stroke-linecap: round; stroke-linejoin: round; }
.paper-fill, .panel-fill { fill: var(--paper); }
.shadow-fill { fill: var(--ink); opacity: .12; stroke: none; }
.casing { stroke-width: 4; }
.hatching { stroke-width: 1; opacity: .22; stroke-dasharray: 3 7; }
.screen-bezel { fill: url("#hatch-mobile"); stroke-width: 4; }
.screen-glass { fill: var(--screen); stroke-width: 4; }
.machine-name { fill: var(--ink); stroke: none; font: 700 25px "Courier New", monospace; letter-spacing: .025em; }
.lamp { fill: var(--paper); stroke-width: 2.6; }
.lamp:nth-child(odd) { fill: var(--ink); }
.panel-fill { stroke-width: 3; }
.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 39px "Courier New", monospace; letter-spacing: .04em; }
.electricity { opacity: 0; }
.spark { fill: none; stroke-width: 3.5; stroke-linecap: square; }

.screen {
  position: absolute;
  z-index: 2;
  left: 12%;
  top: 12%;
  width: 76%;
  height: 25.8%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  overflow: hidden;
  padding: 4% 4.5%;
  color: var(--screen-ink);
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 700;
  letter-spacing: .035em;
  text-transform: uppercase;
  -webkit-font-smoothing: none;
  text-rendering: geometricPrecision;
}

.screen p { margin: 0; }
.screen-brand { font-size: clamp(6px, 2vw, 10px); opacity: .68; white-space: nowrap; }
.share-button {
  position: absolute;
  z-index: 2;
  top: 7%;
  right: 4.5%;
  min-width: 48px;
  height: 30px;
  padding: 0 7px;
  border: 1px solid var(--screen-ink);
  color: var(--screen-ink);
  background: var(--screen);
  font: 700 clamp(7px, 2.1vw, 10px) "Courier New", monospace;
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
}
.share-button:hover:not(:disabled), .share-button:focus-visible { color: var(--screen); background: var(--screen-ink); }
.share-button:focus-visible { outline: 2px dashed var(--screen-ink); outline-offset: 3px; }
.share-button:disabled { opacity: .32; cursor: not-allowed; }
.screen-main { margin: auto 0 !important; font-size: clamp(28px, 10vw, 48px); line-height: 1; }
.cursor { animation: cursor-blink .72s steps(1) infinite; }
.diagnostics { margin: auto 0; font-size: clamp(8px, 2.7vw, 13px); line-height: 1.3; }
.diagnostics[hidden], .phrase[hidden], .screen-main[hidden] { display: none; }
.progress-track { width: 100%; height: 10px; margin: .65em 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(16px, 5.5vw, 27px); line-height: 1.02; overflow-wrap: anywhere; text-wrap: balance; }

.setting-panel {
  position: absolute;
  z-index: 3;
  top: 66.6%;
  width: 39%;
  height: 14%;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto 1fr auto;
  align-items: center;
  column-gap: 5px;
  padding: 0 2%;
  color: var(--ink);
  font-size: clamp(9px, 2.8vw, 13px);
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

.moral-panel { left: 7.1%; }
.ambition-panel { left: 53.9%; }
.setting-panel label { min-width: 0; white-space: nowrap; }
.setting-panel output { min-width: 0; font-size: .9em; white-space: nowrap; }
.setting-panel input {
  grid-column: 1;
  width: 100%;
  height: 44px;
  margin: 0;
  padding: 0;
  appearance: none;
  background: transparent;
  cursor: ew-resize;
  touch-action: none;
  accent-color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
.setting-panel input::-webkit-slider-runnable-track { height: 3px; border: 0; background: var(--ink); box-shadow: 0 2px 0 rgba(17, 16, 14, .2); }
.setting-panel input::-webkit-slider-thumb {
  width: 24px;
  height: 32px;
  margin-top: -14px;
  border: 3px solid var(--ink);
  border-radius: 2px 4px 2px 5px;
  appearance: none;
  background: var(--paper);
  box-shadow: 3px 2px 0 var(--ink);
}
.setting-panel input::-moz-range-track { height: 3px; border: 0; background: var(--ink); }
.setting-panel input::-moz-range-thumb { width: 21px; height: 29px; border: 3px solid var(--ink); border-radius: 2px 4px 2px 5px; background: var(--paper); box-shadow: 3px 2px 0 var(--ink); }
.setting-panel input:focus-visible { outline: 3px dashed var(--ink); outline-offset: 2px; }
.setting-panel input:disabled { cursor: wait; opacity: .5; }
.scale { grid-column: 1; min-width: 0; display: flex; justify-content: space-between; gap: 4px; padding-inline: 2px; color: var(--faint-ink); font-size: .6em; }
.scale span { white-space: nowrap; }

.motivate-button {
  position: absolute;
  z-index: 4;
  left: 11%;
  top: 85.1%;
  width: 78%;
  height: 10.8%;
  padding: 0;
  border: 0;
  border-radius: 5% 5% 3% 3% / 12% 12% 6% 6%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.motivate-button:active:not(:disabled) { transform: translateY(4px); }
.motivate-button:focus-visible { outline: 4px double var(--ink); outline-offset: 4px; }
.motivate-button:disabled { cursor: wait; }

.live-status {
  min-height: 2.5em;
  margin: 7px 6px 2px;
  color: var(--faint-ink);
  font-size: clamp(8px, 2.4vw, 11px);
  line-height: 1.25;
  text-align: center;
  text-transform: uppercase;
}

footer { min-height: 28px; padding-top: 5px; }

.machine.is-working .reel-left { animation: reel-spin .78s steps(6) infinite; transform-origin: 126px 480px; }
.machine.is-working .reel-right { animation: reel-spin-reverse .91s steps(7) infinite; transform-origin: 374px 480px; }
.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(4px); }
.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; }

.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 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 (min-width: 600px) {
  .app { padding-top: 14px; padding-bottom: 18px; }
  .machine-shell { padding: 7px; }
}

@media (max-height: 720px) and (orientation: landscape) {
  .app { width: min(100%, 390px); }
  .masthead, footer { display: none; }
}

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