@font-face {
  font-family: "Press Start 2P";
  src: url(fonts/press-start-2p.woff2) format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "VT323";
  src: url(fonts/vt323.woff2) format("woff2");
  font-display: swap;
}

:root {
  --bg: #0d0c0b;
  --ink: #f3eee6;
  --dim: #9a9184;
  --line: #2a2622;
  --edge: #5c5347;
  --gold: #ffd21f;
  --hot: #ff5b3a;
  --glow: #3d1508;
  --slab: #ffd21f;
  --slab-ink: #14110a;
  --slab-edge: #a86a00;
  --b1: #fff07a;
  --b2: #ffd21f;
  --b3: #f2a600;
  --echo: #ff5b3a;
  --echo-fill: transparent;
  --rim: 0 0 #0000;
  --halo: none;
  --weave: repeating-linear-gradient(0deg, rgb(255 255 255 / 0.035) 0 1px, transparent 1px 4px);
  --p1: #d28e05;
  --p2: #00a888;
  --p3: #e76624;
  --p4: #338ced;
  --p5: #e24d8b;
  --p6: #0aac23;
  --p7: #9887ef;
  --p8: #eb6263;
  --rest: #8f887c;
  --arcade: "Press Start 2P", ui-monospace, Menlo, Consolas, monospace;
  --pixel: "VT323", ui-monospace, Menlo, Consolas, monospace;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Noto Serif", serif;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f1e7;
  --ink: #1f1a14;
  --dim: #6f665b;
  --line: #ddd5c6;
  --edge: #1f1a14;
  --gold: #8a5a00;
  --hot: #c9310f;
  --glow: #ffcdbb;
  --slab-ink: #1f1a14;
  --slab-edge: #1f1a14;
  --b1: #1f1a14;
  --b2: #1f1a14;
  --b3: #1f1a14;
  --echo: #1f1a14;
  --echo-fill: #ffd21f;
  --rim: inset 0 0 0 2px #1f1a14;
  --halo: 0 0 2px #f6f1e7, 0 0 2px #f6f1e7, 0 0 3px #f6f1e7;
  --weave: radial-gradient(rgb(31 26 20 / 0.13) 1px, transparent 1.6px) 0 0 / 7px 7px;
  --p1: #f2a600;
  --p2: #00b894;
  --p3: #f47230;
  --p4: #257de0;
  --p5: #ee7fac;
  --p6: #008a17;
  --p7: #9887ef;
  --p8: #ec4647;
  --rest: #9a9184;
  color-scheme: light;
}

:root[data-theme="night"] {
  --bg: #000;
  --ink: #dc3626;
  --dim: #c02c1e;
  --line: #330a06;
  --edge: #7a1a10;
  --gold: #ff4f3b;
  --hot: #ff8a75;
  --glow: #3a0805;
  --slab: #c22a1b;
  --slab-ink: #000;
  --slab-edge: #5e130b;
  --b1: #ff4f3b;
  --b2: #dc3626;
  --b3: #a8261a;
  --echo: #7a1a10;
  --p1: #dc3626;
  --p2: #dc3626;
  --p3: #dc3626;
  --p4: #dc3626;
  --p5: #dc3626;
  --p6: #dc3626;
  --p7: #dc3626;
  --p8: #dc3626;
  --rest: #dc3626;
}

* {
  box-sizing: border-box;
  margin: 0;
}

body {
  background: var(--weave), var(--bg);
  color: var(--ink);
  font: 0.95rem/1.5 var(--mono);
  overflow-wrap: anywhere;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body > * {
  display: none;
}

body[data-screen="home"] > #home {
  display: block;
}

body[data-screen="ready"] > #ready,
body[data-screen="hold"] > #hold,
body[data-screen="done"] > #done {
  display: flex;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 0;
  cursor: pointer;
}

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

::placeholder {
  color: var(--dim);
  opacity: 1;
}

