/* ==========================================================================
   BEFANA · 5 minute typing test — web build
   One palette, one accent, hairline geometry. Nothing decorative that does
   not carry information.
   ========================================================================== */

@font-face { font-family: "JBMono"; src: url("../assets/fonts/JBMono-Light.ttf") format("truetype"); font-weight: 300; font-display: swap; }
@font-face { font-family: "JBMono"; src: url("../assets/fonts/JBMono-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "JBMono"; src: url("../assets/fonts/JBMono-Medium.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "JBMono"; src: url("../assets/fonts/JBMono-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "JBMono"; src: url("../assets/fonts/JBMono-ExtraBold.ttf") format("truetype"); font-weight: 800; font-display: swap; }

:root {
  --bg: #0a0b0c;
  --bg2: #0d0e10;
  --panel: #101113;
  --grid: #161719;
  --line: #242629;
  --line2: #1a1c1f;
  --dim: #4c5056;
  --muted: #7a7f86;
  --text: #caced3;
  --white: #eaecee;
  --accent: #8bb0a3;
  --accent2: #a0a4aa;
  --rose: #c0766a;

  --tgt-cur: #d6dce2;
  --tgt-done: #888d94;
  --tgt-fut: #9ea3aa;
  --in-ok: #858b91;
  --in-err: #c2766a;
  --in-ok-p: #4a4e53;
  --in-err-p: #5c3e3a;

  --mono: "JBMono", ui-monospace, "SF Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;

  --pad: clamp(18px, 4.4vw, 88px);
  --hud-h: clamp(128px, 20vh, 208px);
  --chart-h: clamp(140px, 22vh, 212px);
}

* { box-sizing: border-box; }

/* class selectors must never beat the hidden attribute */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior: none;
}

body::before {
  /* the faint grid the desktop build draws under everything */
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(circle at 1px 1px, var(--grid) 1px, transparent 0);
  background-size: 22px 22px;
  opacity: .55;
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 90% at 50% 42%, transparent 38%, rgba(0, 0, 0, .55) 100%);
  pointer-events: none;
  z-index: 1;
}

.app { position: relative; z-index: 2; height: 100dvh; }

/* ---------- colophon ---------------------------------------------------- */
.colophon {
  position: fixed;
  top: clamp(16px, 3vh, 34px);
  left: var(--pad);
  z-index: 5;
  line-height: 1.25;
  pointer-events: none;
}
.colophon__by { font-size: clamp(13px, 1.55vw, 19px); font-weight: 500; color: var(--text); letter-spacing: .18em; }
.colophon__by--en { font-size: clamp(9px, 1.02vw, 11px); color: var(--muted); letter-spacing: .34em; margin-top: 2px; }
.colophon__pb { margin-top: clamp(8px, 1.4vh, 16px); font-size: clamp(8px, .9vw, 10px); color: var(--dim); letter-spacing: .28em; }
.colophon__pb b { color: var(--accent2); font-weight: 500; }
/* the signature belongs to the cover: on the other screens the header needs
   the top-left corner for the WPM hero */
.app:not([data-state="ready"]) .colophon { opacity: 0; transform: translateY(-4px); }
.colophon { transition: opacity .25s, transform .25s; }

/* ---------- screens ----------------------------------------------------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  animation: screen-in .34s ease-out both;
}
.app[data-state="ready"]   #screen-ready,
.app[data-state="library"] #screen-library,
.app[data-state="typing"]  #screen-typing,
.app[data-state="result"]  #screen-result { display: flex; }

@keyframes screen-in { from { opacity: 0; } to { opacity: 1; } }

/* ======================================================================== */
/*  cover                                                                   */
/* ======================================================================== */
.screen--ready { align-items: center; justify-content: center; padding: 0 var(--pad) clamp(88px, 15vh, 150px); }

.mark {
  width: clamp(210px, 38vh, 356px);
  aspect-ratio: 1;
  margin-bottom: clamp(2px, .8vh, 12px);
}
.mark__svg { width: 100%; height: 100%; overflow: visible; }
.mark__ring { fill: none; stroke: var(--line); }
.mark__ring--outer { stroke-width: 1; opacity: .95; }
.mark__ring--inner { stroke: var(--accent2); stroke-width: .9; opacity: .55; }
.mark__bar { stroke: var(--accent); stroke-width: 5; }
.mark__dash { stroke: var(--line); stroke-width: 1; stroke-dasharray: 4 7; }
.mark__ticks line { stroke: var(--muted); stroke-width: 1; opacity: .55; }
.mark__ticks line.major { stroke: var(--text); opacity: .45; }
.mark__rot { transform-origin: 200px 200px; }
.mark__rot--a { animation: spin 34s linear infinite; }
.mark__rot--b { animation: spin 26s linear infinite reverse; }
.mark__rot circle { fill: none; stroke: var(--line2); stroke-width: 1.4; stroke-dasharray: 3 9; }
.mark__rot--a circle { stroke: var(--line); }
.mark__rot--b circle { stroke: var(--line2); }
.mark__sweep { transform-origin: 200px 200px; animation: spin 11s linear infinite; }
.mark__sweep path, .mark__sweep circle { fill: none; stroke: var(--accent); stroke-width: 4.2; stroke-linecap: butt; }
@keyframes spin { to { transform: rotate(360deg); } }

.wordmark {
  margin: 0;
  font-size: clamp(30px, 5.4vw, 62px);
  font-weight: 800;
  letter-spacing: .22em;
  color: var(--text);
  text-indent: .22em;
}
.tagline {
  margin: clamp(4px, .9vh, 10px) 0 0;
  font-size: clamp(9px, 1.1vw, 15px);
  font-weight: 500;
  letter-spacing: .42em;
  color: var(--muted);
  text-indent: .42em;
}

.press {
  margin-top: clamp(16px, 3.4vh, 38px);
  padding: 6px 10px;
  background: none;
  border: 0;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  animation: pulse 2.6s ease-in-out infinite;
}
.press__cn { font-size: clamp(12px, 1.6vw, 19px); color: var(--text); letter-spacing: .12em; }
.press__en { font-size: clamp(9px, 1vw, 11px); color: var(--muted); letter-spacing: .3em; }
@keyframes pulse {
  0%, 100% { opacity: .55; }
  50%      { opacity: 1; }
}

.armed {
  margin-top: clamp(14px, 2.6vh, 30px);
  display: flex;
  align-items: baseline;
  gap: clamp(8px, 1.4vw, 18px);
  max-width: min(680px, 78vw);
  justify-content: center;
}
.armed__tag { font-size: clamp(9px, 1.05vw, 12px); color: var(--accent); letter-spacing: .26em; white-space: nowrap; }
.armed__title {
  font-size: clamp(12px, 1.35vw, 17px);
  color: var(--text);
  letter-spacing: .14em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip {
  margin-top: clamp(10px, 1.8vh, 20px);
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 4px 12px 4px 4px;
  background: none;
  border: 1px solid var(--muted);
  color: var(--muted);
  font: inherit;
  font-size: clamp(9px, 1.02vw, 11px);
  letter-spacing: .16em;
  cursor: pointer;
  transition: border-color .16s, color .16s;
}
.chip kbd {
  border: 1px solid currentColor;
  padding: 2px 7px;
  font: inherit;
  letter-spacing: .14em;
  color: var(--accent);
}
.chip:hover { border-color: var(--accent); color: var(--accent2); }

.cover-foot {
  position: absolute;
  left: var(--pad);
  right: var(--pad);
  bottom: clamp(14px, 3vh, 34px);
}
.rule {
  position: relative;
  height: 8px;
  border-bottom: 1px solid var(--line2);
}
.rule i {
  position: absolute;
  bottom: 0;
  width: 1px;
  background: var(--line);
}
.rule i.major { height: 7px; background: var(--dim); }

.meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 8px;
  font-size: clamp(9px, 1.02vw, 11px);
  letter-spacing: .22em;
  color: var(--dim);
}
.meta__best b { color: var(--accent2); font-size: 1.5em; font-weight: 500; letter-spacing: 0; }

/* ---------- hint row ---------------------------------------------------- */
.hints {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(10px, 2.1vw, 34px);
  font-size: clamp(9px, 1.02vw, 12px);
  letter-spacing: .1em;
  color: var(--dim);
}
.hints--bottom { position: absolute; left: var(--pad); right: var(--pad); bottom: clamp(12px, 2.4vh, 24px); }
.hint { display: inline-flex; align-items: center; gap: 8px; }
.hint kbd {
  border: 1px solid var(--muted);
  color: var(--text);
  padding: 2px 7px;
  font: inherit;
  letter-spacing: .14em;
  line-height: 1.5;
}
.hint b { font-weight: 400; color: var(--muted); letter-spacing: .14em; }
.hint--hot kbd { border-color: var(--accent); color: var(--accent); }
.hint--hot b { color: var(--accent2); }
.hint--off kbd { border-color: var(--line); color: var(--dim); }
.hint--off b { color: var(--dim); }

/* ======================================================================== */
/*  library                                                                 */
/* ======================================================================== */
.screen--library { padding: calc(var(--hud-h) * .42) var(--pad) clamp(60px, 9vh, 96px); }
.lib { display: grid; grid-template-columns: minmax(150px, 19%) 1fr; gap: clamp(18px, 3.4vw, 56px); height: 100%; min-height: 0; }

.lib__rail { display: flex; flex-direction: column; gap: 1px; overflow-y: auto; border-right: 1px solid var(--line2); padding-right: clamp(10px, 1.6vw, 24px); }
.cat {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 5px 8px;
  border: 0;
  background: none;
  color: var(--dim);
  font: inherit;
  font-size: clamp(10px, 1.16vw, 13px);
  letter-spacing: .16em;
  text-align: left;
  cursor: pointer;
  transition: color .12s;
}
.cat span { color: inherit; }
.cat em { font-style: normal; color: var(--line); font-size: .82em; letter-spacing: .1em; }
.cat:hover { color: var(--muted); }
.cat.is-on { color: var(--accent); }
.cat.is-on em { color: var(--accent2); }
.cat.is-on::before { content: ""; width: 2px; height: 1em; background: var(--accent); margin-left: -8px; }

.lib__pane { display: flex; flex-direction: column; min-height: 0; }
.lib__head { display: flex; justify-content: space-between; align-items: baseline; padding-bottom: 8px; border-bottom: 1px solid var(--line2); }
.lib__label { font-size: clamp(9px, 1vw, 11px); letter-spacing: .3em; color: var(--muted); }
.lib__count { font-size: clamp(9px, 1vw, 11px); letter-spacing: .2em; color: var(--dim); }

.lib__list { list-style: none; margin: 0; padding: 4px 0 0; overflow-y: auto; min-height: 0; }
.item {
  display: grid;
  grid-template-columns: 3em minmax(0, 1fr) 5.2em;
  gap: clamp(10px, 1.6vw, 22px);
  align-items: baseline;
  padding: clamp(5px, .95vh, 10px) 10px;
  cursor: pointer;
  border-left: 2px solid transparent;
  color: var(--dim);
  transition: color .12s, background .12s;
}
.item__no { font-size: clamp(9px, 1vw, 11px); letter-spacing: .18em; }
.item__title { font-size: clamp(12px, 1.34vw, 16px); letter-spacing: .06em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item__words { font-size: clamp(8px, .92vw, 10px); letter-spacing: .16em; text-align: right; }
.item:hover { color: var(--muted); background: rgba(139, 176, 163, .03); }
.item.is-on { color: var(--text); border-left-color: var(--accent); background: rgba(139, 176, 163, .055); }
.item.is-on .item__no { color: var(--accent); }

/* ======================================================================== */
/*  hud                                                                     */
/* ======================================================================== */
.hud {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: clamp(18px, 3.4vw, 64px);
  padding: clamp(12px, 2.4vh, 30px) var(--pad);
  min-height: var(--hud-h);
}

.hero { flex: 0 0 auto; min-width: clamp(150px, 13vw, 280px); }
.lab {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: clamp(8px, .95vw, 11px);
  font-weight: 500;
  letter-spacing: .34em;
  color: var(--muted);
}
.lab__bar { width: 4px; height: 1em; background: var(--accent); display: inline-block; }
.hero__row { display: flex; align-items: flex-end; gap: clamp(10px, 1.4vw, 20px); }
.hero__num {
  font-size: clamp(46px, 8.2vw, 132px);
  font-weight: 800;
  line-height: .86;
  color: var(--white);
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  margin-top: 6px;
}

.stats {
  display: flex;
  align-items: center;
  gap: clamp(14px, 2.4vw, 44px);
  flex: 1 1 auto;
  min-width: 0;
}
.stat { flex: 1 1 0; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--line2); padding-left: clamp(14px, 2.4vw, 44px); }
.stat .val {
  font-size: clamp(22px, 2.9vw, 48px);
  font-weight: 700;
  color: var(--text);
  line-height: 1.05;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.stat .val .unit { font-size: .55em; font-weight: 400; color: var(--dim); margin-left: 2px; }
.meter { position: relative; height: 3px; background: var(--line2); margin-top: clamp(6px, .9vh, 12px); overflow: hidden; }
.meter i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); transition: width .22s linear; }
.meter::after {
  content: "";
  position: absolute; inset: 0;
  background: repeating-linear-gradient(to right, transparent 0, transparent calc(25% - 1px), var(--bg) calc(25% - 1px), var(--bg) 25%);
  pointer-events: none;
}

