:root {
  --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Monaco, "Cascadia Code", monospace;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

body[data-theme="dark"] {
  --bg: #111318; --surface: #181b21; --surface-2: #1f232b;
  --text: #d6dbe4; --sub: #565f6e; --faint: #333a45;
  --accent: #e2b714; --error: #ca4754; --error-extra: #7e2a33;
  --caret: #e2b714; --chart-wpm: #e2b714; --chart-raw: #565f6e;
}
body[data-theme="midnight"] {
  --bg: #0c1022; --surface: #12172e; --surface-2: #1a2040;
  --text: #dfe4ff; --sub: #4d5893; --faint: #262d52;
  --accent: #6ee7ff; --error: #ff5c7a; --error-extra: #802a3d;
  --caret: #6ee7ff; --chart-wpm: #6ee7ff; --chart-raw: #4d5893;
}
body[data-theme="light"] {
  --bg: #eeeeee; --surface: #ffffff; --surface-2: #e2e2e2;
  --text: #2c2e33; --sub: #939aa8; --faint: #cfd3da;
  --accent: #444cf7; --error: #d84d5e; --error-extra: #f0a9b1;
  --caret: #444cf7; --chart-wpm: #444cf7; --chart-raw: #939aa8;
}
body[data-theme="matcha"] {
  --bg: #131a14; --surface: #18211a; --surface-2: #1e2a21;
  --text: #dce8dc; --sub: #5a705d; --faint: #2c3b30;
  --accent: #9ece6a; --error: #d86b6b; --error-extra: #7a3a3a;
  --caret: #9ece6a; --chart-wpm: #9ece6a; --chart-raw: #5a705d;
}
body[data-theme="dracula"] {
  --bg: #282a36; --surface: #323440; --surface-2: #3c3e4d;
  --text: #f8f8f2; --sub: #6272a4; --faint: #44475a;
  --accent: #bd93f9; --error: #ff5555; --error-extra: #8b2a2a;
  --caret: #bd93f9; --chart-wpm: #bd93f9; --chart-raw: #6272a4;
}
body[data-theme="nord"] {
  --bg: #2e3440; --surface: #3b4252; --surface-2: #434c5e;
  --text: #eceff4; --sub: #6b7a96; --faint: #4c566a;
  --accent: #88c0d0; --error: #bf616a; --error-extra: #7a3a3a;
  --caret: #88c0d0; --chart-wpm: #88c0d0; --chart-raw: #6b7a96;
}
body[data-theme="gruvbox"] {
  --bg: #282828; --surface: #32302f; --surface-2: #3c3836;
  --text: #ebdbb2; --sub: #928374; --faint: #504945;
  --accent: #fabd2f; --error: #fb4934; --error-extra: #7d2e2e;
  --caret: #fabd2f; --chart-wpm: #fabd2f; --chart-raw: #928374;
}
body[data-theme="rose"] {
  --bg: #191724; --surface: #1f1d2e; --surface-2: #26233a;
  --text: #e0def4; --sub: #6e6a86; --faint: #403d52;
  --accent: #ebbcba; --error: #eb6f92; --error-extra: #6b2d3e;
  --caret: #ebbcba; --chart-wpm: #ebbcba; --chart-raw: #6e6a86;
}
body[data-theme="ocean"] {
  --bg: #0e1e2e; --surface: #142a3e; --surface-2: #1a3450;
  --text: #cde9ff; --sub: #4a6d8a; --faint: #26405a;
  --accent: #5eead4; --error: #f87171; --error-extra: #7a2a2a;
  --caret: #5eead4; --chart-wpm: #5eead4; --chart-raw: #4a6d8a;
}
body[data-theme="crimson"] {
  --bg: #1a0f13; --surface: #24151b; --surface-2: #2e1b24;
  --text: #f5d6d6; --sub: #8a5a5a; --faint: #4a2e35;
  --accent: #f43f5e; --error: #e11d48; --error-extra: #7f1d2d;
  --caret: #f43f5e; --chart-wpm: #f43f5e; --chart-raw: #8a5a5a;
}
body[data-theme="lavender"] {
  --bg: #17111f; --surface: #211b2e; --surface-2: #2b2440;
  --text: #e9ddff; --sub: #7c6e9e; --faint: #3d3652;
  --accent: #a78bfa; --error: #f472b6; --error-extra: #7a2a4a;
  --caret: #a78bfa; --chart-wpm: #a78bfa; --chart-raw: #7c6e9e;
}
body[data-theme="amber"] {
  --bg: #1c150a; --surface: #281e0f; --surface-2: #342815;
  --text: #fde6c8; --sub: #8a7560; --faint: #4a3d2b;
  --accent: #f59e0b; --error: #ef4444; --error-extra: #7f1d1d;
  --caret: #f59e0b; --chart-wpm: #f59e0b; --chart-raw: #8a7560;
}

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

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  transition: background 0.4s ease, color 0.4s ease;
  overflow-x: hidden;
}

