:root,
[data-theme="rose-pine"] {
  --base: #191724;
  --surface: #1f1d2e;
  --overlay: #26233a;
  --muted: #6e6a86;
  --subtle: #908caa;
  --text: #e0def4;
  --love: #eb6f92;
  --gold: #f6c177;
  --rose: #ebbcba;
  --pine: #31748f;
  --foam: #9ccfd8;
  --iris: #c4a7e7;
  --accent: #c4a7e7;
  --error: #eb6f92;
}

[data-theme="kanagawa"] {
  --base: #1f1f28;
  --surface: #2a2a37;
  --overlay: #363646;
  --muted: #54546d;
  --subtle: #727169;
  --text: #dcd7ba;
  --love: #c34043;
  --gold: #c0a36e;
  --rose: #d27e99;
  --pine: #6a9589;
  --foam: #7e9cd8;
  --iris: #957fb8;
  --accent: #7e9cd8;
  --error: #c34043;
}

[data-theme="gruvbox"] {
  --base: #282828;
  --surface: #3c3836;
  --overlay: #504945;
  --muted: #665c54;
  --subtle: #a89984;
  --text: #ebdbb2;
  --love: #fb4934;
  --gold: #fabd2f;
  --rose: #d3869b;
  --pine: #8ec07c;
  --foam: #83a598;
  --iris: #b8bb26;
  --accent: #fabd2f;
  --error: #fb4934;
}

[data-theme="catppuccin"] {
  --base: #1e1e2e;
  --surface: #313244;
  --overlay: #45475a;
  --muted: #585b70;
  --subtle: #a6adc8;
  --text: #cdd6f4;
  --love: #f38ba8;
  --gold: #f9e2af;
  --rose: #f5c2e7;
  --pine: #a6e3a1;
  --foam: #89dceb;
  --iris: #cba6f7;
  --accent: #cba6f7;
  --error: #f38ba8;
}

[data-theme="nord"] {
  --base: #2e3440;
  --surface: #3b4252;
  --overlay: #434c5e;
  --muted: #4c566a;
  --subtle: #d8dee9;
  --text: #eceff4;
  --love: #bf616a;
  --gold: #ebcb8b;
  --rose: #d08770;
  --pine: #a3be8c;
  --foam: #88c0d0;
  --iris: #b48ead;
  --accent: #88c0d0;
  --error: #bf616a;
}

[data-theme="dracula"] {
  --base: #282a36;
  --surface: #343746;
  --overlay: #44475a;
  --muted: #6272a4;
  --subtle: #959dcb;
  --text: #f8f8f2;
  --love: #ff5555;
  --gold: #f1fa8c;
  --rose: #ff79c6;
  --pine: #50fa7b;
  --foam: #8be9fd;
  --iris: #bd93f9;
  --accent: #bd93f9;
  --error: #ff5555;
}

[data-theme="tokyo-night"] {
  --base: #1a1b26;
  --surface: #24283b;
  --overlay: #343a52;
  --muted: #565f89;
  --subtle: #9aa5ce;
  --text: #c0caf5;
  --love: #f7768e;
  --gold: #e0af68;
  --rose: #ff9e64;
  --pine: #9ece6a;
  --foam: #7dcfff;
  --iris: #bb9af7;
  --accent: #bb9af7;
  --error: #f7768e;
}

[data-theme="solarized"] {
  --base: #002b36;
  --surface: #073642;
  --overlay: #094552;
  --muted: #586e75;
  --subtle: #93a1a1;
  --text: #eee8d5;
  --love: #dc322f;
  --gold: #b58900;
  --rose: #d33682;
  --pine: #859900;
  --foam: #2aa198;
  --iris: #6c71c4;
  --accent: #2aa198;
  --error: #dc322f;
}

[data-theme="one-dark"] {
  --base: #282c34;
  --surface: #2c323c;
  --overlay: #3e4451;
  --muted: #5c6370;
  --subtle: #848b98;
  --text: #abb2bf;
  --love: #e06c75;
  --gold: #e5c07b;
  --rose: #c678dd;
  --pine: #98c379;
  --foam: #56b6c2;
  --iris: #61afef;
  --accent: #61afef;
  --error: #e06c75;
}

[data-theme="everforest"] {
  --base: #2d353b;
  --surface: #343f44;
  --overlay: #3d484d;
  --muted: #5c6a72;
  --subtle: #9da9a0;
  --text: #d3c6aa;
  --love: #e67e80;
  --gold: #dbbc7f;
  --rose: #d699b6;
  --pine: #a7c080;
  --foam: #7fbbb3;
  --iris: #83c092;
  --accent: #a7c080;
  --error: #e67e80;
}

[data-theme="kanso-ink"] {
  --base: #14171d;
  --surface: #1f1f26;
  --overlay: #22262d;
  --muted: #717c7c;
  --subtle: #a4a7a4;
  --text: #c5c9c7;
  --love: #c34043;
  --gold: #e6c384;
  --rose: #7aa89f;
  --pine: #98bb6c;
  --foam: #7fb4ca;
  --iris: #938aa9;
  --accent: #98bb6c;
  --error: #c34043;
}

