/* ============================================
   StenoType - Typing Room App Styles
   Dark theme with royal blue + gold accents
   Premium, professional, Monkeytype-inspired
   ============================================ */

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

:root {
  --bg: #0c0e14;
  --bg-surface: #12151e;
  --bg-elevated: #181c28;
  --bg-hover: #1e2333;
  --border: #252a3a;
  --text-primary: #e8eaf0;
  --text-secondary: #6b7394;
  --text-dim: #3d4263;
  --gold: #d4a843;
  --gold-bright: #f0c74d;
  --gold-dim: #8a6d2b;
  --blue: #4a7cff;
  --blue-bright: #6b9aff;
  --blue-dim: #2a4a8c;
  --teal: #0d9488;
  --teal-dim: #0a7a70;
  --green: #34d399;
  --red: #f87171;
  --red-dim: #991b1b;
  --amber: #fbbf24;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'DM Sans', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --max-width: 1100px;
  --transition: 150ms ease;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100vh;
}

h1, h2, h3, h4 { font-family: var(--font-display); }

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-bright); }

/* ============ NAV ============ */
#app-nav {
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--max-width);
  margin: 0 auto;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  color: var(--text-primary);
  text-decoration: none;
  letter-spacing: -0.5px;
}
.logo span { color: var(--teal); }

.nav-links {
  display: flex;
  gap: 0.25rem;
}

.nav-link {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  text-decoration: none;
}
.nav-link:hover { color: var(--text-primary); background: var(--bg-hover); }
.nav-link.active { color: var(--gold); background: rgba(212,168,67,0.08); }

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

.nav-btn {
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.5rem 1.15rem;
  border-radius: 100px;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.nav-btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.nav-btn-ghost:hover { color: var(--text-primary); border-color: var(--text-dim); }

.nav-btn-primary {
  background: var(--gold);
  color: var(--bg);
}
.nav-btn-primary:hover { background: var(--gold-bright); }

.nav-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.nav-user:hover { background: var(--bg-hover); color: var(--text-primary); }

.nav-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--blue-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.7rem;
  color: var(--blue-bright);
}

.nav-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  min-width: 160px;
  z-index: 100;
  display: none;
}
.nav-dropdown.open { display: block; }
.nav-dropdown a, .nav-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-body);
  text-decoration: none;
}
.nav-dropdown a:hover, .nav-dropdown button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ============ MAIN ============ */
#app-main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem;
  min-height: calc(100vh - 70px);
}

/* ============ TYPING ROOM ============ */
.typing-room {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  padding-top: 2rem;
}

.typing-header {
  text-align: center;
}
.typing-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}
.typing-header p {
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* Test Config Bar */
.test-config {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 100px;
}

.config-group {
  display: flex;
  gap: 0.15rem;
}

.config-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 0.25rem;
}

.config-btn {
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.4rem 0.9rem;
  border: none;
  border-radius: 100px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.config-btn:hover { color: var(--text-primary); }
.config-btn.active {
  background: var(--gold);
  color: var(--bg);
  font-weight: 600;
}

/* Text Display Area */
.typing-area {
  width: 100%;
  max-width: 900px;
  position: relative;
}

.typing-prompt {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  line-height: 2;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  position: relative;
  user-select: none;
  min-height: 180px;
  overflow: hidden;
  padding: 1.5rem 0;
  cursor: text;
  outline: none;
}

.typing-prompt .char {
  position: relative;
  transition: color 50ms;
}
.typing-prompt .char.correct {
  color: var(--text-primary);
}
.typing-prompt .char.incorrect {
  color: var(--red);
  background: rgba(248,113,113,0.1);
  border-radius: 2px;
}
.typing-prompt .char.current {
  color: var(--text-dim);
}
.typing-prompt .char.current::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--gold);
  animation: blink 1s ease-in-out infinite;
  border-radius: 1px;
}

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

.typing-prompt .char.extra {
  color: var(--red);
  opacity: 0.5;
}

/* Hidden input for mobile compatibility */
.typing-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

/* Live Stats Bar */
.live-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.5rem;
  padding: 1rem 0;
}

.live-stat {
  text-align: center;
}
.live-stat-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
}
.live-stat-value.wpm-value { color: var(--gold); }
.live-stat-label {
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-top: 0.3rem;
}

/* Timer */
.typing-timer {
  font-family: var(--font-display);
  font-size: 3rem;
  font-weight: 700;
  color: var(--gold);
  text-align: center;
  line-height: 1;
  min-width: 80px;
}

/* Restart Button */
.restart-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.5rem;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 100px;
  cursor: pointer;
  transition: all var(--transition);
}
.restart-btn:hover { color: var(--text-primary); border-color: var(--text-dim); }
.restart-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-align: center;
}

/* Focus overlay */
.typing-focus-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12,14,20,0.85);
  border-radius: var(--radius);
  z-index: 5;
  cursor: pointer;
}
.typing-focus-hint span {
  font-size: 1rem;
  color: var(--text-secondary);
  font-weight: 500;
}
.typing-focus-hint.hidden { display: none; }

/* ============ RESULTS SCREEN ============ */
.results-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  padding: 3rem 0;
  animation: fadeIn 0.4s ease;
}

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