button { font-family: inherit; background: none; border: none; color: inherit; cursor: pointer; }
svg { width: 1em; height: 1em; fill: currentColor; vertical-align: -0.12em; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.75rem clamp(1.5rem, 5vw, 4rem);
  animation: fadeDown 0.6s var(--ease-out) both;
  position: relative;
  z-index: 100;
}
.logo {
  font-family: var(--font-mono); font-size: 1.6rem; font-weight: 600;
  color: var(--text); text-decoration: none; letter-spacing: -0.02em;
}
.logo-icon { color: var(--accent); margin-right: 0.35rem; font-size: 1.15rem; }
.cursor-dot { color: var(--accent); animation: blink 1.1s steps(1) infinite; }

.topbar-actions { display: flex; gap: 0.35rem; align-items: center; }
.ghost-btn {
  font-size: 1.25rem; color: var(--sub); padding: 0.45rem;
  border-radius: 0.6rem; transition: color 0.2s, transform 0.2s var(--ease-out), background 0.2s;
  line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.ghost-btn:hover { color: var(--text); transform: translateY(-2px); background: var(--surface); }
.ghost-btn.active-view { color: var(--accent); }

/* ---------- appearance picker ---------- */
.appearance-wrap { position: relative; z-index: 101; }
.appearance-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 252px;
  max-height: min(70vh, 420px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--faint);
  border-radius: 1rem;
  padding: 0.65rem;
  box-shadow: 0 16px 40px rgb(0 0 0 / 0.35), 0 4px 14px rgb(0 0 0 / 0.22);
  z-index: 200;
  animation: menuIn 0.22s var(--ease-out) both;
}
.appearance-menu-header {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--sub);
  padding: 0.35rem 0.55rem 0.65rem;
  flex-shrink: 0;
}
.appearance-options {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
  margin-right: -2px;
  scrollbar-width: thin;
  scrollbar-color: var(--faint) transparent;
}
.appearance-options::-webkit-scrollbar { width: 6px; }
.appearance-options::-webkit-scrollbar-track { background: transparent; }
.appearance-options::-webkit-scrollbar-thumb {
  background: var(--faint);
  border-radius: 999px;
}
.appearance-options::-webkit-scrollbar-thumb:hover { background: var(--sub); }
.appearance-option {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.58rem 0.7rem;
  border-radius: 0.7rem;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--sub);
  text-align: left;
}
.appearance-option:hover {
  background: var(--surface-2);
  color: var(--text);
  transform: translateY(-1px);
}
.appearance-option.active {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--faint);
}
.appearance-option.active .appearance-name { color: var(--accent); font-weight: 600; }
.appearance-left { display: flex; align-items: center; gap: 0.7rem; }
.appearance-name { text-transform: capitalize; font-size: 0.9rem; }
.color-dots { display: flex; gap: 0.32rem; align-items: center; }
.color-dot {
  width: 13px; height: 13px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.14);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.3), inset 0 0 0 1px rgb(0 0 0 / 0.08);
  flex-shrink: 0;
}
.appearance-check {
  font-size: 0.8rem;
  color: var(--accent);
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.2s, transform 0.2s var(--ease-out);
  margin-left: auto;
}
.appearance-option.active .appearance-check { opacity: 1; transform: none; }
.appearance-option:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.page {
  flex: 1; width: min(64rem, 92vw); margin: 0 auto;
  display: flex; flex-direction: column; justify-content: center;
  padding-bottom: 3rem;
}

