/* style.css - "Home Row" visual identity for Monkey Typing Test
   Concept: everything is a keycap. Chunky, pressable surfaces on a deep jungle ground,
   banana-yellow as the single signal colour, and the tactile F/J bumps as the hero. */
@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,500;12..96,600;12..96,700;12..96,800&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --font-ui: 'Bricolage Grotesque', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --transition-fast: 0.12s ease;
  --transition-normal: 0.25s ease;

  --radius-key: 10px;
  --radius-panel: 16px;
}

/* ---------- Themes ---------- */
html.dark {
  --bg-color: #0e1f17;
  --bg-color-rgb: 14, 31, 23;
  --card-bg: #153024;
  --text-color: #e6eee2;
  --text-color-rgb: 230, 238, 226;
  --sub-color: #8fae9c;
  --accent-color: #f5c518;
  --accent-color-rgb: 245, 197, 24;
  --accent-fill: #f5c518;
  --accent-edge: #b78f00;
  --on-accent: #10261b;
  --error-color: #ff7a6b;
  --error-bg: rgba(255, 122, 107, 0.16);
  --ok-color: #6fdc9a;
  --correct-color: #e6eee2;
  --untyped-color: #6c8b79;
  --border-color: #25432f;
  --key-bg: #1e3d2d;
  --key-border: #2f5640;
  --key-edge: #0a1812;
  --key-active: #2a5039;
}

html.light {
  --bg-color: #e5ede3;
  --bg-color-rgb: 229, 237, 227;
  --card-bg: #f5f9f3;
  --text-color: #10261b;
  --text-color-rgb: 16, 38, 27;
  --sub-color: #4b6757;
  --accent-color: #7d5f00;
  --accent-color-rgb: 125, 95, 0;
  --accent-fill: #f5c518;
  --accent-edge: #b78f00;
  --on-accent: #10261b;
  --error-color: #b3271a;
  --error-bg: rgba(179, 39, 26, 0.12);
  --ok-color: #1d7a45;
  --correct-color: #10261b;
  --untyped-color: #8aa396;
  --border-color: #c3d2c6;
  --key-bg: #eef4ec;
  --key-border: #b3c5b8;
  --key-edge: #9db3a3;
  --key-active: #d7e3d9;
}

/* Font Size System */
html.font-size-small { font-size: 14px; }
html.font-size-medium { font-size: 16px; }
html.font-size-large { font-size: 18px; }

/* Typing Text Size System */
html.text-size-small .typing-container { font-size: 1.25rem; line-height: 1.8rem; }
html.text-size-medium .typing-container { font-size: 1.65rem; line-height: 2.3rem; }
html.text-size-large .typing-container { font-size: 2.1rem; line-height: 2.8rem; }

/* ---------- Base ---------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

body {
  font-family: var(--font-ui);
  background-color: var(--bg-color);
  color: var(--text-color);
  transition: background-color var(--transition-normal), color var(--transition-normal);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent-color);
  text-decoration: none;
  transition: opacity var(--transition-fast);
}
a:hover { opacity: 0.8; }

:focus-visible {
  outline: 2px solid var(--accent-fill);
  outline-offset: 3px;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--key-bg);
  border: 1px solid var(--key-border);
  border-radius: 5px;
  padding: 0.05em 0.4em;
}

/* ---------- Header ---------- */
body > header {
  border-bottom: 2px solid var(--border-color);
  background-color: rgba(var(--bg-color-rgb), 0.9);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-container {
  max-width: 1160px;
  margin: 0 auto;
  padding: 0.7rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.25rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--text-color);
  cursor: pointer;
  letter-spacing: -0.03em;
  white-space: nowrap;
}
.logo:hover { opacity: 1; }
.logo-icon {
  width: 34px;
  height: 34px;
  padding: 5px;
  fill: var(--on-accent);
  background: var(--accent-fill);
  border-radius: 9px;
  box-shadow: 0 3px 0 var(--accent-edge);
  flex-shrink: 0;
}
.logo span { color: var(--text-color); font-weight: 500; }