.label {
  display: inline-block;
  padding: 0.5rem 0.6rem 0.4rem;
  color: var(--slab-ink);
  background: var(--slab);
  box-shadow: 3px 3px 0 var(--slab-edge);
  font: 0.6rem/1.3 var(--arcade);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.plank {
  width: 100%;
  padding: 1.5rem 1rem 1.35rem;
  border: solid var(--slab-edge);
  border-width: 0 0 6px;
  color: var(--slab-ink);
  background: var(--slab) padding-box;
  box-shadow:
    inset 0 4px 0 rgb(255 255 255 / 0.35),
    inset 0 -4px 0 rgb(0 0 0 / 0.16);
  font: 1.15rem/1.3 var(--arcade);
  text-transform: uppercase;
}

.plank:active {
  border-color: transparent;
  border-width: 6px 0 0;
}

.plank:disabled {
  opacity: 0.4;
}

#go::before {
  content: "▶ ";
}

#home {
  max-width: 30rem;
  margin: 0 auto;
  padding: calc(1.5rem + env(safe-area-inset-top)) 1.25rem 3rem;
}

#logo {
  display: grid;
  justify-items: start;
  gap: 0.3em;
  margin: 0.2rem 0 1.5rem;
  font: 400 2.5rem/1 var(--arcade);
  font-size: clamp(2rem, round(down, 12.5vw, 8px), 3.5rem);
  text-transform: uppercase;
}

#logo span {
  position: relative;
  z-index: 0;
}

#logo b {
  display: block;
  color: transparent;
  background:
    repeating-linear-gradient(0deg, var(--bg) 0 1px, transparent 1px 0.125em),
    repeating-linear-gradient(90deg, var(--bg) 0 1px, transparent 1px 0.125em),
    linear-gradient(180deg, var(--b1) 0 25%, var(--b2) 25% 62.5%, var(--b3) 62.5%);
  -webkit-background-clip: text;
  background-clip: text;
  font-weight: 400;
}

#logo span::after {
  content: attr(data-word);
  position: absolute;
  inset: 0;
  z-index: -1;
  color: var(--echo-fill);
  -webkit-text-stroke: 2px var(--echo);
  transform: translate(0.12em, 0.12em);
}

#headline {
  margin-bottom: 0.6rem;
  font: 2rem/1.1 var(--pixel);
}

#headline::after {
  content: "▮";
  margin-left: 0.2em;
  color: var(--gold);
}

#pitch {
  margin-bottom: 0.6rem;
  color: var(--dim);
}

#home h2 {
  margin: 2.4rem 0 1rem;
}

#home .head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 2.4rem 0 1rem;
}

#home .head h2 {
  margin: 0;
}

#exercises,
#again,
#themes,
#views,
#log {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

#themes {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

#views {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
  margin-bottom: 1rem;
}

#exercises button,
#themes button,
#views button,
#log button,
#combine,
#shelf [data-book],
#add,
#speed button {
  padding: 0.85rem 0.8rem;
  border: 2px solid var(--edge);
  color: var(--dim);
  background: var(--bg);
  box-shadow: 3px 3px 0 var(--edge);
  font: 1.5rem/1.1 var(--pixel);
}

#exercises button:active,
#themes button:active,
#views button:active,
#log button:active,
#combine:active,
#shelf [data-book]:active,
#speed button:active {
  box-shadow: inset 3px 3px 0 var(--edge);
}

#exercises [aria-pressed="true"],
#themes [aria-pressed="true"],
#views [aria-pressed="true"],
#combine[aria-pressed="true"],
#shelf [aria-pressed="true"] {
  border-color: var(--gold);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--gold);
}

#exercises button {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#exercises button::before,
#legend span::before {
  content: "";
  display: inline-block;
  width: 0.65em;
  height: 0.65em;
  margin-right: 0.5em;
  background: var(--c);
  box-shadow: var(--rim);
}

#themes button,
#views button,
#combine {
  padding: 0.6rem 0.2rem;
  font-size: 1.3rem;
  text-transform: capitalize;
}