[data-theme="kanso-zen"] {
  --base: #090e13;
  --surface: #1c1e25;
  --overlay: #22262d;
  --muted: #717c7c;
  --subtle: #a4a7a4;
  --text: #c5c9c7;
  --love: #c34043;
  --gold: #e6c384;
  --rose: #7aa89f;
  --pine: #98bb6c;
  --foam: #7fb4ca;
  --iris: #938aa9;
  --accent: #7fb4ca;
  --error: #c34043;
}

[data-theme="kanso-pearl"] {
  --base: #f2f1ef;
  --surface: #e2e1df;
  --overlay: #dddddb;
  --muted: #6d6d69;
  --subtle: #5c6068;
  --text: #22262d;
  --love: #c84053;
  --gold: #de9800;
  --rose: #597b75;
  --pine: #6f894e;
  --foam: #4d699b;
  --iris: #624c83;
  --accent: #6f894e;
  --error: #c84053;
}

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

body {
  font-family: 'IBM Plex Mono', 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;
  font-weight: 500;
  background: var(--base);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.container { max-width: 1200px; width: 100%; }

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.logo {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  font-family: inherit;
  letter-spacing: 0.05em;
}

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

nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  transition: color 0.15s ease, border-color 0.15s ease;
  border: 1px solid transparent;
  cursor: pointer;
}

nav a:hover { color: var(--text); }

nav a.active {
  color: var(--text);
  border-color: var(--subtle);
}

nav .kofi-btn {
  color: var(--subtle);
  border: 1px solid var(--subtle);
}

nav .kofi-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.stats-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 3rem;
}

.stats { display: flex; gap: 2rem; }

.stat { text-align: center; }

.stat-value {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.word-display {
  position: relative;
  font-size: 1.5rem;
  font-weight: 200;
  line-height: 2;
  margin-bottom: 2rem;
  user-select: none;
  min-height: 150px;
  outline: none;
  cursor: text;
  transition: filter 0.15s ease;
}

.word-display.unfocused .words-inner { filter: blur(3px); }
.word-display.unfocused .caret { opacity: 0; }

.focus-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.9rem;
  color: var(--subtle);
  letter-spacing: 0.05em;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  white-space: nowrap;
}

.word-display.unfocused .focus-hint { opacity: 1; }

.words-inner { position: relative; }

.word {
  display: inline-block;
  margin-bottom: 0.25rem;
  margin-right: 0.5rem;
}

.char { color: var(--muted); }
.char.correct { color: var(--text); }
.char.incorrect { color: var(--error); }
.char.missed { color: var(--error); opacity: 0.55; }
.char.extra { color: var(--error); opacity: 0.7; }

.caret {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  background: var(--accent);
  pointer-events: none;
  opacity: 1;
  transition: left 0.1s cubic-bezier(0.4, 0, 0.2, 1),
              top 0.1s cubic-bezier(0.4, 0, 0.2, 1),
              height 0.1s ease;
  will-change: left, top;
  animation: blink 1.1s ease-in-out infinite;
}

.caret.typing { animation: none; opacity: 1; }

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.15; }
}

.hidden-input {
  position: absolute;
  left: -9999px;
  top: -9999px;
  opacity: 0;
  pointer-events: none;
}

.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-top: 2rem;
}

button {
  background: transparent;
  border: 1px solid var(--subtle);
  padding: 0.625rem 1.25rem;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--subtle);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

button:hover {
  color: var(--text);
  border-color: var(--text);
}

button.active {
  color: var(--accent);
  border-color: var(--accent);
}

.control-divider {
  width: 1px;
  height: 24px;
  background: var(--muted);
  margin: 0 0.5rem;
}

.settings-wrapper { position: relative; }

.settings-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: var(--base);
  border: 1px solid var(--subtle);
  padding: 0.75rem;
  display: none;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 220px;
  z-index: 100;
}

.settings-menu.visible { display: flex; }

.settings-section { display: flex; flex-direction: column; gap: 0.5rem; }

.settings-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.theme-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
}

.theme-option {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border: 1px solid transparent;
  background: transparent;
  font-size: 0.8rem;
  color: var(--subtle);
}

.theme-option:hover { color: var(--text); }

.theme-option.active {
  color: var(--accent);
  border-color: var(--accent);
}

.custom-editor {
  display: none;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--muted);
}

.custom-editor.visible { display: flex; }

.custom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--subtle);
}

.hex-input {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--subtle);
  padding: 0.15rem 0.35rem;
  transition: border-color 0.15s ease;
}

.hex-input:focus-within {
  border-color: var(--accent);
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1px solid var(--subtle);
}

.hex-text {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.75rem;
  width: 6.5ch;
  padding: 0;
  letter-spacing: 0.02em;
}

.hex-text::selection {
  background: var(--accent);
  color: var(--base);
}

.custom-actions { display: flex; gap: 0.5rem; }

.custom-actions button {
  flex: 1;
  font-size: 0.75rem;
  padding: 0.4rem;
}