nav {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.nav-link {
  color: var(--sub-color);
  font-weight: 500;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  padding: 0.4rem 0.65rem;
  border-radius: 8px;
  white-space: nowrap;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}
.nav-link:hover {
  color: var(--text-color);
  background-color: rgba(var(--text-color-rgb), 0.08);
  opacity: 1;
}
.nav-link.active {
  background-color: var(--accent-fill);
  color: var(--on-accent);
  font-weight: 700;
  box-shadow: 0 2px 0 var(--accent-edge);
}

.header-actions { display: flex; align-items: center; gap: 1rem; }

.mini-streak {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background-color: var(--key-bg);
  border: 1px solid var(--key-border);
  color: var(--text-color);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.8rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- Layout ---------- */
main {
  flex: 1;
  max-width: 1160px;
  width: 100%;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 3rem;
  display: flex;
  flex-direction: column;
}

.screen { display: none; animation: screenIn 0.2s ease; }
.screen.active { display: block; }
@keyframes screenIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Buttons (keycaps) ---------- */
.btn {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 1rem;
  padding: 0.7rem 1.35rem;
  border-radius: var(--radius-key);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
  transition: transform 0.06s ease, box-shadow 0.06s ease, background-color var(--transition-fast);
}
.btn:active:not(:disabled) { transform: translateY(3px); }
.btn:disabled { cursor: not-allowed; }

.btn-primary {
  background-color: var(--accent-fill);
  color: var(--on-accent);
  box-shadow: 0 4px 0 var(--accent-edge);
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active:not(:disabled) { box-shadow: 0 1px 0 var(--accent-edge); }

.btn-secondary {
  background-color: var(--key-bg);
  color: var(--text-color);
  border-color: var(--key-border);
  box-shadow: 0 4px 0 var(--key-edge);
}
.btn-secondary:hover:not(:disabled) { background-color: var(--key-active); }
.btn-secondary:active:not(:disabled) { box-shadow: 0 1px 0 var(--key-edge); }
.btn-secondary:disabled { opacity: 0.55; box-shadow: none; transform: translateY(3px); }

.btn-accent-outline {
  background-color: transparent;
  color: var(--accent-color);
  border: 2px solid var(--accent-color);
  box-shadow: none;
}
.btn-accent-outline:hover { background-color: rgba(var(--accent-color-rgb), 0.12); }

.btn-sm {
  font-size: 0.85rem;
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
}

/* ---------- Home: hero ---------- */
.hero-section {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.65fr);
  column-gap: 3rem;
  align-items: center;
  text-align: left;
  padding: 2rem 0 1rem;
}
.hero-title    { grid-column: 1; grid-row: 1; }
.hero-subtitle { grid-column: 1; grid-row: 2; }
.hero-actions  { grid-column: 1; grid-row: 3; }
.hero-logo-box { grid-column: 2; grid-row: 1 / span 3; }
.hero-features,
.home-editorial-wrapper { grid-column: 1 / -1; }

.hero-title {
  font-size: clamp(2.6rem, 5.6vw, 4.6rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.045em;
  margin-bottom: 1.25rem;
  color: var(--text-color);
  text-wrap: balance;
}
.hero-subtitle {
  font-size: 1.2rem;
  line-height: 1.5;
  color: var(--sub-color);
  max-width: 34rem;
  margin-bottom: 2rem;
}
.hero-actions {
  display: flex;
  gap: 0.9rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

/* Signature: the F and J keys with their tactile bumps */
.hero-logo-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.75rem;
  padding: 1rem 0 1.5rem;
}
.hero-keys { display: flex; gap: 1.1rem; }
.hk {
  --hk-edge: var(--key-edge);
  position: relative;
  width: clamp(92px, 12vw, 138px);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: clamp(2.8rem, 5vw, 4.4rem);
  line-height: 1;
  border-radius: 20px;
  color: var(--text-color);
  background: var(--key-bg);
  border: 1px solid var(--key-border);
  box-shadow: 0 12px 0 var(--hk-edge), 0 22px 28px -10px rgba(0, 0, 0, 0.35);
  user-select: none;
}
.hk::after { /* the raised bump you feel with your index fingers */
  content: "";
  position: absolute;
  bottom: 15%;
  left: 50%;
  width: 28%;
  height: 6px;
  transform: translateX(-50%);
  border-radius: 3px;
  background: currentColor;
  opacity: 0.45;
}
.hk-f {
  background: var(--accent-fill);
  color: var(--on-accent);
  --hk-edge: var(--accent-edge);
  border-color: transparent;
  transform: rotate(-4deg);
  animation: keyPress 0.5s 0.5s ease-out both;
}
.hk-j {
  transform: rotate(3deg) translateY(10px);
  animation: keyPressJ 0.5s 0.95s ease-out both;
}
@keyframes keyPress {
  0%   { transform: rotate(-4deg) translateY(0); }
  45%  { transform: rotate(-4deg) translateY(10px); box-shadow: 0 2px 0 var(--hk-edge), 0 6px 10px -6px rgba(0,0,0,.3); }
  100% { transform: rotate(-4deg) translateY(0); }
}
@keyframes keyPressJ {
  0%   { transform: rotate(3deg) translateY(10px); }
  45%  { transform: rotate(3deg) translateY(20px); box-shadow: 0 2px 0 var(--hk-edge), 0 6px 10px -6px rgba(0,0,0,.3); }
  100% { transform: rotate(3deg) translateY(10px); }
}
.hero-keys-note {
  font-size: 0.9rem;
  color: var(--sub-color);
  text-align: center;
  max-width: 16rem;
  line-height: 1.4;
}

/* Feature strip */
.hero-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  width: 100%;
  margin-top: 3.5rem;
}
.feature-card {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  padding: 1.5rem;
  border-radius: var(--radius-panel);
  text-align: left;
}
.feature-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3rem;
  height: 2.4rem;
  padding: 0 0.6rem;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-color);
  background: var(--key-bg);
  border: 1px solid var(--key-border);
  border-radius: 8px;
  box-shadow: 0 3px 0 var(--key-edge);
}
.feature-card h3 { font-weight: 700; font-size: 1.15rem; margin-bottom: 0.45rem; letter-spacing: -0.01em; }
.feature-card p { font-size: 0.95rem; color: var(--sub-color); line-height: 1.5; }

