:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  background-color: #090d16;
  color: #f1f5f9;

  --surface: #111827;
  --surface-soft: #172033;
  --surface-muted: #1f293d;
  --border: rgba(255, 255, 255, 0.1);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.25);

  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.15);

  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.18);

  --warning: #f59e0b;
  --info: #0ea5e9;

  --font-mono: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  --radius-lg: 1.25rem;
  --radius-md: 0.85rem;
  --radius-sm: 0.5rem;
  --shadow-lg: 0 20px 40px -15px rgba(0, 0, 0, 0.5);
}

body.light-theme {
  color-scheme: light;
  background-color: #f8fafc;
  color: #0f172a;

  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --surface-muted: #e2e8f0;
  --border: rgba(15, 23, 42, 0.1);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --accent: #4f46e5;
  --accent-light: #6366f1;
  --accent-glow: rgba(79, 70, 229, 0.15);

  --success: #059669;
  --success-bg: rgba(5, 150, 105, 0.12);

  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.12);

  --warning: #d97706;
  --info: #0284c7;
}

* {
  box-sizing: border-box;
}

html, body {
  min-height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: radial-gradient(circle at top left, rgba(99, 102, 241, 0.12), transparent 30%),
              radial-gradient(circle at bottom right, rgba(14, 165, 233, 0.1), transparent 30%),
              var(--background, #090d16);
}

button, input, select {
  font: inherit;
}

button {
  border: none;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

/* Sidebar Styling */
.sidebar {
  display: flex;
  flex-direction: column;
  padding: 2rem 1.25rem;
  gap: 1.5rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

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

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 1rem;
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  color: white;
  font-weight: 800;
  font-size: 1.2rem;
  box-shadow: 0 8px 20px var(--accent-glow);
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
}

.brand p {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin: 0;
}

.nav-menu {
  display: grid;
  gap: 0.5rem;
}

.nav-link {
  width: 100%;
  text-align: left;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  background: transparent;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: all 0.2s ease;
}

.nav-link:hover, .nav-link.active {
  background: var(--accent-glow);
  color: var(--accent-light);
  border-left: 3px solid var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 0.75rem;
}

/* Main Content Area */
.content {
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  max-width: 1300px;
  margin: 0 auto;
  width: 100%;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.topbar h2 {
  font-size: 1.75rem;
  margin: 0;
}

.topbar p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

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

input[type="search"] {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text-primary);
  min-width: 220px;
}

.action-button, .icon-button, .copy-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  color: white;
  font-weight: 600;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.action-button:hover, .icon-button:hover, .copy-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.icon-button {
  background: var(--surface-muted);
  color: var(--text-primary);
  box-shadow: none;
}

/* Ad Placement Slots */
.ad-slot-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 1rem 0;
  min-height: 90px;
  background: var(--surface-soft);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  padding: 0.5rem;
}

.ad-slot-header {
  min-height: 90px;
  width: 100%;
}

.ad-slot-sidebar {
  min-height: 250px;
  width: 100%;
}

.ad-slot-native {
  min-height: 120px;
  width: 100%;
}

/* Typing Master Card & Controls */
.typing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.test-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  background: var(--surface-soft);
  padding: 1rem 1.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-group {
  display: flex;
  background: var(--surface-muted);
  border-radius: var(--radius-sm);
  padding: 0.25rem;
}

.opt-btn {
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

.opt-btn.active, .opt-btn:hover {
  background: var(--accent);
  color: white;
}

.toggle-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
}

/* Scoreboard */
.scoreboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
}

.stat-box {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.stat-box h3 {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
}

.stat-box .val {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--accent-light);
  margin: 0.25rem 0 0;
  font-family: var(--font-mono);
}

/* Circular Timer Ring */
.timer-container {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.timer-ring-svg {
  transform: rotate(-90deg);
  width: 70px;
  height: 70px;
}

.timer-ring-circle {
  transition: stroke-dashoffset 0.3s linear;
  stroke-linecap: round;
}

.timer-text {
  position: absolute;
  font-weight: 800;
  font-size: 1.1rem;
  font-family: var(--font-mono);
}

/* Typing Words Container */
.words-wrapper {
  position: relative;
  background: var(--surface-soft);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.75rem;
  min-height: 160px;
  max-height: 220px;
  overflow: hidden;
  line-height: 2.2rem;
  user-select: none;
}

.words-wrapper:focus-within, .words-wrapper:hover {
  border-color: var(--accent);
}

.words-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 0.85rem;
  font-size: 1.4rem;
  font-family: var(--font-mono);
}

.word {
  display: inline-flex;
  padding: 0.1rem 0.25rem;
  border-radius: 0.3rem;
  transition: background 0.15s ease;
}

.word.current {
  background: rgba(99, 102, 241, 0.18);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.word.correct {
  opacity: 0.7;
}

.word.incorrect {
  text-decoration: underline red;
}

.char {
  color: var(--text-muted);
  position: relative;
}

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

.char.incorrect {
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: 2px;
}

.char.caret::before {
  content: '';
  position: absolute;
  left: 0;
  top: 10%;
  height: 80%;
  width: 2.5px;
  background-color: var(--accent-light);
  animation: blink 1s infinite;
  box-shadow: 0 0 8px var(--accent);
}

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

/* Hidden Input for Focus Capture */
.hidden-input {
  position: absolute;
  opacity: 0;
  left: -9999px;
}

.test-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.shortcut-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.shortcut-hint kbd {
  background: var(--surface-muted);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  color: var(--text-primary);
}

/* Modal Dialog */
[hidden], .modal-overlay[hidden] {
  display: none !important;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1.5rem;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 650px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  text-align: center;
}

.modal-header h3 {
  font-size: 1.8rem;
  margin: 0 0 0.5rem;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal-rank {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
}

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

.res-box {
  background: var(--surface-soft);
  padding: 1rem;
  border-radius: var(--radius-md);
  text-align: center;
  border: 1px solid var(--border);
}

.res-box label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.res-box span {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--accent-light);
  font-family: var(--font-mono);
}

.modal-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.gold-btn {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
}

/* Touch Typing Lessons */
.lessons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}

.lesson-card {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.lesson-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.lesson-header h4 {
  margin: 0;
  font-size: 1.1rem;
}

/* Keyboard Diagnostics Panel */
.panel-list {
  display: grid;
  gap: 1.25rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.metric-item {
  background: var(--surface-soft);
  padding: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Articles & FAQ */
.articles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

.article-card {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.75rem;
}

.faq-list {
  display: grid;
  gap: 1rem;
}

.faq-item {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.faq-question {
  width: 100%;
  text-align: left;
  padding: 1.25rem;
  background: transparent;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.05rem;
  display: flex;
  justify-content: space-between;
}

.faq-answer {
  padding: 0 1.25rem 1.25rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Badges */
.badge {
  display: inline-flex;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-info { background: rgba(14, 165, 233, 0.15); color: var(--info); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: var(--warning); }

/* Status Banners */
.status-banner {
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid var(--accent-glow);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.status-success { background: var(--success-bg); border-color: rgba(16, 185, 129, 0.3); }

/* Footer */
.site-footer {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.site-footer a {
  color: var(--accent-light);
  text-decoration: none;
}

/* Responsive Breakpoints */
@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .scoreboard {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .content {
    padding: 1rem;
  }
  .test-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .scoreboard {
    grid-template-columns: 1fr;
  }
  .results-grid {
    grid-template-columns: 1fr;
  }
}