#combine {
  padding: 0.5rem 0.7rem;
}

#yours {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0.4rem 0 0.8rem;
  color: var(--dim);
  font-size: 0.8rem;
}

#own {
  margin-left: auto;
  padding: 0.7rem 0;
  color: var(--gold);
  font: 1.4rem var(--pixel);
  white-space: nowrap;
}

#own::before {
  content: "+ ";
}

#edit {
  width: min(24rem, 100% - 2.5rem);
  margin: 3rem auto auto;
  padding: 1.25rem;
  border: 2px solid var(--gold);
  color: var(--ink);
  background: var(--bg);
  box-shadow: 5px 5px 0 var(--edge);
}

#edit[open] {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 1rem 1.4rem;
}

#edit::backdrop {
  background: rgb(0 0 0 / 0.7);
}

#edit > :not(button) {
  grid-column: 1 / -1;
}

#name {
  width: 100%;
  padding: 0.7rem;
  border: 2px solid var(--edge);
  border-radius: 0;
  color: var(--ink);
  background: none;
  font: 1.5rem var(--pixel);
}

#reads {
  accent-color: var(--gold);
}

#trouble,
#moved {
  color: var(--dim);
  font-size: 0.85rem;
}

#edit button {
  padding: 0.7rem 0;
  color: var(--dim);
  font: 1.4rem var(--pixel);
}

#remove {
  justify-self: start;
}

#cancel {
  grid-column: 2;
}

#edit #save {
  grid-column: 3;
  color: var(--gold);
}

#stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 1.8rem;
}

#stats dt {
  color: var(--dim);
  font: 0.55rem var(--arcade);
  text-transform: uppercase;
}

#stats dd {
  margin-top: 0.3rem;
  color: var(--gold);
  font: 2.6rem/1 var(--pixel);
  font-variant-numeric: tabular-nums;
}

#stack {
  display: grid;
  gap: 3px;
  padding: 0.9rem 0.7rem 0.6rem;
  border: 2px solid var(--edge);
  box-shadow: 4px 4px 0 var(--edge);
}

#stack.bricks,
#stack.minutes {
  grid-template-columns: repeat(14, minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr);
  height: 10rem;
}

#stack.days {
  grid-template-columns: repeat(15, minmax(0, 1fr));
  grid-auto-rows: 2rem;
}

#stack button {
  min-width: 0;
  padding: 0;
  color: var(--dim);
  font: 0.65rem/1 var(--mono);
}

#stack.bricks button,
#stack.minutes button {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 5px;
}

#stack span {
  display: flex;
  flex-direction: column-reverse;
  gap: 2px;
  min-height: 0;
  overflow: hidden;
  border-bottom: 2px solid var(--line);
}

#stack i {
  flex: 0 1 auto;
  min-height: 2px;
  background: var(--c);
  box-shadow: var(--rim);
}

#stack.bricks i {
  flex-basis: 0.9rem;
}

#stack button:last-child,
#stack button[aria-pressed="true"] {
  color: var(--ink);
}

#stack button[aria-pressed="true"] span {
  border-color: var(--gold);
}

#stack.days .laid {
  color: var(--slab-ink);
  text-shadow: var(--halo);
  box-shadow: var(--rim);
  font-weight: 700;
}

#stack.days .gap {
  box-shadow: inset 0 0 0 2px var(--line);
}

#stack.days .next {
  color: var(--gold);
  box-shadow: inset 0 0 0 2px var(--gold);
}

#stack.days .outside {
  visibility: hidden;
}

#stack.days button[aria-pressed="true"] {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

#readout {
  min-height: 3em;
  margin: 1rem 0 0.5rem;
}

#legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1.1rem;
  color: var(--dim);
  font-size: 0.85rem;
}

#board {
  padding: 0;
  list-style: none;
  counter-reset: place;
}

#board:empty::after {
  content: "Your first hold sets the mark.";
  color: var(--dim);
}