.view { animation: fadeUp 0.45s var(--ease-out) both; }

/* ---------- test header (config + live stats overlay) ---------- */
.test-header {
  position: relative;
  margin-bottom: 2.75rem;
  min-height: 2.2rem;
}
.config-bar {
  display: flex; align-items: center; gap: 0.75rem;
  font-family: var(--font-mono); font-size: 0.85rem;
  color: var(--sub);
  margin-bottom: 0;
  transition: opacity 0.28s var(--ease-out), transform 0.28s var(--ease-out), visibility 0.28s;
  visibility: visible;
}
.config-bar.hidden-during-test {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
  visibility: hidden;
}
.config-group { display: flex; gap: 0.15rem; }
.cfg-btn {
  padding: 0.35rem 0.55rem; border-radius: 0.4rem; color: var(--sub);
  transition: color 0.15s, background 0.15s;
}
.cfg-btn:hover { color: var(--text); }
.cfg-btn.active { color: var(--accent); background: var(--surface-2); }
.config-divider { width: 1px; height: 1rem; background: var(--sub); opacity: 0.4; }

.live-stats {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex; align-items: flex-end; gap: 1.6rem 2rem;
  margin-bottom: 0;
  font-family: var(--font-mono);
  opacity: 0;
  transform: translateY(6px);
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.28s var(--ease-out), transform 0.28s var(--ease-out), visibility 0.28s;
  flex-wrap: wrap;
  min-height: 2.2rem;
}
.live-stats:not([hidden]) {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
  pointer-events: auto;
}
/* keep element in flow for transition despite global [hidden] */
.test-header .live-stats[hidden] {
  display: flex !important;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(6px);
}
.live-stat { display: flex; flex-direction: column; justify-content: flex-end; min-width: 2.6rem; }
.live-stat.primary { min-width: 3.2rem; }
.live-stat.secondary { min-width: 2.2rem; opacity: 0.95; }
.live-stat-label { display: block; font-size: 0.66rem; color: var(--sub); text-transform: uppercase; letter-spacing: 0.08em; line-height: 1; margin-bottom: 0.18rem; }
.live-stat-value { font-size: 1.9rem; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; font-weight: 600; }
.live-stat-value.secondary { font-size: 1.15rem; color: var(--text); font-weight: 600; }
.live-stat-value.secondary.error { color: var(--error); }
.live-stat-value.secondary.error.zero { color: var(--sub); }
.live-stat-value.bump { animation: statBump 0.28s var(--ease-out); }
@keyframes statBump { 0% { transform: scale(1); } 35% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* ---------- typing area ---------- */

.typing-area { position: relative; outline: none; }
#hiddenInput {
  position: absolute; opacity: 0; pointer-events: none;
  top: 0; left: 0; width: 1px; height: 1px;
}