.results-hero {
  text-align: center;
}
.results-hero h2 {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 0.75rem;
}
.results-wpm {
  font-family: var(--font-display);
  font-size: 5rem;
  font-weight: 700;
  color: var(--gold);
  line-height: 1;
}
.results-wpm-label {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  width: 100%;
  max-width: 600px;
}

.result-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
}
.result-card-value {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}
.result-card-value.green { color: var(--green); }
.result-card-value.red { color: var(--red); }
.result-card-value.blue { color: var(--blue-bright); }
.result-card-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
}

.results-actions {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.btn {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.65rem 1.5rem;
  border-radius: 100px;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
}
.btn-primary {
  background: var(--gold);
  color: var(--bg);
}
.btn-primary:hover { background: var(--gold-bright); }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--text-dim); }

.results-save-prompt {
  text-align: center;
  padding: 1.25rem 2rem;
  background: rgba(212,168,67,0.06);
  border: 1px solid rgba(212,168,67,0.15);
  border-radius: var(--radius);
  max-width: 500px;
}
.results-save-prompt p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

/* ============ AUTH PAGES ============ */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}

.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}

.auth-card h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 0.25rem;
}

.auth-card .auth-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.form-group {
  margin-bottom: 1.25rem;
}
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.5rem;
}
.form-group input {
  width: 100%;
  padding: 0.7rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  transition: border-color var(--transition);
  outline: none;
}
.form-group input:focus {
  border-color: var(--gold);
}
.form-group input::placeholder {
  color: var(--text-dim);
}

.form-error {
  background: rgba(248,113,113,0.08);
  border: 1px solid rgba(248,113,113,0.2);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  font-size: 0.85rem;
  color: var(--red);
  margin-bottom: 1rem;
  display: none;
}
.form-error.visible { display: block; }

.auth-submit {
  width: 100%;
  padding: 0.75rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--gold);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}
.auth-submit:hover { background: var(--gold-bright); }
.auth-submit:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.auth-footer a { color: var(--gold); font-weight: 500; }

/* ============ LEADERBOARD PAGE ============ */
.leaderboard-page {
  padding-top: 2rem;
}

.leaderboard-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 2rem;
  gap: 1rem;
}
.leaderboard-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.leaderboard-header p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.leaderboard-filters {
  display: flex;
  gap: 0.5rem;
}

.lb-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.lb-stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
}
.lb-stat-value {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--gold);
}
.lb-stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

.leaderboard-table {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.lb-row {
  display: grid;
  grid-template-columns: 60px 1fr 120px 100px 140px;
  align-items: center;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.lb-row:last-child { border-bottom: none; }
.lb-row:hover { background: var(--bg-hover); }

.lb-row-header {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  background: var(--bg-elevated);
}
.lb-row-header:hover { background: var(--bg-elevated); }

.lb-rank {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-secondary);
}
.lb-rank.gold { color: var(--gold-bright); font-size: 1.1rem; }
.lb-rank.silver { color: #c0c0c0; }
.lb-rank.bronze { color: #cd7f32; }

.lb-user {
  font-weight: 500;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.lb-wpm {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  color: var(--gold);
}

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

.lb-date {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.lb-empty {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-secondary);
}
.lb-empty h3 {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}
.lb-empty p {
  font-size: 0.9rem;
  color: var(--text-dim);
}

/* ============ PROFILE PAGE ============ */
.profile-page {
  padding-top: 2rem;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-dim), var(--blue));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  color: white;
}

.profile-info h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.profile-info p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2.5rem;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
}
.stat-card-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--gold);
}
.stat-card-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-top: 0.25rem;
}
.stat-card-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

.history-section h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.history-table {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.history-row {
  display: grid;
  grid-template-columns: 1fr 100px 100px 100px 140px;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.history-row:last-child { border-bottom: none; }
.history-row-header {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  background: var(--bg-elevated);
}

.history-wpm {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--gold);
}

/* ============ LOADING / EMPTY STATES ============ */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 0.75rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ MOBILE ============ */
@media (max-width: 768px) {
  #app-nav { padding: 0.75rem 1rem; }
  .nav-links { display: none; }
  #app-main { padding: 1rem; }

  .typing-prompt { font-size: 1.1rem; line-height: 1.9; }

  .results-grid { grid-template-columns: repeat(2, 1fr); }
  .results-wpm { font-size: 3.5rem; }

  .lb-stats { grid-template-columns: repeat(2, 1fr); }
  .lb-row { grid-template-columns: 40px 1fr 80px 70px; }
  .lb-date { display: none; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .history-row { grid-template-columns: 1fr 80px 80px; }
  .history-row > *:nth-child(4),
  .history-row > *:nth-child(5) { display: none; }

  .test-config { flex-wrap: wrap; justify-content: center; }
  .leaderboard-header { flex-direction: column; align-items: flex-start; }

  .profile-header { flex-direction: column; text-align: center; }
}

/* Mobile nav toggle */
.mobile-nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.5rem;
}

@media (max-width: 768px) {
  .mobile-nav-toggle { display: block; }
  .nav-links.open {
    display: flex;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem;
    flex-direction: column;
    z-index: 50;
  }
}