.clock { position: relative; width: clamp(82px, 10.6vh, 140px); aspect-ratio: 1; flex: 0 0 auto; }
.clock svg { width: 100%; height: 100%; transform: rotate(0deg); }
.clock__track { fill: none; stroke: var(--line); stroke-width: 2; }
.clock__arc { fill: none; stroke: var(--accent); stroke-width: 3.4; stroke-linecap: butt; transform-origin: 100px 100px; transform: rotate(-90deg); }
.clock__ticks line { stroke: var(--line); stroke-width: 1; }
.clock__ticks line.on { stroke: var(--accent2); }
.clock__ticks line.major.on { stroke: var(--accent); }
.clock__time {
  position: absolute; left: 0; right: 0; top: 50%;
  transform: translateY(-58%);
  text-align: center;
  font-size: clamp(15px, 1.9vw, 30px);
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.clock__cap {
  position: absolute; left: 0; right: 0; top: 50%;
  transform: translateY(1.55em);
  text-align: center;
  font-size: clamp(7px, .78vw, 10px);
  letter-spacing: .3em;
  color: var(--dim);
}

.tools { display: flex; flex-direction: column; gap: clamp(6px, 1vh, 12px); flex: 0 0 auto; }
.icon-btn {
  width: clamp(30px, 3.4vw, 44px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  transition: color .14s, border-color .14s, background .14s;
}
.icon-btn svg { width: 56%; fill: none; stroke: currentColor; stroke-width: 1.6; }
.icon-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--bg2); }
#btn-quit:hover, #btn-quit-2:hover { color: var(--rose); border-color: var(--rose); }