.words-viewport {
  position: relative;
  height: calc(3 * 3.4rem + 0.4rem);
  overflow: hidden;
  font-family: var(--font-mono);
  filter: blur(0);
  transition: filter 0.3s;
}
.words-inner { transition: transform 0.22s var(--ease-out); position: relative; will-change: transform; }
.words {
  display: flex; flex-wrap: wrap;
  font-size: 1.7rem; line-height: 3.4rem;
  letter-spacing: 0.02em;
}
.word {
  display: inline-block; margin-right: 0.75ch; white-space: nowrap;
  border-bottom: 2px solid transparent; padding-bottom: 2px; margin-top: -4px;
  transition: border-color 0.15s;
}
.word.error-word { border-color: var(--error); }
.letter { color: var(--sub); transition: color 0.09s linear; }
.letter.correct { color: var(--text); }
.letter.incorrect { color: var(--error); }
.letter.extra-incorrect { color: var(--error-extra); }
.word.active-word .letter.current-letter { box-shadow: inset 0 -3px 0 var(--faint); border-radius: 1px; }

.caret {
  position: absolute; width: 2.5px; border-radius: 2px;
  background: var(--caret);
  left: 0; top: 0;
  transition: opacity 0.3s;
  animation: blinkCaret 1.1s steps(1) infinite;
  will-change: transform, height, opacity;
  transform: translate3d(0, 0, 0);
  pointer-events: none;
}
.caret.typing { animation: none; opacity: 1; }
.caret.hidden-caret { opacity: 0; }

.focus-overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center; text-align: center;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(6px);
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
  font-family: var(--font-mono);
}
.focus-overlay.visible { opacity: 1; pointer-events: auto; cursor: pointer; }
.focus-title { font-size: 1.15rem; color: var(--text); margin-bottom: 0.5rem; }
.focus-sub { font-size: 0.8rem; color: var(--sub); }

.bottom-bar { margin-top: 2rem; display: flex; justify-content: center; }
.restart-btn {
  font-size: 1.5rem; color: var(--sub); padding: 0.6rem 1rem; border-radius: 0.6rem;
  transition: color 0.2s, transform 0.25s var(--ease-out), background 0.2s;
}
.restart-btn:hover { color: var(--accent); transform: rotate(-40deg); background: var(--surface); }

.footer {
  padding: 1.25rem; text-align: center;
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--faint);
  animation: fadeUp 0.6s var(--ease-out) both;
}

/* ---------- results ---------- */
.result-card {
  background: var(--surface); border-radius: 1.25rem;
  padding: 2.5rem; box-shadow: 0 20px 60px rgb(0 0 0 / 0.25);
  animation: popIn 0.55s var(--ease-out) both;
}
.result-top {
  display: grid; grid-template-columns: auto 1fr; gap: 2.5rem; align-items: stretch;
}
.result-main { display: flex; flex-direction: column; gap: 1.25rem; }
.result-wpm-group { animation: fadeUp 0.5s var(--ease-out) both; }
.result-wpm-group:nth-child(2) { animation-delay: 0.1s; }
.result-label {
  display: block; font-family: var(--font-mono); font-size: 0.75rem;
  color: var(--sub); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 0.15rem;
}
.result-big {
  font-family: var(--font-mono); font-size: clamp(2.75rem, 7vw, 4rem);
  font-weight: 700; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums;
}
.result-big.acc { color: var(--text); }

.result-chart-wrap { position: relative; min-height: 180px; animation: fadeIn 0.8s 0.2s both; }
#resultChart { width: 100%; height: 100%; position: absolute; inset: 0; }

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1.5rem; margin-top: 2.25rem; padding-top: 1.75rem;
  border-top: 1px solid var(--faint);
}
.stat-cell { animation: fadeUp 0.45s var(--ease-out) both; }
.stat-key {
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--sub);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.stat-val { font-family: var(--font-mono); font-size: 1.4rem; font-weight: 600; margin-top: 0.2rem; }
.stat-val small { font-size: 0.8rem; color: var(--sub); font-weight: 400; }

.personal-bests { margin-top: 1.5rem; font-family: var(--font-mono); font-size: 0.82rem; color: var(--sub); }
.personal-bests .pb-new { color: var(--accent); animation: pulseGlow 1.6s ease-in-out infinite; }