.timer {
  font-size: 3rem;
  font-weight: 300;
  color: var(--accent);
  text-align: center;
  margin-bottom: 2rem;
  font-variant-numeric: tabular-nums;
}

.results {
  display: none;
  text-align: center;
  padding: 2rem;
  border: 1px solid var(--subtle);
  margin-top: 2rem;
}

.results.visible { display: block; }

.results h2 {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 1.5rem;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}

.result-item { padding: 1rem; }

.result-value {
  font-size: 2rem;
  font-weight: 600;
  color: var(--accent);
}

.result-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 0.25rem;
}

footer {
  margin-top: 3rem;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

footer kbd {
  border: 1px solid var(--muted);
  padding: 0.15rem 0.4rem;
  margin: 0 0.25rem;
  font-family: inherit;
}

footer .wordmark {
  margin-top: 0.75rem;
  font-size: 0.7rem;
  letter-spacing: 0.35em;
  color: var(--subtle);
  opacity: 0.5;
}

/* ===== switch test ===== */

.stats-bar {
  display: flex;
  justify-content: center;
  gap: 3rem;
  margin-bottom: 2rem;
  padding: 1.25rem;
  border: 1px solid var(--subtle);
}

.last-key-display { text-align: center; margin-bottom: 2rem; }

.last-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 120px;
  min-height: 120px;
  padding: 1.5rem;
  background: transparent;
  border: 1px solid var(--subtle);
  font-size: 2rem;
  font-weight: 600;
  color: var(--text);
  transition: color 0.1s ease, border-color 0.1s ease, transform 0.1s ease;
}

.last-key.pressed {
  color: var(--accent);
  border-color: var(--accent);
  transform: scale(0.98);
}

.last-key-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.keyboard-wrapper {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin-bottom: 2rem;
}

.keyboard-main { display: flex; flex-direction: column; }
.keyboard { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.keyboard-nav { display: flex; flex-direction: column; gap: 20px; }
.nav-cluster, .arrow-cluster { display: flex; flex-direction: column; gap: 6px; }
.keyboard-numpad { display: flex; flex-direction: column; gap: 6px; }

.row { display: flex; gap: 6px; }
.row-spacer { height: 12px; }
.key-spacer { width: 24px; }
.key-spacer-half { width: 12px; }
.key-placeholder { width: 42px; height: 42px; }
.key-placeholder.triple { width: calc(42px * 3 + 12px); }

.key {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 42px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid var(--subtle);
  font-size: 0.7rem;
  color: var(--subtle);
  transition: color 0.08s ease, border-color 0.08s ease, transform 0.08s ease;
  user-select: none;
}

.key.small { min-width: 42px; padding: 0 6px; font-size: 0.65rem; }

.key.pressed {
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(2px);
}

.key.was-pressed {
  color: var(--accent);
  border-color: var(--accent);
}

.key.space { min-width: 252px; }
.key.backspace { min-width: 84px; }
.key.tab { min-width: 63px; }
.key.caps { min-width: 78px; }
.key.enter { min-width: 93px; }
.key.shift-l { min-width: 102px; }
.key.shift-r { min-width: 117px; }
.key.ctrl { min-width: 54px; }
.key.alt { min-width: 48px; }
.key.meta { min-width: 48px; }
.key.menu { min-width: 48px; }

.key.numpad-plus {
  height: calc(42px * 2 + 6px);
  position: absolute;
  right: 0;
  top: 0;
}

.key.numpad-enter {
  height: calc(42px * 2 + 6px);
  position: absolute;
  right: 0;
  top: 0;
}

.key.numpad-zero { min-width: calc(42px * 2 + 6px); }

.keyboard-numpad .row { position: relative; }

.heatmap .key.heat-1 { border-color: var(--error); opacity: 0.35; }
.heatmap .key.heat-2 { border-color: var(--error); opacity: 0.55; }
.heatmap .key.heat-3 { border-color: var(--error); opacity: 0.75; }
.heatmap .key.heat-4 { border-color: var(--error); color: var(--error); opacity: 0.9; }
.heatmap .key.heat-5 { border-color: var(--error); color: var(--error); opacity: 1; }

.toggle-btn.active {
  color: var(--accent);
  border-color: var(--accent);
}

.history {
  margin-top: 2rem;
  padding: 1.25rem;
  border: 1px solid var(--subtle);
}

.history-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.75rem;
}

.history-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 36px;
}

.history-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--muted);
  font-size: 0.75rem;
  color: var(--text);
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

@media (max-width: 1200px) {
  .keyboard-wrapper { transform: scale(0.85); transform-origin: top center; }
}
@media (max-width: 1000px) {
  .keyboard-wrapper { transform: scale(0.7); transform-origin: top center; }
  .keyboard-numpad { display: none; }
}
@media (max-width: 800px) {
  .keyboard-wrapper { transform: scale(0.55); transform-origin: top center; }
  .keyboard-nav { display: none; }
}
@media (max-width: 600px) {
  .keyboard-wrapper { display: none; }
  .stats-bar { flex-wrap: wrap; gap: 1.5rem; }
}
