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

/* The `hidden` HTML attribute maps to `display: none` in the UA stylesheet,
   but any author rule using an ID or higher-specificity selector with
   `display: <something>` silently wins over it. Force hidden everywhere. */
[hidden] { display: none !important; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #252836;
  --border: #2e3242;
  --text: #e4e4e7;
  --text-muted: #9ca3af;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --success: #22c55e;
  --error: #ef4444;
  --radius: 12px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* Hide spinner arrows on number inputs — keeps numeric keyboard on mobile */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* ========== Auth screen ========== */

#auth-screen {
  max-width: 380px;
  margin: 0 auto;
  padding: 60px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.auth-logo {
  width: 72px;
  height: 72px;
  margin-bottom: 16px;
}

#auth-screen h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.auth-subtitle {
  color: var(--text-muted);
  margin-bottom: 28px;
  font-size: 0.95rem;
}

#login-form,
#signup-form,
#confirm-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#auth-screen input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

#auth-screen input:focus { border-color: var(--accent); }
#auth-screen input::placeholder { color: var(--text-muted); }

#auth-screen button {
  padding: 12px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 4px;
}

#auth-screen button:hover { background: var(--accent-hover); }
#auth-screen button:disabled { opacity: 0.6; cursor: not-allowed; }

#confirm-form p {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  margin-bottom: 4px;
}

.auth-link {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 14px;
}

.auth-link a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  margin-left: 4px;
}

.auth-link a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

#auth-error {
  color: var(--error);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 14px;
  min-height: 1em;
}

/* ========== Game screen ========== */

#game-screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#game-screen header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-logo {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

#game-screen header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

#player-name {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-muted);
}

#player-name::before {
  content: '·';
  margin: 0 8px;
  color: var(--border);
}

.header-btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.header-btn:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.header-btn.primary {
  border-color: var(--accent);
  color: var(--accent);
}

.header-btn.primary:hover {
  background: rgba(99, 102, 241, 0.1);
}

.game-content {
  flex: 1;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  padding: 20px;
}

.intro {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 14px;
}

/* Progress bands + legend */

#progress-bands {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.band {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: rgba(15, 17, 23, 0.85);
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

#band-legend {
  margin-bottom: 24px;
}

#band-legend .legend-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 5px;
}

.legend-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10px;
}

.legend-color {
  width: 100%;
  aspect-ratio: 1.4;
  border-radius: 4px;
  opacity: 0.9;
}

.legend-label {
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* Question card */

#question-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  margin-bottom: 20px;
}

#result-text {
  min-height: 1.3em;
  text-align: center;
  font-size: 0.85rem;
  margin-bottom: 10px;
  color: var(--text-muted);
  font-weight: 500;
}

#result-text.correct { color: var(--success); }
#result-text.wrong { color: var(--error); }

#question-text {
  font-size: 2rem;
  font-weight: 700;
  margin: 4px 0 18px;
  text-align: center;
  color: var(--text);
  letter-spacing: -0.01em;
}

.answer-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

#answer-input {
  flex: 1;
  font-size: 1.75rem;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}

#answer-input:focus { border-color: var(--accent); }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: all 0.2s;
}

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-btn.listening {
  border-color: var(--error);
  color: var(--error);
  background: rgba(239, 68, 68, 0.1);
  animation: mic-pulse 1.4s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  50%      { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

#submit-btn {
  padding: 0 24px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

#submit-btn:hover:not(:disabled) { background: var(--accent-hover); }
#submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Scores table */

#scores-table {
  margin-bottom: 24px;
}

#scores-table h3 {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

#scores-table table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.85rem;
}

#scores-table th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 8px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

#scores-table td {
  padding: 11px 8px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

#scores-table tbody tr:last-child td { border-bottom: none; }

#scores-table tbody tr {
  position: relative;
  transition: background 0.15s;
}

#scores-table tbody tr:hover { background: var(--surface-2); }

/* Row-colour stripe: the band colour as a left-border, not the whole row.
   Achieved via a box-shadow inset on the first cell (which already has the
   row background via JS-set style). */
#scores-table tbody td:first-child {
  position: relative;
  padding-left: 14px;
}

#scores-table tbody td:first-child::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--row-color, var(--border));
}

#scores-table tbody td:first-child strong {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

/* Footer */

footer {
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding: 16px 0 4px;
  line-height: 1.55;
}

footer p { margin-bottom: 8px; }
footer p:last-child { margin-bottom: 0; }

footer .rewards {
  color: var(--accent);
  font-weight: 600;
  padding: 10px 14px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: 8px;
  margin-top: 10px;
}

/* ========== Details modal ========== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal[hidden] { display: none; }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
  margin-bottom: 18px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

#details-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#details-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#details-form input,
#details-form textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  outline: none;
  transition: border-color 0.2s;
}

#details-form input:focus,
#details-form textarea:focus { border-color: var(--accent); }

#details-form input::placeholder,
#details-form textarea::placeholder { color: var(--text-muted); }

#details-form input[readonly] {
  background: var(--bg);
  color: var(--text-muted);
  cursor: not-allowed;
}

#details-form textarea {
  resize: vertical;
  line-height: 1.5;
}

#details-form small {
  display: block;
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: none;
  letter-spacing: normal;
  margin-top: -2px;
}

.modal-error {
  color: var(--error);
  min-height: 1em;
  margin-top: 6px;
  font-size: 0.85rem;
  text-align: center;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.modal-actions button {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

/* ========== Mobile ========== */

@media (max-width: 600px) {
  #game-screen header { padding: 12px 14px; gap: 8px; }
  #game-screen header h1 { font-size: 1rem; }
  .header-btn { padding: 6px 10px; font-size: 0.75rem; }
  .game-content { padding: 14px; }
  #question-text { font-size: 1.75rem; }
  #answer-input { font-size: 1.5rem; }
  .icon-btn { width: 48px; font-size: 20px; }
  .band { font-size: 12px; border-radius: 6px; }
  #progress-bands { gap: 4px; }
  #band-legend .legend-grid { gap: 3px; }
  .legend-item { font-size: 9px; }
  #scores-table table { font-size: 0.78rem; }
  #scores-table th, #scores-table td { padding: 8px 6px; }
  #scores-table tbody td:first-child { padding-left: 10px; }
  #scores-table tbody td:first-child::before { width: 3px; }
}