/* ---------- Levels ---------- */
.levels-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1.25rem;
}
.levels-title-box h2 {
  font-size: clamp(1.9rem, 3.6vw, 2.8rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.05;
}
.levels-progress-box { display: flex; flex-direction: column; gap: 0.5rem; min-width: 270px; }
.progress-bar-container {
  background-color: var(--key-bg);
  border: 1px solid var(--key-border);
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar-fill {
  background-color: var(--accent-fill);
  height: 100%;
  width: 0%;
  border-radius: 999px;
  transition: width var(--transition-normal);
}
.progress-text {
  gap: 1rem;
  font-size: 0.88rem;
  color: var(--sub-color);
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}

.level-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.75rem;
  overflow-x: auto;
  padding: 0.25rem 0.25rem 0.9rem;
}
.level-tab {
  background: var(--key-bg);
  border: 1px solid var(--key-border);
  color: var(--sub-color);
  padding: 0.5rem 1rem;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.92rem;
  box-shadow: 0 3px 0 var(--key-edge);
  transition: color var(--transition-fast), background-color var(--transition-fast);
}
.level-tab:hover { color: var(--text-color); }
.level-tab.active {
  background-color: var(--accent-fill);
  color: var(--on-accent);
  border-color: transparent;
  box-shadow: 0 3px 0 var(--accent-edge);
}

.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
}
.level-card {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-panel);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: border-color var(--transition-fast);
}
.level-card:hover { border-color: var(--sub-color); }
.level-card.locked { border-style: dashed; background: transparent; }
.level-card.locked h3, .level-card.locked .level-desc, .level-card.locked .level-stats { opacity: 0.55; }
.level-card.completed { border-color: var(--accent-fill); border-width: 2px; padding: calc(1.25rem - 1px); }

