/* ============================================================
   APEXTYPE — style.css  v2
   ============================================================ */

:root {
  --bg:           #09090b;
  --surface:      #0f0f12;
  --surface2:     #131318;
  --surface3:     #18181f;
  --border:       rgba(255,255,255,0.065);
  --border-hi:    rgba(255,128,0,0.3);

  --accent:       #FF8000;
  --accent2:      #ffaa44;
  --accent-glow:  rgba(255,128,0,0.4);
  --accent-faint: rgba(255,128,0,0.08);
  --accent-dim:   rgba(255,128,0,0.25);

  --text:         #dddde8;
  --text-dim:     #52526a;
  --text-muted:   #46465e;

  --correct:      #e8e8f0;
  --incorrect:    #e05555;
  --incorrect-bg: rgba(224,85,85,0.12);
  --extra:        #aa3333;

  --font-mono:    'Roboto Mono', monospace;
  --font-ui:      'Rajdhani', sans-serif;
  --font-display: 'Orbitron', sans-serif;

  --ease:  cubic-bezier(0.4,0,0.2,1);
  --ease-spring: cubic-bezier(0.34,1.56,0.64,1);
  --r:     10px;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font-family: var(--font-ui); cursor: pointer; border: none; outline: none; background: none; }

/* ===== BACKGROUND ===== */
#bg-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 0; }

/* ===== APP ===== */
.app {
  position: relative; z-index: 1;
  max-width: 1040px; margin: 0 auto;
  padding: 0 28px 80px;
  min-height: 100vh;
  display: flex; flex-direction: column;
}

/* ===== HEADER ===== */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 30px 0 26px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px; gap: 20px;
  position: relative;
}
.header::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-dim), transparent);
}

.logo { display: flex; flex-direction: column; }
.logo-wordmark { display: flex; align-items: baseline; gap: 0; line-height: 1; }
.logo-a {
  font-family: var(--font-display); font-size: 21px; font-weight: 900;
  letter-spacing: 3px; color: var(--accent);
  text-shadow: 0 0 24px var(--accent-glow), 0 0 48px rgba(255,128,0,0.15);
}
.logo-t {
  font-family: var(--font-display); font-size: 21px; font-weight: 900;
  letter-spacing: 3px; color: var(--text);
}
.logo-sub {
  font-size: 9px; letter-spacing: 2.5px; color: var(--text-dim);
  text-transform: uppercase; margin-top: 5px; font-weight: 500;
}