#board li {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
  padding: 0.5rem 0;
  border-bottom: 2px solid var(--line);
  counter-increment: place;
}

#board li::before {
  content: counter(place, decimal-leading-zero);
  width: 2.2rem;
  color: var(--dim);
  font: 0.6rem var(--arcade);
}

#board b {
  font: 2.1rem/1 var(--pixel);
  font-variant-numeric: tabular-nums;
}

#board li:first-child b {
  color: var(--gold);
}

#board span {
  margin-left: auto;
  color: var(--dim);
}

#shelf {
  display: grid;
  gap: 0.8rem;
}

#shelf [data-book] {
  display: grid;
  gap: 0.15rem;
  color: var(--ink);
  text-align: left;
}

#shelf [data-remove] {
  justify-self: end;
  margin-top: -0.4rem;
  padding: 0.5rem 1rem;
  color: var(--dim);
  font-size: 0.85rem;
}

#add {
  margin-top: 0.8rem;
  font-size: 1.35rem;
}

#add[open] summary {
  margin-bottom: 0.8rem;
}

#paste {
  display: block;
  width: 100%;
  height: 11rem;
  padding: 0.7rem;
  border: 2px solid var(--edge);
  border-radius: 0;
  color: var(--ink);
  background: none;
  font: 1rem/1.45 var(--serif);
}

#shelve {
  width: 100%;
  padding: 0.9rem 0 0;
  color: var(--gold);
  font: 1.4rem var(--pixel);
}

#shelf b {
  font: 1.65rem/1.1 var(--pixel);
}

#shelf span {
  color: var(--dim);
  font: 0.8rem/1.4 var(--mono);
}

#shelf button > i {
  height: 6px;
  margin: 0.5rem 0 0.25rem;
  background: var(--line);
}

#shelf i i {
  display: block;
  height: 100%;
  background: var(--gold);
}

#speed {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1.2rem;
  color: var(--dim);
}

#speed button {
  width: 3.2rem;
  height: 3.2rem;
  padding: 0;
  color: var(--ink);
  font-size: 2rem;
}

#kept {
  margin-bottom: 1rem;
  color: var(--dim);
  font-size: 0.85rem;
}

#moved {
  margin-top: 0.8rem;
}

#moved:empty {
  display: none;
}

#ready,
#hold,
#done {
  position: fixed;
  inset: 0;
  flex-direction: column;
  padding: calc(1.25rem + env(safe-area-inset-top)) 1.25rem calc(1.25rem + env(safe-area-inset-bottom));
  background-color: var(--bg);
  user-select: none;
  -webkit-user-select: none;
  animation: settle 0.6s;
}

@keyframes settle {
  from,
  to {
    pointer-events: none;
  }
}

.how {
  color: var(--dim);
  text-align: center;
}

#ready {
  justify-content: space-between;
}

#ready .how {
  color: var(--ink);
  font: 1.8rem/1.05 var(--pixel);
}

#exercise {
  display: block;
  margin-bottom: 0.8rem;
  color: var(--gold);
  font: 400 1.5rem/1.3 var(--arcade);
  text-transform: uppercase;
}

#count {
  color: var(--gold);
  font: 8rem/1 var(--arcade);
  text-align: center;
  text-shadow: 0.07em 0.07em 0 var(--echo);
}

#previously {
  min-height: 6rem;
  color: var(--dim);
  font: 1.05rem/1.5 var(--serif);
}

#track {
  position: relative;
  flex: none;
  height: 18px;
  background: var(--line);
}

#fill {
  height: 100%;
  background: var(--gold);
  -webkit-mask: repeating-linear-gradient(90deg, #000 0 10px, transparent 10px 12px);
  mask: repeating-linear-gradient(90deg, #000 0 10px, transparent 10px 12px);
}

#track i {
  position: absolute;
  top: -6px;
  bottom: -6px;
  width: 3px;
  margin-left: -1px;
  background: var(--ink);
}

#chase {
  margin-top: 0.9rem;
  color: var(--dim);
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

