:root {
  --paper: #f6f1e7;
  --ink: #1d1d1f;
  --yellow: #ffd23f;
  --red: #ff5d4d;
  --blue: #3d5afe;
  --green: #2ecc71;
  --keycap: #ffffff;
  --shadow: 0 6px 0 var(--ink);
  --shadow-sm: 0 4px 0 var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Space Grotesk", system-ui, -apple-system, sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  max-width: 860px;
  margin: 0 auto;
  padding: clamp(1.2rem, 4vw, 2.5rem);
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
  gap: clamp(1.2rem, 3vh, 2rem);
}

.screen[hidden] { display: none; }

.screen > * { min-width: 0; max-width: 100%; }

.kicker {
  font-family: "Archivo Black", Impact, "Arial Black", sans-serif;
  font-size: clamp(0.7rem, 2.4vw, 0.9rem);
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--red);
  margin: 0;
  overflow-wrap: anywhere;
}

.title {
  font-family: "Archivo Black", Impact, "Arial Black", sans-serif;
  font-size: clamp(2.2rem, 8.5vw, 5rem);
  line-height: 1.05;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  margin: 0;
  overflow-wrap: anywhere;
}

.result-title { font-size: clamp(1.8rem, 6.5vw, 3.4rem); }

.explainer {
  max-width: 34rem;
  font-size: clamp(1rem, 2.6vw, 1.15rem);
  line-height: 1.6;
  margin: 0;
}

.explainer strong {
  background: var(--yellow);
  padding: 0 0.3em;
  box-shadow: inset 0 -0.15em 0 rgba(0, 0, 0, 0.15);
}

.footnote {
  color: var(--red);
  font-weight: 700;
  margin: 0;
  font-size: 0.95rem;
}

/* ---- speed picker ---- */

.speed-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.picker-label {
  font-family: "Archivo Black", Impact, "Arial Black", sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  margin: 0;
  overflow-wrap: anywhere;
}

.speed-row {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  max-width: 21rem;
}

.key-speed {
  flex: 1 0 auto;
  min-width: 0;
  white-space: nowrap;
  font-size: clamp(0.7rem, 2.6vw, 0.95rem);
  padding: 0.55em 0.55em;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

.key-speed span {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 0.8em;
  opacity: 0.7;
  margin-left: 0.25em;
}

.key-speed.is-selected {
  background: var(--blue);
  color: #fff;
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--ink);
}

/* ---- story picker screen ---- */

#view-stories {
  justify-content: flex-start;
  padding: 0.5rem 0 1.5rem;
}

#view-stories .explainer { max-width: 24rem; }

.story-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  max-width: 22rem;
  flex-shrink: 0;
  padding-bottom: 0.25rem;
}

.key-story {
  width: 100%;
  font-size: clamp(0.85rem, 2.8vw, 1rem);
  padding: 0.55em 0.8em;
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
}

.key-story.is-selected {
  background: var(--blue);
  color: #fff;
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--ink);
}

.footer-hint {
  font-size: 0.8rem;
  opacity: 0.65;
  margin: 0.25rem 0 0;
  max-width: 24rem;
}

/* ---- keyboard keys ---- */

.key {
  font-family: "Archivo Black", Impact, "Arial Black", sans-serif;
  font-size: clamp(1.1rem, 3.4vw, 1.4rem);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--keycap);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 0.9em 2.2em;
  box-shadow: var(--shadow), inset 0 3px 0 rgba(255, 255, 255, 0.9);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
  user-select: none;
}

a.key {
  text-decoration: none;
  display: inline-block;
}

.key:hover { transform: translateY(-2px); }
.key:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--ink);
}
.key:focus-visible {
  outline: 3px dashed var(--blue);
  outline-offset: 4px;
}

.key:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--shadow-sm);
}

.key-big {
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  padding: 0.7em 1.6em;
  border-radius: 18px;
  box-shadow: 0 8px 0 var(--ink), inset 0 4px 0 rgba(255, 255, 255, 0.9);
}
.key-big:active { box-shadow: 0 2px 0 var(--ink); }

.key-small {
  font-size: 0.95rem;
  padding: 0.6em 1.2em;
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
}

.key-yellow { background: var(--yellow); }
.key-red { background: var(--red); color: #fff; }
.key-blue { background: var(--blue); color: #fff; }
.key-white { background: var(--keycap); }

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  justify-content: center;
}

.button-row .key {
  font-size: clamp(0.85rem, 2.8vw, 1.05rem);
  padding: 0.5em 1.2em;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

/* ---- play screen ---- */

.hud {
  display: flex;
  align-items: center;
  gap: clamp(0.6rem, 2vw, 1.2rem);
  width: 100%;
  flex-wrap: wrap;
  justify-content: center;
}

.timer-chip {
  font-family: "Archivo Black", Impact, "Arial Black", sans-serif;
  font-size: clamp(1.3rem, 4.5vw, 1.8rem);
  font-variant-numeric: tabular-nums;
  background: var(--ink);
  color: var(--yellow);
  border-radius: 12px;
  padding: 0.35em 0.8em;
  min-width: 6.2em;
}

.progress-track {
  flex: 1 1 10rem;
  min-width: 8rem;
  height: 18px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.word-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
  width: 100%;
}

.countdown {
  font-family: "Archivo Black", Impact, "Arial Black", sans-serif;
  font-size: clamp(6rem, 28vw, 13rem);
  line-height: 1;
  animation: pop 0.5s ease;
}

.word {
  font-family: "Archivo Black", Impact, "Arial Black", sans-serif;
  font-size: clamp(2.4rem, 11vw, 7rem);
  line-height: 1.15;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  max-width: 100%;
  overflow-wrap: anywhere;
  animation: pop 0.18s ease;
}

@keyframes pop {
  from { transform: scale(0.75); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ---- result screen ---- */

.result-sub {
  font-size: clamp(1rem, 3vw, 1.2rem);
  font-weight: 500;
  margin: 0;
  max-width: 32rem;
  white-space: pre-line;
}

.result-time,
.result-speed {
  font-size: clamp(1.2rem, 3.4vw, 1.5rem);
  margin: 0;
}

.result-time strong,
.result-speed strong {
  font-family: "Archivo Black", Impact, "Arial Black", sans-serif;
  color: var(--blue);
  font-variant-numeric: tabular-nums;
}

/* full text box owns all the scrolling when open */
body.result-full {
  overflow: hidden;
}

body.result-full .stage {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

body.result-full #view-result {
  justify-content: flex-start;
  gap: clamp(0.8rem, 2vh, 1.2rem);
}

.fulltext {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: 1.2rem 1.4rem;
  font-size: 1.05rem;
  line-height: 1.7;
  text-align: left;
  max-width: 44rem;
  white-space: pre-line;
  overflow-y: auto;
  overscroll-behavior: contain;
  max-height: 45vh;
}

body.result-full .fulltext {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  width: 100%;
  margin-top: 0.5rem;
}

@media (max-width: 480px) {
  .kicker { letter-spacing: 0.2em; }
  .word-area { min-height: 34vh; }
  .key-speed {
    font-size: 0.72rem;
    padding: 0.5em 0.45em;
  }
  .button-row .key { flex: 1 1 100%; }
}