/* result header tweaks */
.hud--result { min-height: clamp(120px, 19vh, 200px); }
.delta { display: flex; align-items: center; gap: 7px; padding-bottom: clamp(4px, 1vh, 14px); }
.delta__tri { width: clamp(12px, 1.3vw, 18px); stroke: none; fill: currentColor; }
.delta b { font-size: clamp(13px, 1.5vw, 20px); font-weight: 700; }
.delta span { font-size: clamp(8px, .86vw, 10px); letter-spacing: .22em; color: var(--dim); }
.delta.is-up { color: var(--accent); }
.delta.is-down { color: var(--rose); }

/* ======================================================================== */
/*  typing stage                                                            */
/* ======================================================================== */
.stage {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
  padding: 0 var(--pad);
  min-height: 0;
  --fade: clamp(18px, 3.4vh, 46px);
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - var(--fade)), transparent 100%);
  mask-image: linear-gradient(to bottom, #000 calc(100% - var(--fade)), transparent 100%);
}
.lines { position: absolute; inset: 0 var(--pad); will-change: transform; font-size: var(--fs, 18px); }

.pair { position: absolute; left: 0; right: 0; height: 100px; }
.pair__band { position: absolute; inset: 0; background: rgba(139, 176, 163, .028); opacity: 0; }
.pair.is-active .pair__band { opacity: 1; }