#word {
  flex: 1;
  display: grid;
  grid-template-columns: 34fr auto 66fr;
  align-items: center;
  font: calc(min(12vw, 5rem) * var(--fit, 1)) var(--serif);
  white-space: nowrap;
}

#word span:first-child {
  text-align: right;
}

#hold.timer #word {
  display: none;
}

#hold.timer #elapsed {
  flex: 1;
  display: grid;
  place-content: center;
  color: var(--ink);
  font-size: min(30vw, 11rem);
}

#word b {
  color: var(--gold);
  font-weight: inherit;
}

#elapsed {
  color: var(--dim);
  font: 2.9rem var(--pixel);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

#hold.record {
  background: radial-gradient(circle at 50% 45%, var(--glow), var(--bg) 75%);
}

#hold.record #fill {
  background: var(--hot);
}

#hold.record #chase,
#hold.record #word b,
#done.record #time {
  color: var(--hot);
}

#done.record #verdict {
  color: var(--bg);
  background: var(--hot);
  transform: rotate(-2deg);
}

#full {
  color: var(--hot);
}

#done {
  justify-content: safe center;
  align-items: flex-start;
  overflow-y: auto;
  gap: 0.9rem;
  max-width: 30rem;
  margin: 0 auto;
}

#done > * {
  flex: none;
}

#done > :not(.label) {
  align-self: stretch;
}

#time {
  font: min(8.5rem, 30vw)/0.9 var(--pixel);
  font-variant-numeric: tabular-nums;
}

#versus {
  font: 1.75rem/1.05 var(--pixel);
}

#read,
#unsaved {
  color: var(--dim);
}

#read:empty,
#dropped:empty,
#trouble:empty {
  display: none;
}

#dropped {
  padding-left: 0.9rem;
  border-left: 3px solid var(--gold);
  color: var(--dim);
  font: italic 1.05rem/1.5 var(--serif);
}

#more {
  display: grid;
}

#more:empty {
  display: none;
}

#more::before {
  content: "Read more";
  color: var(--dim);
  font: 0.55rem var(--arcade);
  text-transform: uppercase;
}

#more a {
  overflow: hidden;
  padding: 0.4rem 0;
  color: var(--gold);
  font: 1.05rem/1.4 var(--serif);
  text-overflow: ellipsis;
  white-space: nowrap;
}

#resume {
  margin-top: 1.2rem;
}

#again {
  margin-top: 0.4rem;
}

#again .plank {
  padding: 1.1rem 0.5rem;
  font: 1.75rem/1.1 var(--pixel);
  text-transform: none;
}

#finish {
  padding: 1rem;
  color: var(--dim);
  font: 1.5rem var(--pixel);
}

@media (prefers-reduced-motion: no-preference) {
  #ready,
  #hold,
  #done {
    animation: settle 0.6s, wipe 0.24s steps(6);
  }

  #logo span {
    animation: drop 0.4s steps(5) both;
  }

  #logo span + span {
    animation-delay: 0.14s;
  }

  #logo b {
    animation: glitch 7s steps(1) 2s infinite;
  }

  #headline::after,
  #go:enabled::before {
    animation: blink 1.1s steps(1) infinite;
  }

  #stack i,
  #stack.days .laid {
    animation: drop 0.32s steps(4) both;
    animation-delay: calc(var(--n) * 22ms);
  }

  #done.record #time {
    animation: pop 0.5s steps(5);
  }
}

@keyframes wipe {
  from {
    clip-path: inset(0 0 100% 0);
  }

  to {
    clip-path: inset(0);
  }
}

@keyframes drop {
  from {
    opacity: 0;
    transform: translateY(-1.4rem);
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@keyframes glitch {
  0%,
  100% {
    transform: none;
  }

  1% {
    transform: translateX(-4px) skewX(-8deg);
  }

  2% {
    transform: translateX(3px);
  }

  3% {
    transform: none;
  }
}

@keyframes pop {
  from {
    transform: scale(1.5);
  }
}