.habit-insights { margin-top: 1.75rem; padding-top: 1.5rem; border-top: 1px solid var(--faint); }
.habit-insights-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.habit-card {
  background: var(--surface-2); border-radius: 0.85rem; padding: 1rem 1.1rem;
  border: 1px solid var(--faint); animation: fadeUp 0.45s var(--ease-out) both;
}
.habit-card-title { font-family: var(--font-mono); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--sub); margin-bottom: 0.55rem; }
.habit-card-value { font-family: var(--font-mono); font-size: 1.25rem; font-weight: 700; color: var(--text); line-height: 1; font-variant-numeric: tabular-nums; }
.habit-card-value.accent { color: var(--accent); }
.habit-card-value.error { color: var(--error); }
.habit-card-sub { font-family: var(--font-mono); font-size: 0.72rem; color: var(--sub); margin-top: 0.32rem; line-height: 1.3; }
.habit-keys { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.5rem; }
.habit-key {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.7rem; height: 1.7rem; padding: 0 0.35rem;
  font-family: var(--font-mono); font-size: 0.82rem; font-weight: 600;
  background: var(--surface); border: 1px solid var(--faint); border-radius: 0.4rem;
  color: var(--text); position: relative;
}
.habit-key.miss-1 { border-color: color-mix(in srgb, var(--error) 35%, var(--faint)); }
.habit-key.miss-2 { border-color: color-mix(in srgb, var(--error) 60%, var(--faint)); background: color-mix(in srgb, var(--error) 12%, var(--surface)); }
.habit-key.miss-3 { border-color: var(--error); background: color-mix(in srgb, var(--error) 18%, var(--surface)); color: var(--error); }
.habit-key-count {
  position: absolute; top: -6px; right: -6px;
  background: var(--error); color: #fff; font-size: 0.58rem; font-weight: 700;
  min-width: 14px; height: 14px; padding: 0 3px; border-radius: 999px;
  display: grid; place-items: center; line-height: 1;
}
.habit-empty { font-family: var(--font-mono); font-size: 0.82rem; color: var(--sub); text-align: center; padding: 0.6rem 0; }
.habit-insight-row { display: flex; flex-wrap: wrap; gap: 0.5rem 1.2rem; margin-top: 0.35rem; font-family: var(--font-mono); font-size: 0.78rem; color: var(--sub); }
.habit-insight-row strong { color: var(--text); font-weight: 600; }
.habit-bar { height: 6px; background: var(--faint); border-radius: 999px; overflow: hidden; margin-top: 0.6rem; }
.habit-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.6s var(--ease-out); }
.habit-bar-fill.error { background: var(--error); }

.result-actions { display: flex; justify-content: center; gap: 0.75rem; margin-top: 2.5rem; }
.action-btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: var(--font-mono); font-size: 0.95rem;
  padding: 0.7rem 1.4rem; border-radius: 0.7rem; color: var(--sub);
  background: var(--surface-2);
  transition: color 0.2s, transform 0.25s var(--ease-out), background 0.2s, box-shadow 0.2s;
}
.action-btn:hover { color: var(--text); transform: translateY(-2px); }
.action-btn.primary { color: var(--bg); background: var(--accent); font-weight: 600; }
.action-btn.primary:hover { box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 35%, transparent); }
.action-btn.danger:hover { color: var(--error); }

/* ---------- history ---------- */
.history-card {
  background: var(--surface); border-radius: 1.25rem; padding: 2.5rem;
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.25);
  animation: popIn 0.55s var(--ease-out) both;
}
.history-card h2 { font-family: var(--font-mono); font-weight: 600; margin-bottom: 1.25rem; }
.history-summary { font-family: var(--font-mono); font-size: 0.85rem; color: var(--sub); margin-bottom: 1.5rem; }
.history-summary strong { color: var(--accent); font-size: 1.05rem; }
.history-table {
  width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 0.88rem;
}
.history-table th {
  text-align: left; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--sub); padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--faint);
}
.history-table td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--faint); }
.history-table tbody tr { transition: background 0.15s; animation: fadeUp 0.35s var(--ease-out) both; }
.history-table tbody tr:hover { background: var(--surface-2); }
.history-table .wpm-col { color: var(--accent); font-weight: 600; }
.history-empty { padding: 2rem 0; text-align: center; color: var(--sub); font-family: var(--font-mono); }
.history-actions { display: flex; gap: 0.75rem; margin-top: 2rem; justify-content: flex-end; }