.level-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.7rem;
}
.level-num {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--sub-color);
}
.level-badge {
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background-color: var(--key-bg);
  border: 1px solid var(--key-border);
  text-transform: capitalize;
}
.badge-beginner { color: var(--ok-color); }
.badge-elementary { color: #5fb4f0; }
.badge-intermediate { color: var(--accent-color); }
.badge-advanced { color: #f09a4c; }
.badge-expert { color: var(--error-color); }
html.light .badge-elementary { color: #1c6aa3; }
html.light .badge-advanced { color: #a85a0f; }

.level-card h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 0.35rem; line-height: 1.25; letter-spacing: -0.01em; }
.level-desc { font-size: 0.88rem; color: var(--sub-color); line-height: 1.45; margin-bottom: 1.25rem; flex-grow: 1; }

.level-stats {
  border-top: 1px solid var(--border-color);
  padding-top: 0.75rem;
  margin-bottom: 1rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--sub-color);
}
.level-stat-val { font-family: var(--font-mono); font-weight: 600; color: var(--text-color); }
.level-card-action { width: 100%; }
.btn-level-play { width: 100%; justify-content: center; }

/* ---------- Typing screen ---------- */
.typing-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 1rem;
}
.typing-title-info { display: flex; align-items: center; gap: 0.75rem; }
.typing-title-info h2 { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.03em; }
.typing-difficulty {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background-color: var(--key-bg);
  border: 1px solid var(--key-border);
  text-transform: capitalize;
}

.live-stats {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  padding: 0.5rem 1.25rem;
  border-radius: 12px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--sub-color);
}
.live-stats-item { display: flex; align-items: center; gap: 0.4rem; }
.live-stats-val { font-weight: 600; color: var(--text-color); min-width: 2ch; }
#live-wpm { color: var(--accent-color); }

.modes-bar {
  display: flex;
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  padding: 0.35rem;
  border-radius: 14px;
  margin-bottom: 1.5rem;
  overflow-x: auto;
  gap: 0.25rem;
}
.mode-btn {
  background: transparent;
  border: none;
  color: var(--sub-color);
  padding: 0.55rem 1.1rem;
  font-family: var(--font-ui);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 10px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}
.mode-btn:hover { color: var(--text-color); }
.mode-btn.active {
  background-color: var(--accent-fill);
  color: var(--on-accent);
  box-shadow: 0 2px 0 var(--accent-edge);
}

.mode-subconfigs {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: -0.5rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}
.subconfig-btn {
  background-color: var(--key-bg);
  border: 1px solid var(--key-border);
  color: var(--sub-color);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.35rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--key-edge);
  transition: color var(--transition-fast), border-color var(--transition-fast);
}
.subconfig-btn:hover { color: var(--text-color); }
.subconfig-btn.active { color: var(--on-accent); background: var(--accent-fill); border-color: transparent; box-shadow: 0 2px 0 var(--accent-edge); }

/* The typing sheet */
.typing-area-wrapper {
  background-color: var(--card-bg);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-panel);
  padding: 2.5rem 2.75rem;
  position: relative;
  margin-bottom: 2rem;
  overflow: hidden;
}

.typing-container {
  font-family: var(--font-mono);
  letter-spacing: 0;
  color: var(--untyped-color);
  outline: none;
  user-select: none;
  cursor: text;
  text-align: left;
  max-height: 140px;
  overflow: hidden;
  position: relative;
}

.blur-overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(var(--bg-color-rgb), 0.88);
  backdrop-filter: blur(5px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}
.typing-area-wrapper.blurred .blur-overlay { opacity: 1; pointer-events: auto; }
.blur-overlay p { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; color: var(--text-color); }

.typing-container-inner {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  position: relative;
  top: 0;
  transition: top var(--transition-normal);
}
.word { margin-right: 0.6em; margin-bottom: 0.3em; display: inline-flex; white-space: nowrap; }
.char { position: relative; transition: color var(--transition-fast); }
.char.correct { color: var(--correct-color); }
.char.incorrect {
  color: var(--error-color);
  background-color: var(--error-bg);
  border-radius: 3px;
}

.caret {
  position: absolute;
  width: 3px;
  height: 1.25em;
  background-color: var(--accent-fill);
  border-radius: 2px;
  z-index: 5;
  transition: left 0.08s ease-out, top 0.08s ease-out;
}
html.caret-line .caret { width: 3px; }
html.caret-block .caret { width: 0.6em; opacity: 0.55; border-radius: 3px; }
html.caret-underline .caret { width: 0.6em; height: 3px !important; transform: translateY(1.1em); }
.caret.blinking { animation: caretBlink 1s infinite; }
@keyframes caretBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.typing-footer-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  color: var(--sub-color);
  margin-top: -0.75rem;
  margin-bottom: 2rem;
  gap: 1rem;
}
.typing-tip { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.keycap {
  background-color: var(--key-bg);
  padding: 0.05rem 0.45rem;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-color);
  border: 1px solid var(--key-border);
  box-shadow: 0 2px 0 var(--key-edge);
}

