/* -------------------------------------------------------------------------- */
/* Design Tokens & CSS Variables (Dark & Light Modes)                         */
/* -------------------------------------------------------------------------- */

:root {
  /* Font Families */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;

  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

/* Dark Theme (Default) */
[data-theme="dark"] {
  --bg-page: #121417;
  --bg-card: #1a1d24;
  --bg-card-hover: #222630;
  --bg-input: #15181e;
  --border-color: #2e3440;
  
  --text-primary: #eceff4;
  --text-secondary: #8892b0;
  --text-muted: #535d75;
  
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --accent-light: rgba(59, 130, 246, 0.12);

  --correct-char: #34d399;
  --error-char: #f87171;
  --error-bg: rgba(248, 113, 113, 0.15);
  --untyped-char: #64748b;
  --caret-color: #3b82f6;
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

/* Light Theme */
[data-theme="light"] {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-input: #f8fafc;
  --border-color: #e2e8f0;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --accent-color: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: rgba(37, 99, 235, 0.08);

  --correct-char: #059669;
  --error-char: #dc2626;
  --error-bg: rgba(220, 38, 38, 0.1);
  --untyped-char: #94a3b8;
  --caret-color: #2563eb;
  
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
}

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

html, body {
  width: 100%;
  min-height: 100vh;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Container */
.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* Header */
.site-header {
  border-bottom: 1px solid var(--border-color);
  padding: 1.25rem 0;
  background: var(--bg-card);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

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

.logo-icon {
  font-size: 1.75rem;
  background: var(--accent-light);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

.main-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.sub-tagline {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  background: transparent;
  color: var(--text-primary);
}

.btn-primary {
  background: var(--accent-color);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

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

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

.btn-outline {
  border-color: var(--border-color);
  color: var(--text-secondary);
}

.btn-outline:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background var(--transition-fast);
}

.icon-btn:hover {
  background: var(--bg-card-hover);
}

/* Main Container Layout */
.main-container {
  padding-top: 1.25rem;
  padding-bottom: 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Controls Card */
.controls-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.65rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  box-shadow: var(--shadow-sm);
}

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

.control-label {
  font-size: 0.775rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: auto;
  white-space: nowrap;
}

.pill-group {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  background: var(--bg-input);
  padding: 0.15rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.pill-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 0.25rem 0.6rem;
  font-size: 0.775rem;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pill-btn:hover {
  color: var(--text-primary);
}

.pill-btn.active {
  background: var(--accent-color);
  color: #ffffff;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* Metrics Dashboard Bar */
.metrics-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.metric-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.metric-item.highlight {
  border-color: var(--accent-color);
  background: var(--accent-light);
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.metric-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

/* Typing Arena Box */
.typing-box-container {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-md);
  cursor: text;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hidden-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  z-index: 2;
  cursor: default;
  resize: none;
}

.touch-overlay {
  position: absolute;
  inset: 0;
  background: rgba(18, 20, 23, 0.75);
  backdrop-filter: blur(3px);
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-align: center;
  transition: opacity var(--transition-normal);
}

[data-theme="light"] .touch-overlay {
  background: rgba(248, 250, 252, 0.85);
}

.touch-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.touch-icon {
  font-size: 2.25rem;
  margin-bottom: 0.5rem;
  animation: bounce 1.5s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.words-wrapper {
  max-height: 140px;
  overflow: hidden;
  position: relative;
  margin-bottom: 1rem;
}

.words-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6em;
  font-family: var(--font-mono);
  font-size: 1.4rem;
  line-height: 1.8;
  color: var(--untyped-char);
  user-select: none;
  transition: transform var(--transition-fast);
}

.word {
  display: inline-block;
  white-space: nowrap;
  position: relative;
  padding: 0 2px;
  border-radius: 3px;
}

.word.current {
  background: var(--accent-light);
}

.char {
  position: relative;
  transition: color 0.05s ease;
}

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

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

.char.extra {
  color: var(--error-char);
  opacity: 0.8;
}

.caret {
  position: absolute;
  left: 0;
  bottom: 2px;
  width: 2px;
  height: 1.2em;
  background-color: var(--caret-color);
  animation: blink 1s infinite;
  transition: left 0.05s ease, top 0.05s ease;
  pointer-events: none;
  z-index: 1;
}

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

.arena-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  margin-top: 1rem;
}

.key-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

kbd {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

/* Results Modal */
.results-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.results-modal.active {
  opacity: 1;
  visibility: visible;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.modal-content-card {
  position: relative;
  z-index: 2;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  width: 100%;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform var(--transition-normal);
}

.results-modal.active .modal-content-card {
  transform: translateY(0);
}

.modal-header {
  text-align: center;
  margin-bottom: 0.85rem;
}

.modal-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.modal-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin-bottom: 0.85rem;
}

.result-card {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.result-card.primary {
  grid-column: span 2;
  background: var(--accent-light);
  border-color: var(--accent-color);
}

.card-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.card-value {
  font-size: 1.6rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-primary);
  margin: 0.1rem 0;
}

.result-card.primary .card-value {
  font-size: 2.25rem;
  color: var(--accent-color);
}

.card-unit {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.rating-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.85rem;
  margin-bottom: 1rem;
}

.rating-icon {
  font-size: 1.5rem;
}

.rating-text h3 {
  font-size: 0.875rem;
  font-weight: 700;
}

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

.modal-actions {
  display: flex;
  gap: 0.5rem;
  position: sticky;
  bottom: 0;
  background: var(--bg-card);
  padding-top: 0.5rem;
}

.modal-actions .btn {
  flex: 1;
  justify-content: center;
  padding: 0.6rem 0.85rem;
  font-size: 0.85rem;
}

/* SEO Article Section */
.seo-article-section {
  margin-top: 2rem;
}

.seo-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-sm);
}

.seo-card h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.seo-card p {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  line-height: 1.7;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
  margin: 1.75rem 0;
}

.feature-item {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
}

.feature-icon {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.feature-item h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.feature-item p {
  font-size: 0.85rem;
  margin-bottom: 0;
}

.faq-accordion {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.faq-item {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.1rem;
}

.faq-item summary {
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  color: var(--text-primary);
}

.faq-item p {
  margin-top: 0.65rem;
  margin-bottom: 0;
  font-size: 0.875rem;
}

/* Site Footer */
.site-footer {
  border-top: 1px solid var(--border-color);
  padding: 1.5rem 0;
  background: var(--bg-card);
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.footer-content {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

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

.footer-links a:hover {
  text-decoration: underline;
}

/* Responsive Media Queries */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .header-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .metrics-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  .control-group {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
  }

  .control-label {
    min-width: auto;
  }

  .words-container {
    font-size: 1.15rem;
  }

  .features-grid {
    grid-template-columns: 1fr;
  }

  .results-grid {
    grid-template-columns: 1fr;
  }

  .result-card.primary {
    grid-column: span 1;
  }

  .arena-footer {
    flex-direction: column;
    gap: 0.75rem;
  }
}