.pair__gut { position: absolute; left: 0; width: 3px; }
.pair.is-active .pair__gut { background: var(--accent); }
.pair.is-active .pair__gut::after {
  content: "";
  position: absolute;
  left: 12px;
  top: calc(50% + var(--rowh) * .5 - 1px);
  width: 10px; height: 1px;
  background: var(--accent);
}
.pair.is-past .pair__gut { width: 1px; background: var(--accent2); opacity: .5; }
.pair.is-future .pair__gut { width: 1px; background: var(--line2); }

.pair__row {
  position: absolute;
  left: var(--gutter, 24px);
  white-space: pre;
  letter-spacing: 0;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
}
.pair__row--tgt { top: 0; color: var(--tgt-fut); }
.pair__row--echo { color: var(--in-ok); }

.pair.is-past .pair__row--tgt,
.pair.is-past .pair__row--tgt .c { color: var(--tgt-done); }
.pair.is-active .pair__row--tgt,
.pair.is-active .pair__row--tgt .c { color: var(--tgt-cur); }
.pair.is-active .pair__row--tgt .c.done { color: var(--tgt-done); }

.pair__row--echo .e { color: var(--in-ok); }
.pair__row--echo .e.err { color: var(--in-err); border-bottom: 2px solid var(--rose); }
.pair.is-cold .pair__row--echo .e { color: var(--in-ok-p); }
.pair.is-cold .pair__row--echo .e.err { color: var(--in-err-p); border-bottom-color: var(--in-err-p); }