/* ---------- Virtual keyboard ---------- */
.keyboard-panel { margin-bottom: 2rem; }
.virtual-keyboard {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-width: 860px;
  margin: 0 auto;
  padding: 1rem 1rem 1.1rem;
  background-color: rgba(var(--text-color-rgb), 0.04);
  border-radius: 18px;
  border: 1px solid var(--border-color);
}
.keyboard-row { display: flex; justify-content: center; gap: 0.4rem; width: 100%; }
.keyboard-key {
  height: 44px;
  background-color: var(--key-bg);
  border: 1px solid var(--key-border);
  border-radius: 8px;
  box-shadow: 0 3px 0 var(--key-edge);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  flex: 1 1 42px;
  min-width: 0;
  transition: background-color var(--transition-fast), transform 0.05s ease, box-shadow 0.05s ease;
  user-select: none;
}
.keyboard-key .single-char { font-family: var(--font-ui); font-size: 0.9rem; font-weight: 600; text-transform: uppercase; color: var(--sub-color); }
.keyboard-key .main-char { font-family: var(--font-ui); font-size: 0.85rem; font-weight: 600; color: var(--sub-color); }
.keyboard-key .shift-char { font-family: var(--font-ui); font-size: 0.7rem; color: var(--sub-color); opacity: 0.65; }

.key-backspace { flex-grow: 2.2; }
.key-tab { flex-grow: 1.5; }
.key-capslock { flex-grow: 1.8; }
.key-enter { flex-grow: 2.2; }
.key-shift-left { flex-grow: 2.5; }
.key-shift-right { flex-grow: 2.5; }
.key-spacebar { flex-grow: 8; max-width: 320px; }

.keyboard-key.highlight-next {
  background-color: var(--accent-fill);
  border-color: transparent;
  box-shadow: 0 1px 0 var(--accent-edge);
  transform: translateY(2px);
}
.keyboard-key.highlight-next span { color: var(--on-accent); font-weight: 800; }
.keyboard-key.highlight-error {
  background-color: var(--error-bg);
  border-color: var(--error-color);
  animation: keyShake 0.15s ease;
}
.keyboard-key.highlight-error span { color: var(--error-color); }
@keyframes keyShake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ---------- Results ---------- */
.results-container {
  background-color: var(--card-bg);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-panel);
  padding: 2.75rem;
  text-align: left;
  max-width: 860px;
  margin: 0 auto;
}
.results-container #results-headline { letter-spacing: -0.035em; }
.pb-ribbon {
  background-color: var(--accent-fill);
  color: var(--on-accent);
  font-weight: 800;
  font-size: 0.9rem;
  padding: 0.35rem 1rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 3px 0 var(--accent-edge);
  animation: scaleIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes scaleIn { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.results-stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}
.result-stat-card { border-left: 3px solid var(--border-color); padding-left: 1rem; text-align: left; }
.result-stat-card.accent { border-left-color: var(--accent-fill); }
.result-stat-label { font-size: 0.88rem; color: var(--sub-color); font-weight: 500; margin-bottom: 0.2rem; }
.result-stat-val { font-family: var(--font-mono); font-size: 2.3rem; font-weight: 600; color: var(--text-color); letter-spacing: -0.03em; }
.result-stat-card.accent .result-stat-val { color: var(--accent-color); }

.result-stat-subrow {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  background-color: rgba(var(--text-color-rgb), 0.04);
  padding: 1rem 1.25rem;
  border-radius: 12px;
  margin-bottom: 2rem;
  border: 1px solid var(--border-color);
}
.result-sub-item { display: flex; flex-direction: column; gap: 0.2rem; }
.result-sub-label { font-size: 0.82rem; color: var(--sub-color); }
.result-sub-val { font-family: var(--font-mono); font-weight: 600; font-size: 1.05rem; }
.results-actions { display: flex; justify-content: flex-start; gap: 0.9rem; flex-wrap: wrap; }

/* ---------- Custom text ---------- */
.custom-text-panel {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-panel);
  padding: 2.25rem;
  max-width: 760px;
  margin: 0 auto 2rem;
}
.custom-text-panel h2 { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.035em; margin-bottom: 0.5rem; }
.custom-textarea {
  width: 100%;
  height: 160px;
  background-color: var(--bg-color);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  color: var(--text-color);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  margin-bottom: 1.25rem;
}
.custom-textarea:focus { border-color: var(--accent-fill); }
.custom-configs-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.custom-time-input-box { display: flex; align-items: center; gap: 0.5rem; }
.custom-time-input-box label { font-size: 0.9rem; color: var(--sub-color); font-weight: 600; }
.input-field {
  width: 90px;
  background-color: var(--bg-color);
  border: 2px solid var(--border-color);
  padding: 0.4rem 0.6rem;
  color: var(--text-color);
  font-family: var(--font-mono);
  border-radius: 8px;
  outline: none;
  font-weight: 500;
}
.input-field:focus { border-color: var(--accent-fill); }

