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

body {
  background: #202124;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #e8eaed;
  user-select: none;
  -webkit-user-select: none;
}

#back-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  color: #fff;
  text-decoration: none;
  font-size: 22px;
  font-weight: 700;
  z-index: 20;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #5f6368;
  transition: background 0.2s;
  line-height: 1;
}

#back-btn:hover {
  background: #80868b;
}

#game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
  width: 100%;
  max-width: 800px;
}

/* Toolbar */
#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 4px;
}

#stat-wpm,
#stat-accuracy,
#stat-timer {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#stat-wpm span {
  color: #66bb6a;
}

#stat-timer span {
  color: #ffa726;
}

/* Duration bar */
#duration-bar {
  display: flex;
  gap: 6px;
  background: #292a2d;
  padding: 4px;
  border-radius: 12px;
}

.dur-btn {
  padding: 8px 20px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #9aa0a6;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.dur-btn:hover {
  color: #e8eaed;
}

.dur-btn.active {
  background: #66bb6a;
  color: #fff;
}

/* Text display */
#text-display {
  width: 100%;
  background: #292a2d;
  border-radius: 12px;
  padding: 28px 32px;
  font-size: 22px;
  line-height: 1.8;
  letter-spacing: 0.3px;
  color: #5f6368;
  min-height: 180px;
  position: relative;
  cursor: text;
}

#text-display .char {
  position: relative;
  transition: color 0.05s;
}

#text-display .char.correct {
  color: #e8eaed;
}

#text-display .char.incorrect {
  color: #ef5350;
  background: rgba(239, 83, 80, 0.15);
  border-radius: 2px;
}

#text-display .char.current {
  border-left: 2px solid #66bb6a;
  margin-left: -1px;
  padding-left: 1px;
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  0%, 100% { border-color: #66bb6a; }
  50% { border-color: transparent; }
}

#text-display .char.current-typing {
  border-left: 2px solid #66bb6a;
  margin-left: -1px;
  padding-left: 1px;
  animation: none;
}

/* Word wrapping - extra spaces between words */
#text-display .word-space {
  display: inline;
}

/* Input area */
#input-area {
  width: 100%;
}

#input-field {
  width: 100%;
  background: #303134;
  border: 2px solid #3c4043;
  border-radius: 10px;
  padding: 14px 20px;
  font-size: 20px;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #e8eaed;
  outline: none;
  transition: border-color 0.2s;
  letter-spacing: 0.3px;
}

#input-field:focus {
  border-color: #66bb6a;
}

#input-field:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Restart */
#restart-bar {
  display: flex;
}

#restart-btn {
  background: #3c4043;
  border: none;
  padding: 10px 28px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #e8eaed;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

#restart-btn:hover {
  background: #5f6368;
}

#restart-btn:active {
  transform: scale(0.95);
}

/* Stats bar */
#stats-bar {
  display: flex;
  gap: 28px;
}

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

.stat-label {
  font-size: 12px;
  color: #5f6368;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #e8eaed;
}

.stat-correct {
  color: #66bb6a;
}

.stat-errors {
  color: #ef5350;
}

/* Results overlay */
#results-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}

.results-box {
  background: #303134;
  border-radius: 16px;
  padding: 40px 48px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  min-width: 300px;
}

.results-box h2 {
  font-size: 28px;
  margin-bottom: 4px;
  color: #66bb6a;
}

.results-box .wpm-big {
  font-size: 64px;
  font-weight: 800;
  color: #66bb6a;
  margin: 8px 0 16px;
  font-variant-numeric: tabular-nums;
}

.results-box .result-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 24px;
}

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

.results-box .result-stat .rs-label {
  font-size: 12px;
  color: #5f6368;
  font-weight: 600;
  text-transform: uppercase;
}

.results-box .result-stat .rs-value {
  font-size: 22px;
  font-weight: 700;
  color: #e8eaed;
}

.results-box button {
  background: #66bb6a;
  border: none;
  padding: 12px 36px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.results-box button:hover {
  background: #81c784;
}

@media (max-width: 640px) {
  #game-container {
    padding: 14px;
    gap: 12px;
  }

  #text-display {
    font-size: 18px;
    padding: 20px 18px;
    min-height: 140px;
  }

  #input-field {
    font-size: 16px;
    padding: 12px 16px;
  }

  .dur-btn {
    padding: 6px 14px;
    font-size: 13px;
  }

  #stat-wpm,
  #stat-accuracy,
  #stat-timer {
    font-size: 16px;
  }

  #stats-bar {
    gap: 16px;
  }

  .stat-value {
    font-size: 16px;
  }

  .results-box {
    padding: 28px 24px;
    margin: 0 16px;
  }

  .results-box .wpm-big {
    font-size: 48px;
  }
}