/* ---------- profile ---------- */
.profile-view {
  display: flex; justify-content: center; align-items: flex-start;
  padding-top: 0.5rem;
}
.profile-card {
  background: var(--surface); border-radius: 1.25rem; padding: 2.5rem;
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.25);
  width: 100%; max-width: 56rem;
  animation: popIn 0.55s var(--ease-out) both;
}
.profile-header {
  display: flex; flex-direction: column; gap: 0.2rem;
  margin-bottom: 1.75rem; border-bottom: 1px solid var(--faint); padding-bottom: 1.5rem;
}
.profile-title-row { display: flex; justify-content: space-between; align-items: center; }
.profile-card h2 { font-family: var(--font-mono); font-weight: 700; font-size: 1.55rem; letter-spacing: -0.02em; }
.profile-subtitle { font-family: var(--font-mono); font-size: 0.82rem; color: var(--sub); }
.profile-back-ghost { font-size: 0.9rem; width: 2rem; height: 2rem; display: grid; place-items: center; border-radius: 0.5rem; }

.profile-empty { text-align: center; padding: 2.5rem 1rem 1rem; font-family: var(--font-mono); }
.profile-empty-icon { font-size: 2.2rem; margin-bottom: 0.75rem; }
.profile-empty-title { font-size: 1.05rem; font-weight: 600; color: var(--text); }
.profile-empty-sub { font-size: 0.82rem; color: var(--sub); margin: 0.35rem 0 1.4rem; }

.profile-hero {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.9rem; margin-bottom: 0.5rem;
}
.profile-hero-card {
  background: var(--surface-2); border-radius: 0.9rem; padding: 1.15rem 0.9rem;
  text-align: center; border: 1px solid transparent;
  transition: transform 0.2s var(--ease-out), border-color 0.2s, box-shadow 0.2s;
  animation: fadeUp 0.45s var(--ease-out) both;
}
.profile-hero-card:nth-child(2) { animation-delay: 0.06s; }
.profile-hero-card:nth-child(3) { animation-delay: 0.12s; }
.profile-hero-card:nth-child(4) { animation-delay: 0.18s; }
.profile-hero-card:hover { transform: translateY(-2px); border-color: var(--faint); box-shadow: 0 6px 18px rgb(0 0 0 / 0.12); }
.profile-hero-value {
  font-family: var(--font-mono); font-size: 1.85rem; font-weight: 700;
  color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums;
}
.profile-hero-value.accent-text { color: var(--text); }
.profile-hero-label {
  font-family: var(--font-mono); font-size: 0.64rem; text-transform: uppercase;
  letter-spacing: 0.11em; color: var(--sub); margin-top: 0.42rem;
}
.profile-hero-sub {
  font-family: var(--font-mono); font-size: 0.68rem; color: var(--sub); opacity: 0.8; margin-top: 0.18rem;
}

.profile-section { margin-top: 2.1rem; }
.profile-section-title {
  font-family: var(--font-mono); font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.13em; color: var(--sub); margin-bottom: 0.9rem; padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--faint);
}
.profile-grid { margin-top: 0 !important; padding-top: 0 !important; border-top: none !important; }

