/* ==========================================================================
   TypeApex Pro — Design System & Core Stylesheet
   Luxury Executive Dark/Light Themes, Glassmorphic UI & 60+ FPS Caret
   ========================================================================== */

:root {
  /* Obsidian Cyber Theme (Default) */
  --bg-primary: #0a0d14;
  --bg-secondary: #101522;
  --bg-tertiary: #171e2e;
  --bg-surface: rgba(23, 30, 46, 0.7);
  --bg-glass: rgba(16, 21, 34, 0.85);
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-active: rgba(99, 102, 241, 0.5);
  --border-glow: rgba(99, 102, 241, 0.25);
  
  --text-main: #f8fafc;
  --text-muted: #64748b;
  --text-dim: #475569;
  
  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.4);
  
  --accent-cyan: #06b6d4;
  --accent-amber: #f59e0b;
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;
  --accent-purple: #a855f7;
  
  --char-default: #64748b;
  --char-correct: #f8fafc;
  --char-incorrect: #f43f5e;
  --char-extra: #fb7185;
  --char-cursor: #6366f1;
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Roboto Mono', Consolas, monospace;
  --font-display: 'Plus Jakarta Sans', var(--font-sans);
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  
  --shadow-subtle: 0 4px 20px rgba(0, 0, 0, 0.25);
  --shadow-elevated: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.2);
}

/* Theme: Carbon Gold */
[data-theme="carbon-gold"] {
  --bg-primary: #0d0e11;
  --bg-secondary: #14171d;
  --bg-tertiary: #1d212a;
  --bg-surface: rgba(29, 33, 42, 0.7);
  --border-subtle: rgba(245, 158, 11, 0.12);
  --border-active: rgba(245, 158, 11, 0.6);
  --accent-primary: #f59e0b;
  --accent-primary-hover: #d97706;
  --accent-glow: rgba(245, 158, 11, 0.4);
  --char-cursor: #f59e0b;
}

/* Theme: Matrix Emerald */
[data-theme="matrix-emerald"] {
  --bg-primary: #050d0a;
  --bg-secondary: #0a1813;
  --bg-tertiary: #112820;
  --bg-surface: rgba(17, 40, 32, 0.7);
  --border-subtle: rgba(16, 185, 129, 0.15);
  --border-active: rgba(16, 185, 129, 0.6);
  --accent-primary: #10b981;
  --accent-primary-hover: #059669;
  --accent-glow: rgba(16, 185, 129, 0.4);
  --char-cursor: #10b981;
}

/* Theme: Midnight Ocean */
[data-theme="midnight-ocean"] {
  --bg-primary: #070e1b;
  --bg-secondary: #0c1930;
  --bg-tertiary: #142747;
  --bg-surface: rgba(20, 39, 71, 0.7);
  --border-subtle: rgba(6, 182, 212, 0.15);
  --border-active: rgba(6, 182, 212, 0.6);
  --accent-primary: #06b6d4;
  --accent-primary-hover: #0891b2;
  --accent-glow: rgba(6, 182, 212, 0.4);
  --char-cursor: #06b6d4;
}

/* Theme: Executive Light */
[data-theme="executive-light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-surface: rgba(255, 255, 255, 0.9);
  --bg-glass: rgba(255, 255, 255, 0.95);
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-active: rgba(79, 70, 229, 0.4);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --accent-primary: #4f46e5;
  --accent-primary-hover: #4338ca;
  --accent-glow: rgba(79, 70, 229, 0.2);
  --char-default: #94a3b8;
  --char-correct: #0f172a;
  --char-incorrect: #e11d48;
  --char-cursor: #4f46e5;
  --shadow-subtle: 0 4px 20px rgba(0, 0, 0, 0.06);
  --shadow-elevated: 0 10px 40px -10px rgba(0, 0, 0, 0.1);
}

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

html, body {
  min-height: 100vh;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.ambient-mesh {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  background: 
    radial-gradient(circle at 15% 15%, var(--accent-glow) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(6, 182, 212, 0.1) 0%, transparent 45%);
  opacity: 0.6;
}

.app-wrapper {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 1.5rem;
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-primary), #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: var(--shadow-glow);
  color: #fff;
  flex-shrink: 0;
}