/* Mode nav */
.mode-nav {
  position: relative; display: flex;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 100px; padding: 4px; gap: 2px;
}
.mode-btn {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 7px;
  padding: 8px 22px; border-radius: 100px;
  font-size: 13px; font-weight: 600; letter-spacing: 0.8px;
  color: var(--text-dim);
  transition: color 0.25s var(--ease);
  white-space: nowrap;
}
.mode-btn:hover:not(.active) { color: var(--text); }
.mode-btn.active { color: #000; font-weight: 700; }
.mode-slider {
  position: absolute; z-index: 0;
  top: 4px; bottom: 4px;
  border-radius: 100px;
  background: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
  transition: left 0.28s var(--ease), width 0.28s var(--ease);
}

/* Scores */
.header-scores { display: flex; gap: 20px; }
.score-chip { text-align: right; }
.score-label {
  font-size: 9px; letter-spacing: 2px; color: var(--text-dim);
  text-transform: uppercase; margin-bottom: 3px;
}
.score-val {
  font-family: var(--font-display); font-size: 19px; font-weight: 700;
  color: var(--accent); text-shadow: 0 0 14px var(--accent-glow); line-height: 1;
}

/* ===== PANELS ===== */
.panel { display: none; flex: 1; }
.panel.active { display: block; animation: panel-in 0.35s var(--ease); }
@keyframes panel-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== SETTINGS BAR ===== */
.settings-bar {
  display: flex; align-items: center; justify-content: center;
  gap: 4px; margin-bottom: 28px; flex-wrap: wrap;
}
.opt-group { display: flex; gap: 2px; }
.opt-group.hidden { display: none; }
.bar-div { width: 1px; height: 16px; background: var(--border); margin: 0 8px; }
.opt-btn {
  padding: 5px 15px; border-radius: 100px;
  font-size: 13px; font-weight: 500; letter-spacing: 0.3px;
  color: var(--text-dim);
  transition: all 0.18s var(--ease);
}
.opt-btn:hover:not(.active) { color: var(--text); background: rgba(255,255,255,0.05); }
.opt-btn.active { color: var(--accent); background: var(--accent-faint); font-weight: 600; }

/* ===== LIVE BAR ===== */
.live-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px; margin-bottom: 16px; min-height: 68px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.4s ease;
}
.live-bar.visible { opacity: 1; pointer-events: all; }
.lstat { display: flex; flex-direction: column; align-items: flex-start; min-width: 60px; }
.lstat.right-stat { align-items: flex-end; }
.lstat-val {
  font-family: var(--font-display); font-size: 30px; font-weight: 700;
  color: var(--accent); line-height: 1; text-shadow: 0 0 20px var(--accent-glow);
}
.lstat-key { font-size: 10px; letter-spacing: 2px; color: var(--text-dim); text-transform: uppercase; margin-top: 3px; }
.center-stat { align-items: center; flex: 1; }
.lstat-timer {
  font-family: var(--font-display); font-size: 56px; font-weight: 900;
  color: var(--text); line-height: 1; text-align: center;
  letter-spacing: -2px;
  transition: color 0.3s ease, text-shadow 0.3s ease;
}
.lstat-timer.urgent {
  color: var(--incorrect);
  text-shadow: 0 0 28px rgba(224,85,85,0.6);
  animation: timer-pulse 0.55s ease infinite alternate;
}
@keyframes timer-pulse {
  from { transform: scale(1); }
  to   { transform: scale(1.05); }
}

/* ===== WORDS AREA ===== */
.words-wrap {
  position: relative; border-radius: 14px;
  overflow: hidden; margin-bottom: 16px; cursor: text;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.03);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.words-wrap.focused {
  border-color: rgba(255,128,0,0.12);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 0 30px rgba(255,128,0,0.04), inset 0 1px 0 rgba(255,255,255,0.03);
}

/* Time progress bar */
.time-bar-track {
  position: absolute; top: 0; left: 0; right: 0; height: 2px; z-index: 6;
  background: rgba(255,255,255,0.04);
}
.time-bar-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  box-shadow: 0 0 8px var(--accent-glow);
  transform-origin: left;
  transition: transform 0.9s linear, background 0.5s ease;
}
.time-bar-fill.urgent {
  background: linear-gradient(90deg, #e05555, #cc2222);
  box-shadow: 0 0 8px rgba(224,85,85,0.6);
}

/* Fade masks */
.words-wrap::before, .words-wrap::after {
  content: ''; position: absolute; left: 0; right: 0; height: 28px;
  z-index: 4; pointer-events: none;
}
.words-wrap::before { top: 2px; background: linear-gradient(to bottom, var(--surface) 20%, transparent); }
.words-wrap::after  { bottom: 0; background: linear-gradient(to top, var(--surface), transparent); }

.words-viewport {
  height: 160px; overflow: hidden;
  padding: 20px 28px; position: relative;
}
.words {
  display: flex; flex-wrap: wrap; gap: 8px 14px;
  will-change: transform;
  transition: transform 0.15s var(--ease);
}

/* Word / char */
.word { display: inline-flex; position: relative; padding-bottom: 2px; }
.word.wrong-word::after {
  content: ''; position: absolute; bottom: -1px; left: 0; right: 0;
  height: 2px; background: var(--incorrect); border-radius: 2px; opacity: 0.7;
}
.char {
  font-family: var(--font-mono); font-size: 20px; font-weight: 400;
  color: var(--text-muted); transition: color 0.06s ease;
  line-height: 1.75; position: relative;
}
.char.correct  { color: var(--correct); }
.char.incorrect { color: var(--incorrect); background: var(--incorrect-bg); border-radius: 2px; }
.char.extra    { color: var(--extra); opacity: 0.7; }

/* ===== CARET ===== */
.caret {
  position: absolute; width: 2px;
  background: var(--accent); border-radius: 3px;
  box-shadow: 0 0 8px var(--accent), 0 0 20px var(--accent-glow);
  pointer-events: none; z-index: 5;
  transition: left 80ms var(--ease), top 80ms var(--ease);
}
@keyframes caret-blink {
  0%, 40% { opacity: 1; }
  60%, 100% { opacity: 0; }
}
.caret.blinking { animation: caret-blink 1.1s ease infinite; }

/* Focus veil */
.focus-veil {
  position: absolute; inset: 0;
  background: rgba(9,9,11,0.8); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 6; border-radius: 14px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.22s ease;
}
.words-wrap:not(.focused) .focus-veil { opacity: 1; pointer-events: all; }
.focus-hint {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; letter-spacing: 1px; color: var(--text-dim);
}

#typing-input { position: absolute; top: -9999px; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* Test footer */
.test-footer {
  display: flex; align-items: center; justify-content: center;
  gap: 14px; margin-top: 4px;
}
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border); color: var(--text-dim);
  transition: all 0.2s var(--ease);
}
.icon-btn:hover {
  color: var(--accent); border-color: var(--border-hi);
  box-shadow: 0 0 16px var(--accent-glow);
  transform: rotate(-30deg);
}
.kbd-hint { font-size: 11px; letter-spacing: 1px; color: var(--text-muted); }