/* ---------- Statistics ---------- */
.stats-header-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}
.stat-box {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-panel);
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.stat-box-icon { font-size: 1.7rem; line-height: 1; }
.stat-box-content { display: flex; flex-direction: column; }
.stat-box-label { font-size: 0.88rem; color: var(--sub-color); font-weight: 500; }
.stat-box-val { font-family: var(--font-mono); font-size: 1.7rem; font-weight: 600; color: var(--text-color); letter-spacing: -0.03em; }

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(400px, 100%), 1fr));
  gap: 1.25rem;
  margin-bottom: 2.5rem;
}
.chart-card { background-color: var(--card-bg); border: 1px solid var(--border-color); border-radius: var(--radius-panel); padding: 1.5rem; }
.chart-card h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 1.25rem; display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.chart-card h3 span { font-size: 0.82rem; color: var(--sub-color); font-weight: 500; }
.chart-container-el { width: 100%; height: 180px; position: relative; }
.chart-placeholder {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--sub-color);
  font-size: 0.92rem;
  border: 2px dashed var(--border-color);
  border-radius: 12px;
}

/* ---------- Settings ---------- */
.settings-container {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-panel);
  padding: 2.5rem;
  max-width: 760px;
  margin: 0 auto;
}
.settings-container h2 { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.035em; margin-bottom: 1.75rem; }
.settings-section { display: flex; flex-direction: column; gap: 1.25rem; }
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1.25rem;
}
.setting-row:last-child { border-bottom: none; }
.setting-info { display: flex; flex-direction: column; gap: 0.2rem; }
.setting-label { font-size: 1rem; font-weight: 700; }
.setting-desc { font-size: 0.88rem; color: var(--sub-color); line-height: 1.4; }
.setting-control { min-width: 140px; display: flex; justify-content: flex-end; }

.select-field {
  background-color: var(--key-bg);
  border: 1px solid var(--key-border);
  color: var(--text-color);
  padding: 0.5rem 0.9rem;
  font-family: var(--font-ui);
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: 9px;
  box-shadow: 0 3px 0 var(--key-edge);
  outline: none;
  cursor: pointer;
}
.select-field:focus-visible { outline: 2px solid var(--accent-fill); outline-offset: 2px; }

.switch { position: relative; display: inline-block; width: 52px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--key-bg);
  border: 1px solid var(--key-border);
  transition: background-color 0.15s;
  border-radius: 8px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 22px;
  left: 3px;
  top: 3px;
  background-color: var(--sub-color);
  box-shadow: 0 2px 0 var(--key-edge);
  transition: transform 0.15s, background-color 0.15s;
  border-radius: 5px;
}
input:checked + .slider { background-color: rgba(var(--accent-color-rgb), 0.22); border-color: var(--accent-fill); }
input:checked + .slider:before { transform: translateX(24px); background-color: var(--accent-fill); box-shadow: 0 2px 0 var(--accent-edge); }
input:focus-visible + .slider { outline: 2px solid var(--accent-fill); outline-offset: 2px; }

