/* Game-specific tokens (shared tokens from design-tokens.css) */


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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

#app {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===== Transitions ===== */
.view {
  width: 100%;
  animation: fadeIn 0.35s ease;
}

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

/* ===== Landing View ===== */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  text-align: center;
  gap: 32px;
}

.landing-icon {
  font-size: 3.5rem;
  line-height: 1;
  margin-bottom: -12px;
}

.landing h1 {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--color-primary);
}

.landing .subtitle {
  color: var(--text-secondary);
  font-size: 1.05rem;
  margin-top: -20px;
  max-width: 420px;
}

/* Duration Picker */
.duration-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.duration-picker label {
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.pill-group {
  display: flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 4px;
  gap: 2px;
}

.pill-btn {
  padding: 10px 28px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

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

.pill-btn.active {
  background: var(--color-primary);
  color: var(--bg-primary);
}

/* Start Button */
.start-btn {
  padding: 16px 64px;
  border: none;
  border-radius: var(--radius);
  background: var(--color-primary);
  color: var(--bg-primary);
  font-family: var(--font-main);
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s ease;
  letter-spacing: 0.02em;
}

.start-btn:hover {
  transform: translateY(-2px);
  opacity: 0.9;
}

.start-btn:active {
  transform: translateY(0);
}

/* ===== Game View ===== */
.game-view {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Stats Bar */
.stats-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px 24px;
  gap: 16px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--color-primary);
  line-height: 1.2;
}

.stat-value.accuracy {
  color: var(--color-success);
}

.stat-value.timer {
  color: var(--color-warning);
  font-family: var(--font-mono);
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

/* Timer Progress Bar */
.timer-bar-container {
  width: 100%;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  background: var(--color-warning);
  border-radius: var(--radius);
  transition: width 0.5s linear;
  will-change: width;
}

/* Typing Area */
.typing-area {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 28px 32px;
  min-height: 260px;
  max-height: 400px;
  overflow-y: auto;
  position: relative;
  cursor: text;
  scroll-behavior: smooth;
}

.typing-area:focus-within {
  border-color: rgba(0, 212, 255, 0.3);
}

.passage-text {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  line-height: 2;
  word-wrap: break-word;
  letter-spacing: 0.01em;
}

.passage-text .word {
  white-space: nowrap;
  display: inline;
}

.passage-text .char {
  position: relative;
  transition: color 0.05s ease;
  border-radius: 2px;
}

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

.passage-text .char.incorrect {
  color: var(--color-accent);
  background: rgba(233, 69, 96, 0.15);
  border-radius: 2px;
  text-decoration: underline wavy var(--color-accent);
  text-underline-offset: 3px;
}

.passage-text .char.untyped {
  color: var(--text-muted);
}

.passage-text .char.current {
  color: var(--text-primary);
}

/* Blinking Cursor */
.passage-text .char.current::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 2px;
  bottom: 2px;
  width: 2px;
  background: var(--color-primary);
  border-radius: 1px;
  animation: blink 1s steps(2) infinite;
}

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

/* Typing prompt */
.typing-prompt {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-muted);
  font-size: 0.95rem;
  pointer-events: none;
  animation: pulse 2s ease-in-out infinite;
}

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

/* Mobile focus helper */
.focus-helper {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 24px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.85rem;
  display: none;
  z-index: 100;
  animation: pulse 2s ease-in-out infinite;
}

/* Hidden input for mobile keyboard */
.hidden-input {
  position: fixed;
  top: -100px;
  left: -100px;
  opacity: 0;
  width: 1px;
  height: 1px;
}

/* ===== Results View ===== */
.results-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  gap: 32px;
  text-align: center;
}

.results-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

/* Big WPM Display */
.wpm-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.wpm-number {
  font-size: 5rem;
  font-weight: 800;
  line-height: 1;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}

.wpm-unit {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Rating Badge */
.rating-badge {
  padding: 8px 20px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--color-primary);
  font-size: 0.9rem;
  font-weight: 600;
}

/* Rank Badge */
.rank-badge {
  display: flex;
  align-items: baseline;
  gap: 6px;
  animation: rankReveal 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

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

.rank-position {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--color-primary);
}

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

/* Accuracy Ring */
.accuracy-ring-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.accuracy-ring {
  position: relative;
  width: 120px;
  height: 120px;
}

.accuracy-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.accuracy-ring .ring-bg {
  fill: none;
  stroke: var(--bg-tertiary);
  stroke-width: 6;
}

.accuracy-ring .ring-fg {
  fill: none;
  stroke: var(--color-success);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset 1.5s ease;
}

.accuracy-ring .ring-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.accuracy-ring .ring-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-success);
  line-height: 1.2;
}

.accuracy-ring .ring-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 400px;
}

.stats-grid .stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stats-grid .stat-card .sc-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stats-grid .stat-card .sc-label {
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

/* Results Buttons */
.results-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  #app {
    padding: 24px 12px;
  }

  .landing h1 {
    font-size: 2rem;
  }

  .pill-btn {
    padding: 8px 18px;
    font-size: 0.85rem;
  }

  .start-btn {
    padding: 14px 48px;
    font-size: 1rem;
  }

  .stats-bar {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 12px;
  }

  .stat-value {
    font-size: 1.2rem;
  }

  .typing-area {
    padding: 20px 16px;
    min-height: 200px;
    max-height: 320px;
  }

  .passage-text {
    font-size: 1rem;
    line-height: 1.9;
  }

  .wpm-number {
    font-size: 3.5rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .focus-helper {
    display: block;
  }
}

@media (max-width: 400px) {
  .pill-btn {
    padding: 7px 14px;
    font-size: 0.8rem;
  }

  .stats-bar {
    justify-content: center;
  }
}

/* ===== Scrollbar ===== */
.typing-area::-webkit-scrollbar {
  width: 6px;
}

.typing-area::-webkit-scrollbar-track {
  background: transparent;
}

.typing-area::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.typing-area::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Misc Utility ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
