:root {
  --panel: rgba(18, 12, 32, 0.78);
  --edge: #140c1c;
  --main: #ffcc33;
  --sub: #8e8aa8;
  --text: #f4efe6;
  --error: #ff5470;
  --error-extra: #a8344e;
  --font-ui: 'Press Start 2P', monospace;
  --font-type: 'VT323', monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: #120d22;
  color: var(--text);
  font-family: var(--font-ui);
  overflow-x: hidden;
}

#scene {
  position: fixed;
  inset: 0 auto auto 0;
  z-index: 0;
  min-width: 100vw;
  min-height: 100vh;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px 20px 20px;
  display: flex;
  flex-direction: column;
}

/* chunky pixel border with notched corners */
.panel {
  background: var(--panel);
  box-shadow:
    0 -4px 0 0 var(--edge),
    0 4px 0 0 var(--edge),
    -4px 0 0 0 var(--edge),
    4px 0 0 0 var(--edge),
    inset 0 4px 0 0 rgba(255, 255, 255, 0.06),
    inset 0 -4px 0 0 rgba(0, 0, 0, 0.25);
}

button {
  font: inherit;
  background: none;
  border: 0;
  color: var(--sub);
  cursor: pointer;
  padding: 8px 10px;
}
button:hover, button:focus-visible { color: var(--text); }
button.active { color: var(--main); }
button:focus-visible { outline: 3px solid var(--main); outline-offset: 2px; }

.fade { transition: opacity 0.25s; }
body.typing .fade { opacity: 0; pointer-events: none; }

/* ---------- header ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.logo {
  font-size: 24px;
  color: var(--sub);
  text-decoration: none;
  text-shadow: 4px 4px 0 var(--edge);
  display: flex;
  align-items: center;
  gap: 4px;
}
.logo b { color: var(--main); font-weight: normal; }
.logo-caret {
  width: 12px;
  height: 24px;
  margin-right: 10px;
  background: var(--main);
  box-shadow: 4px 4px 0 var(--edge);
  animation: blink 1s steps(1) infinite;
}

#config {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  font-size: 10px;
  padding: 4px 8px;
}
.group { display: flex; flex-wrap: wrap; }
.sep {
  width: 4px;
  height: 20px;
  margin: 0 6px;
  background: rgba(255, 255, 255, 0.12);
}

/* ---------- test ---------- */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 5vh 0 16vh;
}

#live {
  display: flex;
  gap: 28px;
  min-height: 40px;
  font-family: var(--font-type);
  font-size: 2.4rem;
  color: var(--main);
  text-shadow: 3px 3px 0 var(--edge);
  padding: 0 6px 10px;
  opacity: 0;
  transition: opacity 0.2s;
}
body.typing #live { opacity: 1; }
#live-wpm { color: var(--text); opacity: 0.7; }

#words-wrap {
  position: relative;
  padding: 18px 26px;
}

#words {
  font-family: var(--font-type);
  font-size: 2.5rem;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  height: calc(1.35em * 3);
  overflow: hidden;
  user-select: none;
  transition: filter 0.2s;
}

.word {
  display: flex;
  height: 1.35em;
  line-height: 1.35em;
  margin-right: 0.5em;
}
.word.error { box-shadow: inset 0 -3px 0 0 var(--error); }

.l { color: var(--sub); }
.l.correct { color: var(--text); }
.l.incorrect { color: var(--error); }
.l.extra { color: var(--error-extra); }

#caret {
  position: absolute;
  left: 0;
  top: 0;
  width: 4px;
  height: 1em;
  background: var(--main);
  transition: transform 0.09s linear;
}
#caret.blink { animation: blink 1s steps(1) infinite; }

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

#focus-msg {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  padding: 20px;
}
#words-wrap.blurred #words { filter: blur(6px); opacity: 0.6; }
#words-wrap.blurred #caret { opacity: 0; }
#words-wrap.blurred #focus-msg { display: flex; }

.icon-btn {
  align-self: center;
  margin-top: 22px;
  font-size: 22px;
  text-shadow: 3px 3px 0 var(--edge);
}

/* ---------- results ---------- */
#test { display: flex; flex-direction: column; }
#result { display: flex; flex-direction: column; gap: 22px; }
#result[hidden], #test[hidden] { display: none; }

.result-top {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 28px;
  padding: 24px;
  align-items: center;
}

.label { font-size: 10px; color: var(--sub); margin-bottom: 10px; }
.big { margin-bottom: 22px; }
.big .label { font-size: 16px; }
.big .value {
  font-size: 48px;
  color: var(--main);
  text-shadow: 4px 4px 0 var(--edge);
}

#pb-badge {
  font-size: 10px;
  color: var(--edge);
  background: var(--main);
  padding: 8px 10px;
  display: inline-block;
  animation: blink 0.8s steps(1) 4;
}
#pb-badge[hidden] { display: none; }

.chart-box { position: relative; min-width: 0; }
#chart {
  width: 100%;
  height: auto;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.axis { position: absolute; left: 4px; top: -14px; font-size: 8px; color: var(--sub); }
.legend { font-size: 8px; color: var(--sub); margin-top: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.legend .k { width: 10px; height: 10px; display: inline-block; }
.legend .k.wpm { background: var(--main); }
.legend .k.raw { background: var(--sub); margin-left: 8px; }
.legend .k.err { background: var(--error); margin-left: 8px; }

.result-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 20px;
  padding: 20px 24px;
}
.stat {
  font-family: var(--font-type);
  font-size: 2rem;
  color: var(--main);
  line-height: 1;
}

/* ---------- footer ---------- */
footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 8px;
  color: var(--text);
  text-shadow: 2px 2px 0 var(--edge);
}
footer .hints { display: flex; gap: 18px; flex-wrap: wrap; }
footer button { font-size: 8px; color: var(--text); text-shadow: 2px 2px 0 var(--edge); }
footer button.active { color: var(--main); }
kbd {
  font-family: inherit;
  background: var(--text);
  color: var(--edge);
  padding: 3px 5px;
  text-shadow: none;
  box-shadow: 0 3px 0 var(--sub);
}

@media (max-width: 640px) {
  .logo { font-size: 16px; }
  #words { font-size: 1.9rem; }
  #words-wrap { padding: 14px 16px; }
  .result-top { grid-template-columns: 1fr; }
  .big .value { font-size: 32px; }
}