/* ===== CPS LAYOUT ===== */
.cps-layout {
  display: flex; flex-direction: column;
  align-items: center; gap: 36px; padding: 8px 0;
}
.cps-counters {
  display: flex; gap: 52px; justify-content: center; align-items: center;
}
.cps-tile { text-align: center; }
.cps-num {
  font-family: var(--font-display); font-size: 50px; font-weight: 700;
  color: var(--text); line-height: 1; letter-spacing: -1px;
  transition: color 0.1s ease;
}
.accent-tile .cps-num { color: var(--accent); text-shadow: 0 0 24px var(--accent-glow); }
.cps-num.flash { animation: num-flash 0.14s ease; }
@keyframes num-flash {
  0%  { transform: scale(1); }
  50% { transform: scale(1.1); color: var(--accent2); text-shadow: 0 0 20px var(--accent-glow); }
  100%{ transform: scale(1); }
}
.cps-lbl { font-size: 10px; letter-spacing: 3px; color: var(--text-dim); text-transform: uppercase; margin-top: 6px; font-weight: 600; }

/* ===== CPS RING ===== */
.cps-ring-wrap {
  position: relative; width: 320px; height: 320px;
  display: flex; align-items: center; justify-content: center;
}
#cps-ring {
  position: absolute; inset: 0;
  pointer-events: none;
}
.click-btn {
  position: relative; z-index: 1;
  width: 200px; height: 200px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; user-select: none;
  border: 1.5px solid rgba(255,128,0,0.25);
  background: radial-gradient(circle at 35% 30%,
    rgba(255,128,0,0.1) 0%,
    rgba(255,128,0,0.02) 60%,
    transparent 100%);
  transition: transform 0.08s var(--ease), box-shadow 0.08s ease, border-color 0.08s ease;
  overflow: hidden;
}
.click-btn:hover {
  border-color: rgba(255,128,0,0.5);
  box-shadow: 0 0 40px rgba(255,128,0,0.2), inset 0 0 30px rgba(255,128,0,0.04);
}
.click-btn:active, .click-btn.clicked {
  transform: scale(0.93);
  border-color: var(--accent);
  box-shadow: 0 0 60px rgba(255,128,0,0.35), 0 0 120px rgba(255,128,0,0.15), inset 0 0 40px rgba(255,128,0,0.06);
}
.click-inner {
  display: flex; flex-direction: column;
  align-items: center; gap: 5px; z-index: 1;
}
.click-label {
  font-family: var(--font-display); font-size: 24px; font-weight: 900;
  letter-spacing: 5px; color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
}
.click-sub {
  font-size: 10px; letter-spacing: 1px; color: var(--text-dim);
  text-align: center; max-width: 130px; line-height: 1.5;
}