/* ---------- About ---------- */
.about-card {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-panel);
  padding: 2.75rem;
  max-width: 800px;
  margin: 0 auto;
}
.about-card h2 { font-size: 2.2rem; font-weight: 800; letter-spacing: -0.04em; margin-bottom: 1.25rem; }
.about-card h3 { font-size: 1.25rem; font-weight: 700; margin-top: 1.75rem; margin-bottom: 0.7rem; }
.about-card p { color: var(--sub-color); font-size: 1.02rem; line-height: 1.7; margin-bottom: 1rem; max-width: 66ch; }
.about-card ul { list-style: none; padding-left: 0; margin-bottom: 1.5rem; }
.about-card li { margin-bottom: 0.55rem; color: var(--sub-color); font-size: 1rem; line-height: 1.55; display: flex; align-items: baseline; gap: 0.7rem; max-width: 66ch; }
.about-card li:before { content: ""; flex: 0 0 8px; height: 8px; margin-top: 0.1em; border-radius: 2px; background: var(--accent-fill); }

/* ---------- Daily challenge ---------- */
.daily-intro-card {
  background-color: var(--card-bg);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-panel);
  padding: 2.5rem 2rem;
  max-width: 760px;
  margin: 0 auto 2rem;
  text-align: center;
}
.daily-intro-header { font-weight: 800; font-size: clamp(1.6rem, 3.4vw, 2.3rem); letter-spacing: -0.035em; line-height: 1.1; margin-bottom: 0.5rem; }
.daily-intro-sub { color: var(--sub-color); font-size: 1rem; margin-bottom: 1.75rem; }
#daily-preview-box { text-align: left; background-color: var(--bg-color) !important; border: 2px solid var(--border-color) !important; border-radius: 12px !important; }
.daily-records-row { display: flex; justify-content: center; gap: 2.5rem; margin-bottom: 2rem; flex-wrap: wrap; }
.daily-rec-item { display: flex; flex-direction: column; gap: 0.15rem; }
.daily-rec-label { font-size: 0.85rem; color: var(--sub-color); }
.daily-rec-val { font-family: var(--font-mono); font-size: 1.3rem; font-weight: 600; }
.daily-actions { display: flex; justify-content: center; }

/* ---------- Footer ---------- */
footer {
  border-top: 2px solid var(--border-color);
  background-color: var(--bg-color);
  color: var(--sub-color);
  font-size: 0.88rem;
  padding: 1.75rem 0;
  margin-top: auto;
}
.footer-content {
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem 2rem;
}
.footer-links { display: flex; gap: 1.25rem; flex-wrap: wrap; }
footer a { color: var(--text-color); }
footer a:hover { color: var(--accent-color); opacity: 1; }

/* ---------- Home: long-form content ---------- */
.home-editorial-wrapper { margin-top: 5rem; width: 100%; text-align: left; }

.academy-banner {
  background: var(--card-bg);
  border: 2px solid var(--accent-fill);
  border-radius: var(--radius-panel);
  padding: 1.75rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 4rem;
}
.academy-banner h3 { font-size: 1.45rem; letter-spacing: -0.02em; margin-bottom: 0.4rem; }
.academy-banner p { color: var(--sub-color); font-size: 1rem; line-height: 1.55; margin: 0; max-width: 46rem; }

.editorial-section {
  display: grid;
  grid-template-columns: minmax(0, 16rem) minmax(0, 1fr);
  column-gap: 4rem;
  align-items: start;
  border-top: 2px solid var(--text-color);
  padding: 1.75rem 0 4rem;
}
.editorial-section > h2 {
  grid-column: 1;
  grid-row: 1 / span 12;
  position: sticky;
  top: 6rem;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.03em;
  color: var(--text-color);
}
.editorial-section > h2 span { display: none; }
.editorial-section > :not(h2) { grid-column: 2; max-width: 44rem; }
.editorial-section h3 { font-size: 1.15rem; font-weight: 700; color: var(--text-color); margin: 1.5rem 0 0.7rem; }
.editorial-section p { color: var(--text-color); font-size: 1.08rem; line-height: 1.7; margin-bottom: 1.2rem; }
.editorial-section ul, .editorial-section ol { margin-left: 1.25rem; margin-bottom: 1.5rem; line-height: 1.65; font-size: 1.05rem; }
.editorial-section li { margin-bottom: 0.55rem; padding-left: 0.25rem; }
.editorial-section li::marker { color: var(--accent-color); }