.caret {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  background: var(--accent);
  pointer-events: none;
  z-index: 2;
}
.caret::before {
  content: "";
  position: absolute;
  inset: 0 -4px 0 -4px;
  background: rgba(139, 176, 163, .10);
  animation: caret-pulse 1s ease-in-out infinite;
}
.pair:not(.is-active) .caret { display: none; }
.caret.is-ghost { width: calc(1ch - 5px); background: none; border-bottom: 2px solid var(--accent); }
.caret.is-ghost::before { background: rgba(139, 176, 163, .26); animation: none; inset: 0; }
@keyframes caret-pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

/* ======================================================================== */
/*  chart                                                                   */
/* ======================================================================== */
.chart { flex: 0 0 auto; height: var(--chart-h); padding: 0 var(--pad) clamp(10px, 2vh, 22px); }
.chart__box {
  position: relative;
  height: 100%;
  border: 1px solid var(--line2);
  background: rgba(16, 17, 19, .82);
}
.chart__box::before, .chart__box::after {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  border: 1px solid var(--line);
  pointer-events: none;
}
.chart__box::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.chart__box::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }
.chart canvas { display: block; width: 100%; height: 100%; }
.chart__tag {
  position: absolute;
  top: 8px; right: 12px;
  font-size: 9px;
  letter-spacing: .26em;
  color: var(--muted);
}
.chart--result { height: auto; flex: 1 1 auto; padding-bottom: clamp(52px, 7vh, 84px); }

/* ======================================================================== */
/*  toast / ime                                                             */
/* ======================================================================== */
.toast {
  position: fixed;
  left: 50%;
  bottom: clamp(74px, 12vh, 120px);
  transform: translate(-50%, 10px);
  padding: 7px 16px;
  background: rgba(16, 17, 19, .96);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: clamp(10px, 1.06vw, 13px);
  letter-spacing: .14em;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 20;
  white-space: nowrap;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.is-hot { border-color: var(--accent); color: var(--accent); }

.ime-warn {
  position: fixed;
  top: clamp(14px, 2.4vh, 28px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  align-items: baseline;
  padding: 7px 16px;
  background: rgba(192, 118, 106, .10);
  border: 1px solid rgba(192, 118, 106, .5);
  color: var(--rose);
  font-size: clamp(10px, 1.06vw, 12px);
  letter-spacing: .1em;
  z-index: 25;
}
.ime-warn b { font-weight: 500; }
.ime-warn span { color: var(--muted); }

/* ======================================================================== */
/*  responsive                                                              */
/* ======================================================================== */
@media (max-width: 1080px) {
  .colophon { display: none; }
  .hud { gap: 16px; }
  .stat + .stat { padding-left: 14px; }
}

@media (max-width: 780px) {
  :root { --hud-h: 112px; --chart-h: 104px; }
  .hud { flex-wrap: wrap; gap: 10px 18px; padding-bottom: 6px; }
  .stats { order: 3; width: 100%; }
  .clock { display: none; }
  .tools { flex-direction: row; margin-left: auto; }
  .lib { grid-template-columns: 1fr; }
  .lib__rail { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line2); padding: 0 0 6px; }
  .cat { white-space: nowrap; }
  .armed { max-width: 92vw; }
  .hints { gap: 10px 18px; }
}

button:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

@media (max-width: 1000px) {
  .hud { display: flex; flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  .mark__rot--a, .mark__rot--b, .mark__sweep, .press, .caret::before { animation: none; }
  .screen { animation: none; }
}