/* Ripple inside button */
.ripple {
  position: absolute; border-radius: 50%;
  background: rgba(255,128,0,0.22);
  transform: scale(0);
  animation: ripple-out 0.55s ease-out forwards;
  pointer-events: none;
}
@keyframes ripple-out { to { transform: scale(4); opacity: 0; } }

/* Floating particles from clicks */
.click-particle {
  position: fixed; border-radius: 50%;
  pointer-events: none; z-index: 1000;
  animation: particle-fly 0.55s ease-out forwards;
}
@keyframes particle-fly {
  to { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

/* ===== RESULTS SCREEN ===== */
.results-screen {
  position: fixed; inset: 0;
  background: rgba(9,9,11,0.88);
  backdrop-filter: blur(28px) saturate(0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; opacity: 0; pointer-events: none;
  transition: opacity 0.35s ease;
}
.results-screen.show { opacity: 1; pointer-events: all; }

.results-card {
  background: var(--surface2);
  border: 1px solid rgba(255,255,255,0.075);
  border-radius: 22px; padding: 44px 52px;
  min-width: 560px; max-width: 680px; width: 100%;
  position: relative; overflow: hidden;
  transform: translateY(20px) scale(0.98);
  transition: transform 0.38s var(--ease-spring);
}
.results-screen.show .results-card { transform: translateY(0) scale(1); }

/* Top racing stripe */
.results-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 25%, var(--accent2) 50%, var(--accent) 75%, transparent 100%);
  box-shadow: 0 0 16px var(--accent-glow);
}
/* Corner glow */
.results-card::after {
  content: ''; position: absolute; bottom: -100px; right: -100px;
  width: 250px; height: 250px;
  background: radial-gradient(circle, rgba(255,128,0,0.05) 0%, transparent 70%);
  pointer-events: none;
}

.res-badge {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; margin-bottom: 24px;
  font-family: var(--font-display); font-size: 10px;
  letter-spacing: 5px; color: var(--accent); text-transform: uppercase;
}
.res-badge-line {
  flex: 1; height: 1px; max-width: 60px;
  background: linear-gradient(90deg, transparent, var(--accent-dim));
}
.res-badge-line:last-child {
  background: linear-gradient(270deg, transparent, var(--accent-dim));
}

.res-hero {
  display: flex; align-items: baseline; justify-content: center;
  gap: 10px; margin-bottom: 28px;
}
.res-big {
  font-family: var(--font-display); font-size: 100px; font-weight: 900;
  color: var(--accent); line-height: 1; letter-spacing: -3px;
  text-shadow: 0 0 48px var(--accent-glow), 0 0 100px rgba(255,128,0,0.12);
}
.res-unit {
  font-family: var(--font-ui); font-size: 20px;
  color: var(--text-dim); font-weight: 300; letter-spacing: 3px; text-transform: uppercase;
}

/* WPM Chart */
.chart-wrap {
  position: relative; margin-bottom: 24px;
  background: rgba(255,255,255,0.015);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 16px 12px;
  overflow: hidden;
}
.chart-wrap::before {
  content: ''; position: absolute; inset: 0; border-radius: 10px;
  background: linear-gradient(135deg, rgba(255,128,0,0.02) 0%, transparent 60%);
  pointer-events: none;
}
#wpm-chart { width: 100%; height: 130px; display: block; }
.chart-legend {
  display: flex; gap: 16px; margin-top: 6px;
  justify-content: flex-end;
}
.legend-item {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; letter-spacing: 1px; color: var(--text-dim);
  font-family: var(--font-mono);
}
.legend-item .legend-dot {
  width: 8px; height: 2px; border-radius: 2px; background: var(--text-dim);
}
.legend-item.orange .legend-dot { background: var(--accent); }

/* CPS Meter */
.cps-meter-wrap {
  margin-bottom: 24px;
  display: flex; align-items: center; gap: 16px;
}
.cps-meter-track {
  flex: 1; position: relative;
  background: rgba(255,255,255,0.04);
  border-radius: 100px; height: 12px;
  overflow: visible;
}
.cps-meter-fill {
  height: 100%; border-radius: 100px; width: 0%;
  background: linear-gradient(90deg, #FF8000, #ffcc44);
  box-shadow: 0 0 12px var(--accent-glow);
  transition: width 1s var(--ease-spring);
  position: relative;
}
.cps-meter-fill::after {
  content: ''; position: absolute;
  right: -1px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent2);
  box-shadow: 0 0 12px var(--accent-glow), 0 0 4px rgba(255,255,255,0.3);
}
.cps-meter-labels {
  position: absolute; top: 18px; left: 0; right: 0;
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--text-muted); font-family: var(--font-mono);
}
.cps-rank-badge {
  font-family: var(--font-display); font-size: 14px; font-weight: 700;
  color: var(--accent); letter-spacing: 2px;
  white-space: nowrap; padding-bottom: 2px;
}