.brand-titles {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(to right, var(--text-main), var(--accent-primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tagline {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  font-weight: 600;
}

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

.header-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 0.55rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.header-btn:hover, .header-btn.active {
  background: var(--bg-tertiary);
  color: var(--text-main);
  border-color: var(--border-active);
}

.header-btn .kbd-pill {
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.7rem;
  font-family: var(--font-mono);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  color: var(--text-muted);
}

.modes-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.4rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-subtle);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.mode-pills-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.mode-pill {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 600;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
}

.mode-pill:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.mode-pill.active {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.mode-pill .badge-pro {
  background: rgba(245, 158, 11, 0.2);
  color: #f59e0b;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  text-transform: uppercase;
}

.mode-pill.active .badge-pro {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.mode-pill .badge-fun {
  background: rgba(244, 63, 94, 0.2);
  color: #f43f5e;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  text-transform: uppercase;
}

.mode-pill.active .badge-fun {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.sub-config-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding: 0.25rem 0.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.config-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
}

.config-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
  margin-right: 0.25rem;
}

.sub-pill {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sub-pill:hover {
  color: var(--text-main);
}

.sub-pill.active {
  background: var(--bg-tertiary);
  color: var(--accent-primary);
  font-weight: 700;
}

.config-toggle {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  transition: all 0.15s ease;
}

.config-toggle.active {
  border-color: var(--border-active);
  color: var(--text-main);
  background: var(--bg-tertiary);
}

.live-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding: 0.85rem 1.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  backdrop-filter: blur(12px);
}

.hud-stat-item {
  display: flex;
  flex-direction: column;
}

.hud-stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
}

.hud-stat-value {
  font-family: var(--font-mono);
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
}

.hud-stat-unit {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.hud-timer-progress {
  flex-grow: 1;
  margin: 0 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.progress-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-cyan));
  border-radius: 999px;
  transition: width 0.1s linear;
}

.hud-combo-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  color: #f59e0b;
  font-weight: 700;
  font-size: 0.88rem;
  opacity: 0;
  transform: scale(0.9);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.hud-combo-badge.visible {
  opacity: 1;
  transform: scale(1);
}

.typing-viewport-card {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2.25rem 2.5rem;
  min-height: 220px;
  box-shadow: var(--shadow-elevated);
  backdrop-filter: blur(16px);
  outline: none;
  cursor: text;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
}

.typing-viewport-card:focus-within, .typing-viewport-card.focused {
  border-color: var(--border-active);
  box-shadow: var(--shadow-glow);
}

.words-wrapper {
  position: relative;
  font-family: var(--font-mono);
  font-size: 1.55rem;
  line-height: 2.2;
  height: 140px;
  overflow: hidden;
  letter-spacing: 0.01em;
}

.dynamic-caret {
  position: absolute;
  top: 0;
  left: 0;
  width: 2.5px;
  height: 1.8rem;
  background-color: var(--char-cursor);
  border-radius: 2px;
  box-shadow: 0 0 10px var(--char-cursor);
  transition: left 0.08s ease-out, top 0.12s ease-out;
  pointer-events: none;
  z-index: 10;
  animation: caretBlink 1s infinite alternate;
}

@keyframes caretBlink {
  0% { opacity: 1; }
  45% { opacity: 1; }
  55% { opacity: 0.3; }
  100% { opacity: 0.3; }
}

.typing-viewport-card.is-typing .dynamic-caret {
  animation: none;
  opacity: 1;
}

.word {
  display: inline-block;
  margin-right: 0.85rem;
  white-space: nowrap;
  transition: color 0.1s ease;
}

.word.error-word {
  text-decoration: underline wavy var(--char-incorrect);
}

.letter {
  color: var(--char-default);
  transition: color 0.08s ease;
  position: relative;
}

.letter.correct {
  color: var(--char-correct);
}

.letter.incorrect {
  color: var(--char-incorrect);
  background: rgba(244, 63, 94, 0.15);
  border-radius: 2px;
}

.letter.extra {
  color: var(--char-extra);
  opacity: 0.85;
}

.focus-blur-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 13, 20, 0.7);
  backdrop-filter: blur(4px);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--text-main);
  font-weight: 600;
  font-size: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 20;
}

.focus-blur-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

#hidden-type-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.typing-actions-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

.btn-restart {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 0.65rem 1.4rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-restart:hover {
  background: var(--bg-tertiary);
  color: var(--text-main);
  border-color: var(--border-active);
  transform: translateY(-1px);
}

.btn-restart kbd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.08);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}

.results-card {
  display: none;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-elevated);
  backdrop-filter: blur(20px);
  animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.results-card.active {
  display: block;
}

@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 1.5rem;
  margin-bottom: 2rem;
}

.results-title-group h2 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 800;
}

.results-tier-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.95rem;
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid var(--accent-primary);
  color: #fff;
}

.results-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.metric-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
}

.metric-box.featured {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(6, 182, 212, 0.08));
  border-color: var(--border-active);
}

.metric-box .m-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
}

.metric-box .m-value {
  font-family: var(--font-mono);
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--text-main);
  margin-top: 0.25rem;
  line-height: 1.1;
}