.profile-chart-wrap {
  position: relative; height: 190px;
  background: var(--surface-2); border-radius: 0.9rem; padding: 0.9rem 0.9rem 0.6rem;
  border: 1px solid var(--faint);
  animation: fadeIn 0.6s 0.15s both;
}
#profileChart { width: 100%; height: 100%; display: block; }
.profile-chart-legend {
  display: flex; gap: 1.2rem; margin-top: 0.65rem; font-family: var(--font-mono);
  font-size: 0.7rem; color: var(--sub); align-items: center;
}
.legend-item { display: inline-flex; align-items: center; gap: 0.32rem; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.profile-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.75rem; }
.pb-table-wrap {
  background: var(--surface-2); border-radius: 0.9rem; padding: 0.45rem;
  border: 1px solid var(--faint);
}
.pb-table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 0.84rem; }
.pb-table th {
  text-align: left; font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--sub); padding: 0.55rem 0.65rem; border-bottom: 1px solid var(--faint);
}
.pb-table td { padding: 0.55rem 0.65rem; border-bottom: 1px solid var(--faint); }
.pb-table tr:last-child td { border-bottom: none; }
.pb-table td:first-child { color: var(--sub); }
.pb-table td:nth-child(2) { color: var(--accent); font-weight: 700; }
.pb-table .pb-empty { text-align: center; color: var(--sub); padding: 1.1rem; font-size: 0.8rem; }

.activity-list { display: flex; flex-direction: column; gap: 0.5rem; }
.activity-item {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface-2); border-radius: 0.7rem; padding: 0.68rem 0.85rem;
  border: 1px solid transparent; font-family: var(--font-mono); font-size: 0.82rem;
  transition: border-color 0.15s, transform 0.15s var(--ease-out);
  animation: fadeUp 0.35s var(--ease-out) both;
}
.activity-item:hover { border-color: var(--faint); transform: translateY(-1px); }
.activity-left { display: flex; flex-direction: column; gap: 0.06rem; }
.activity-wpm { font-weight: 700; color: var(--accent); font-size: 0.98rem; line-height: 1; }
.activity-mode { font-size: 0.66rem; color: var(--sub); text-transform: uppercase; letter-spacing: 0.06em; }
.activity-right { text-align: right; display: flex; flex-direction: column; gap: 0.06rem; }
.activity-acc { font-size: 0.82rem; color: var(--text); font-weight: 600; }
.activity-date { font-size: 0.68rem; color: var(--sub); }
.activity-empty { font-family: var(--font-mono); font-size: 0.82rem; color: var(--sub); text-align: center; padding: 1.2rem; background: var(--surface-2); border-radius: 0.7rem; border: 1px dashed var(--faint); }

.profile-table td:first-child { font-weight: 700; color: var(--accent); }
.profile-table .empty-row td { text-align: center; color: var(--sub); padding: 1rem; }

.profile-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 2.25rem; padding-top: 1.5rem; border-top: 1px solid var(--faint); }

/* ---------- keyframes ---------- */
@keyframes blink { 50% { opacity: 0; } }
@keyframes blinkCaret { 50% { opacity: 0; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fadeDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes menuIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes pulseGlow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

@media (max-width: 800px) {
  .profile-hero { grid-template-columns: repeat(2, 1fr); }
  .profile-two-col { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .words { font-size: 1.3rem; line-height: 2.7rem; }
  .words-viewport { height: calc(3 * 2.7rem + 0.4rem); }
  .result-top { grid-template-columns: 1fr; }
  .result-chart-wrap { min-height: 160px; order: -1; }
  .profile-card { padding: 1.6rem; }
  .profile-chart-wrap { height: 160px; }
  .appearance-menu { width: 220px; right: -6px; }
  .live-stats { gap: 1.1rem; }
  .live-stat-value { font-size: 1.55rem; }
  .live-stat-value.secondary { font-size: 1rem; }
  .hide-mobile { display: none !important; }
  .habit-insights-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 500px) {
  .live-stats { gap: 0.9rem; }
  .live-stat.secondary:not(:nth-child(-n+5)) { display: none; }
  .habit-insights-grid { grid-template-columns: 1fr; }
}