/* Stats grid */
.res-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 16px; padding: 24px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border); margin-bottom: 24px;
}
.res-grid.three-col { grid-template-columns: repeat(3, 1fr); }
.res-cell { text-align: center; }
.res-val {
  font-family: var(--font-display); font-size: 20px; font-weight: 700;
  color: var(--text); line-height: 1; margin-bottom: 5px;
}
.res-key { font-size: 10px; letter-spacing: 1.5px; color: var(--text-dim); text-transform: uppercase; }

/* New best */
.new-best {
  text-align: center; margin-bottom: 20px;
  font-family: var(--font-display); font-size: 11px;
  letter-spacing: 3px; color: var(--accent);
  animation: best-glow 1.8s ease infinite alternate;
}
.new-best.hidden { display: none; }
@keyframes best-glow {
  from { opacity: 0.6; text-shadow: 0 0 8px rgba(255,128,0,0.3); }
  to   { opacity: 1;   text-shadow: 0 0 20px var(--accent-glow), 0 0 40px rgba(255,128,0,0.2); }
}

.res-btns { display: flex; gap: 10px; justify-content: center; margin-bottom: 16px; }
.res-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 32px; border-radius: 100px;
  font-size: 14px; font-weight: 600; letter-spacing: 0.8px;
  transition: all 0.2s var(--ease); border: 1px solid transparent;
}
.res-btn.primary { background: var(--accent); color: #000; font-weight: 700; }
.res-btn.primary:hover {
  background: var(--accent2);
  box-shadow: 0 0 28px var(--accent-glow), 0 4px 14px rgba(0,0,0,0.3);
  transform: translateY(-2px);
}
.res-btn:not(.primary) { background: transparent; color: var(--text); border-color: var(--border); }
.res-btn:not(.primary):hover { border-color: var(--text-dim); background: rgba(255,255,255,0.04); }

.res-hint { text-align: center; font-size: 11px; letter-spacing: 1px; color: var(--text-muted); }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 720px) {
  .app { padding: 0 16px 40px; }
  .header { flex-wrap: wrap; gap: 12px; margin-bottom: 24px; }
  .header-scores { display: none; }
  .cps-counters { gap: 24px; }
  .cps-num { font-size: 36px; }
  .cps-ring-wrap { width: 280px; height: 280px; }
  #cps-ring { width: 280px; height: 280px; }
  .click-btn { width: 175px; height: 175px; }
  .results-card { min-width: auto; padding: 32px 20px; margin: 14px; }
  .res-big { font-size: 72px; }
  .res-grid { grid-template-columns: repeat(2, 1fr); }
  .res-grid.three-col { grid-template-columns: repeat(3, 1fr); }
  .char { font-size: 17px; }
}
@media (max-width: 480px) {
  .logo-a, .logo-t { font-size: 17px; }
  .res-big { font-size: 60px; }
}