/* WPM bands as a ladder */
.benchmark-grid { display: flex; flex-direction: column; margin: 1.25rem 0 1.75rem; border-top: 1px solid var(--border-color); }
.benchmark-card {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  grid-template-areas: "wpm tier" "wpm desc";
  column-gap: 1.25rem;
  align-items: baseline;
  padding: 1.1rem 0 1.1rem 1rem;
  border-bottom: 1px solid var(--border-color);
  border-left: 4px solid var(--border-color);
  text-align: left;
}
.benchmark-card.highlight { border-left-color: var(--accent-fill); }
.benchmark-wpm { grid-area: wpm; font-family: var(--font-mono); font-size: 1.5rem; font-weight: 600; color: var(--text-color); letter-spacing: -0.04em; }
.benchmark-card.highlight .benchmark-wpm { color: var(--accent-color); }
.benchmark-tier { grid-area: tier; font-weight: 700; font-size: 1.05rem; margin-bottom: 0.2rem; }
.benchmark-desc { grid-area: desc; font-size: 0.97rem; color: var(--sub-color); line-height: 1.55; }

/* FAQ */
.faq-grid { display: flex; flex-direction: column; gap: 0; border-top: 1px solid var(--border-color); }
.faq-card { padding: 1.25rem 0; border-bottom: 1px solid var(--border-color); }
.faq-q { font-size: 1.12rem; font-weight: 700; margin-bottom: 0.45rem; letter-spacing: -0.01em; }
.faq-a { color: var(--sub-color); font-size: 1.02rem; line-height: 1.65; margin: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1060px) {
  .header-container { flex-wrap: wrap; row-gap: 0.5rem; }
  nav { order: 3; width: 100%; overflow-x: auto; padding-bottom: 0.25rem; }
}

@media (max-width: 860px) {
  .hero-section { grid-template-columns: 1fr; }
  .hero-title, .hero-subtitle, .hero-actions, .hero-logo-box { grid-column: 1; }
  .hero-title { grid-row: 2; }
  .hero-subtitle { grid-row: 3; }
  .hero-actions { grid-row: 4; }
  .hero-logo-box { grid-row: 1; align-items: flex-start; padding-bottom: 2rem; }
  .editorial-section { grid-template-columns: 1fr; padding-bottom: 3rem; }
  .editorial-section > h2 { grid-column: 1; grid-row: auto; position: static; margin-bottom: 1.25rem; }
  .editorial-section > :not(h2) { grid-column: 1; }
}

@media (max-width: 768px) {
  .levels-header { flex-direction: column; align-items: flex-start; }
  .typing-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .typing-area-wrapper { padding: 1.5rem; }
  .keyboard-key { height: 36px; border-radius: 6px; }
  .keyboard-key .single-char { font-size: 0.8rem; }
  .keyboard-key .shift-char { display: none; }
  .results-container, .settings-container, .about-card { padding: 1.75rem; }
  .results-stats-row { grid-template-columns: 1fr 1fr; }
  .footer-content { flex-direction: column; align-items: flex-start; }
  .setting-row { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .setting-control { justify-content: flex-start; }
  .live-stats { gap: 1rem; flex-wrap: wrap; }
  .typing-footer-info { flex-direction: column; align-items: flex-start; margin-top: 0; }
  .benchmark-card { grid-template-columns: 5.5rem 1fr; }
}

@media (max-width: 480px) {
  main { padding: 1.25rem 1rem 2rem; }
  .levels-grid { grid-template-columns: 1fr; }
  .keyboard-panel { display: none; }
  .hk { width: 84px; font-size: 2.6rem; border-radius: 16px; }
  .result-stat-card { border-left: none; border-bottom: 2px solid var(--border-color); padding-left: 0; padding-bottom: 0.5rem; }
  .result-stat-card.accent { border-bottom-color: var(--accent-fill); }
  .academy-banner { padding: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .hk-j { transform: rotate(3deg) translateY(10px); }
}
