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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.tr-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #1e2130;
}
.tr-header h1 { font-size: 1.2rem; font-weight: 700; flex: 1; }
.tr-back { color: #94a3b8; text-decoration: none; font-size: 0.9rem; }
.tr-back:hover { color: #e2e8f0; }

.tr-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}
.tr-screen.hidden { display: none; }

.tr-card {
  background: #1a1f2e;
  border: 1px solid #2d3348;
  border-radius: 16px;
  padding: 2rem;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.tr-card h2 { font-size: 1.4rem; font-weight: 700; text-align: center; }
.tr-card h3 { font-size: 1rem; font-weight: 600; margin-top: 0.5rem; }

input[type="text"] {
  width: 100%;
  padding: 0.75rem 1rem;
  background: #0f1117;
  border: 1px solid #2d3348;
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus { border-color: #6366f1; }

.tr-btn {
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tr-btn:hover { opacity: 0.85; }
.tr-btn.primary { background: #6366f1; color: #fff; }
.tr-btn.secondary { background: #2d3348; color: #e2e8f0; }
.tr-btn.small { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.tr-btn.ready-active { background: #22c55e; color: #fff; }

.tr-home-buttons { display: flex; gap: 0.75rem; }
.tr-home-buttons .tr-btn { flex: 1; }
.tr-join-row { display: flex; gap: 0.5rem; }
.tr-join-row input { flex: 1; }

.tr-error { color: #f87171; font-size: 0.85rem; min-height: 1.2em; text-align: center; }

.tr-room-code {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #0f1117;
  border: 1px solid #2d3348;
  border-radius: 8px;
  padding: 0.75rem 1rem;
}
.tr-room-code strong { font-size: 1.4rem; letter-spacing: 0.1em; color: #6366f1; flex: 1; }
.tr-hint { color: #94a3b8; font-size: 0.85rem; line-height: 1.5; }

.tr-players-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.tr-players-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: #0f1117;
  border-radius: 6px;
  font-size: 0.95rem;
}
.ready-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #374151; flex-shrink: 0;
}
.ready-dot.ready { background: #22c55e; }

.tr-countdown-display {
  font-size: 8rem;
  font-weight: 900;
  color: #6366f1;
  user-select: none;
  animation: pulse 0.9s ease-in-out infinite;
}
@keyframes pulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

#screen-race {
  flex-direction: column;
  align-items: stretch;
  padding: 1.5rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  gap: 1rem;
}

.tr-race-progress { display: flex; flex-direction: column; gap: 0.4rem; }
.tr-progress-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
}
.tr-progress-name {
  width: 100px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #94a3b8;
}
.tr-progress-bar-wrap {
  flex: 1; height: 8px;
  background: #1e2130;
  border-radius: 4px;
  overflow: hidden;
}
.tr-progress-bar {
  height: 100%;
  border-radius: 4px;
  background: #6366f1;
  transition: width 0.3s ease;
  width: 0%;
}
.tr-progress-wpm { width: 60px; text-align: right; color: #94a3b8; font-size: 0.8rem; }

.tr-words-wrap {
  background: #1a1f2e;
  border: 1px solid #2d3348;
  border-radius: 12px;
  padding: 1.5rem;
  min-height: 120px;
}
.tr-words {
  font-size: 1.5rem;
  line-height: 2.2;
  color: #4b5563;
  user-select: none;
}
.tr-words .word { margin-right: 0.35em; display: inline; }
.tr-words .word.done { color: #6b7280; }
.tr-words .word.correct { color: #22c55e; }
.tr-words .word.wrong { color: #ef4444; }
.tr-words .word.current { color: #e2e8f0; }

#race-input {
  font-size: 1.2rem;
  padding: 0.9rem 1.2rem;
  border-radius: 10px;
  border: 2px solid #2d3348;
}
#race-input:focus { border-color: #6366f1; }
#race-input.error { border-color: #ef4444; }

.tr-race-stats {
  display: flex;
  justify-content: space-between;
  color: #94a3b8;
  font-size: 0.9rem;
}

.tr-results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}
.tr-results-table th,
.tr-results-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid #2d3348;
}
.tr-results-table th { color: #94a3b8; font-weight: 600; }
.tr-results-table td:last-child { font-weight: 700; color: #6366f1; }

.tr-results-actions { display: flex; gap: 0.75rem; }
.tr-results-actions .tr-btn { flex: 1; }

@media (max-width: 600px) {
  .tr-words { font-size: 1.1rem; }
  .tr-countdown-display { font-size: 5rem; }
  #screen-race { padding: 1rem; }
}