.metric-box .m-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.chart-container {
  position: relative;
  height: 220px;
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 2rem;
}

.chart-canvas {
  width: 100%;
  height: 100%;
}

.career-benchmark-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.benchmark-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.benchmark-tiers-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.benchmark-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.85rem;
}

.benchmark-name {
  width: 220px;
  color: var(--text-muted);
  font-weight: 500;
}

.benchmark-bar-track {
  flex-grow: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.benchmark-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent-primary);
}

.benchmark-wpm-val {
  width: 65px;
  font-family: var(--font-mono);
  font-weight: 700;
  text-align: right;
}

.results-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), #4f46e5);
  color: #fff;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: all 0.2s ease;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 0.75rem 1.35rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-active);
}

.keyboard-section {
  margin-top: 2.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  backdrop-filter: blur(12px);
}

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

.keyboard-title {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.virtual-keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 960px;
  margin: 0 auto;
  user-select: none;
}

.kb-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.key-cap {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  height: 48px;
  min-width: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  transition: all 0.1s ease;
  position: relative;
}

.key-cap.active-press {
  transform: translateY(2px);
  background: var(--accent-primary);
  color: #fff;
  border-color: #fff;
  box-shadow: 0 0 14px var(--accent-glow);
}

.key-cap.wide-15 { min-width: 65px; }
.key-cap.wide-175 { min-width: 75px; }
.key-cap.wide-2 { min-width: 86px; }
.key-cap.wide-225 { min-width: 98px; }
.key-cap.space-key { min-width: 280px; }

.finger-l-pinky { border-bottom: 3px solid #ec4899; }
.finger-l-ring { border-bottom: 3px solid #a855f7; }
.finger-l-middle { border-bottom: 3px solid #3b82f6; }
.finger-l-index { border-bottom: 3px solid #06b6d4; }
.finger-thumb { border-bottom: 3px solid #10b981; }
.finger-r-index { border-bottom: 3px solid #06b6d4; }
.finger-r-middle { border-bottom: 3px solid #3b82f6; }
.finger-r-ring { border-bottom: 3px solid #a855f7; }
.finger-r-pinky { border-bottom: 3px solid #ec4899; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 12, 0.8);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  padding: 2rem;
  transform: scale(0.95);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 1rem;
}

.modal-title {
  font-size: 1.3rem;
  font-weight: 700;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
}

.modal-close:hover {
  color: var(--text-main);
}

.certificate-preview-box {
  background: #ffffff;
  color: #0f172a;
  border-radius: 12px;
  padding: 2.5rem;
  position: relative;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  border: 8px double #cbd5e1;
  font-family: 'Times New Roman', serif;
  text-align: center;
}

.cert-header {
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #64748b;
  margin-bottom: 0.5rem;
  font-family: var(--font-sans);
  font-weight: 700;
}

.cert-main-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #0f172a;
  margin-bottom: 0.75rem;
}

.cert-candidate {
  font-size: 1.85rem;
  font-style: italic;
  font-weight: 700;
  color: #3b82f6;
  border-bottom: 2px solid #e2e8f0;
  display: inline-block;
  padding: 0 2rem 0.35rem 2rem;
  margin: 1rem 0;
}

.cert-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin: 1.5rem 0;
  padding: 1rem;
  background: #f8fafc;
  border-radius: 8px;
  font-family: var(--font-sans);
}

.cert-stat-label {
  font-size: 0.7rem;
  color: #64748b;
  text-transform: uppercase;
  font-weight: 700;
}

.cert-stat-val {
  font-size: 1.5rem;
  font-weight: 800;
  color: #0f172a;
}

.cert-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: 2rem;
  font-family: var(--font-sans);
}

.cert-seal {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 2px dashed #f59e0b;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f59e0b;
  font-size: 1.8rem;
  background: #fffbeb;
}

.cert-serial {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: #94a3b8;
}

.main-footer {
  margin-top: auto;
  padding: 2rem 0;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.footer-links {
  display: flex;
  gap: 1.25rem;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.footer-links a:hover {
  color: var(--text-main);
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
}

@media (max-width: 900px) {
  .words-wrapper { font-size: 1.25rem; line-height: 2; }
  .hud-stat-value { font-size: 1.4rem; }
  .key-cap { height: 40px; min-width: 32px; font-size: 0.75rem; }
}

@media (max-width: 640px) {
  .main-header { flex-direction: column; align-items: flex-start; gap: 1rem; }
  .modes-bar { overflow-x: auto; }
  .live-hud { flex-wrap: wrap; gap: 1rem; }
  .hud-timer-progress { order: 3; width: 100%; margin: 0.5rem 0 0 0; }
  .virtual-keyboard { display: none; }
}
