/* ================================================================
   TYPE RACER — SimplyJavaScript Game
   styles.css
   ================================================================ */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #0d0d0d;
  color: #f0f0f0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── Layout ── */
#game-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: relative;
}

/* ── Top bar ── */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: #111;
  border-bottom: 2px solid #FFC107;
  flex-shrink: 0;
  z-index: 20;
  gap: 4px 8px;
}

.top-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand {
  font-size: 0.95rem;
  font-weight: 700;
  color: #FFC107;
  letter-spacing: 0.3px;
  white-space: nowrap;
  text-decoration: none;
}
.brand:hover { color: #ffca28; }

/* ── Game controls ── */
.game-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid #333;
  border-radius: 6px;
  background: rgba(255,255,255,0.04);
  color: #aaa;
  cursor: pointer;
  transition: all 0.15s;
}
.ctrl-btn:hover {
  border-color: #FFC107;
  color: #FFC107;
  background: rgba(255,193,7,0.08);
}
.ctrl-btn svg { width: 14px; height: 14px; fill: currentColor; pointer-events: none; }

/* ── Stats row ── */
.stats {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.stat-item {
  font-size: 0.78rem;
  color: #999;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.stat-value {
  color: #FFC107;
  font-weight: 700;
  font-size: 0.9rem;
  min-width: 18px;
  text-align: center;
}

/* ── Progress bar ── */
#progress-bar-container {
  height: 3px;
  background: #1a1a1a;
  flex-shrink: 0;
  z-index: 10;
}

#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #66bb6a, #43a047);
  transition: width 0.4s ease;
}

/* ── Main game content area ── */
#game-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: radial-gradient(ellipse at 50% 0%, #131320 0%, #0a0a0a 80%);
}

/* ── Code block ── */
#code-section {
  width: 100%;
  max-width: 680px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #2a2a3a;
  background: #1a1a2e;
  animation: fadeSlideIn 0.35s ease-out;
}

#code-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: #16162a;
  border-bottom: 1px solid #2a2a3a;
}

.code-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.code-dot.red { background: #ff5f57; }
.code-dot.yellow { background: #ffbd2e; }
.code-dot.green { background: #28c840; }

.code-filename {
  font-size: 0.75rem;
  color: #666;
  margin-left: 6px;
  font-family: 'Fira Code', 'Consolas', monospace;
}

#code-block {
  padding: 18px 20px;
  overflow-x: auto;
  background: #1a1a2e;
  -webkit-overflow-scrolling: touch;
}

#code-display {
  font-family: 'Fira Code', 'Consolas', 'Courier New', monospace;
  font-size: 1.05rem;
  line-height: 1.8;
  white-space: pre;
  min-height: 1.8em;
  position: relative;
}

/* Character states */
.char {
  position: relative;
  display: inline-block;
  transition: color 0.1s;
  color: #666;
  border-bottom: 2px solid transparent;
}

.char.current {
  color: #f0f0f0;
  border-bottom-color: #FFC107;
  animation: cursorBlink 1s step-end infinite;
}

.char.correct {
  color: #4caf50;
  border-bottom-color: transparent;
}

.char.incorrect {
  color: #f44336;
  background: rgba(244, 67, 54, 0.15);
  border-radius: 2px;
  border-bottom-color: transparent;
  animation: charShake 0.3s ease-out;
}

@keyframes cursorBlink {
  0%, 100% { border-bottom-color: #FFC107; }
  50% { border-bottom-color: transparent; }
}

@keyframes charShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-2px); }
  40% { transform: translateX(2px); }
  60% { transform: translateX(-1px); }
  80% { transform: translateX(1px); }
}

/* ── Typing area ── */
#typing-area {
  width: 100%;
  max-width: 680px;
  animation: fadeSlideIn 0.35s ease-out;
}

#typing-prompt {
  font-size: 0.82rem;
  color: #777;
  margin-bottom: 8px;
  font-weight: 600;
}

#input-wrapper {
  position: relative;
  width: 100%;
  border-radius: 10px;
  border: 1.5px solid #2a2a3a;
  background: #141422;
  overflow: hidden;
  transition: border-color 0.2s;
}

#input-wrapper:focus-within {
  border-color: #FFC107;
  box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.1);
}

#typing-input {
  width: 100%;
  padding: 14px 16px;
  background: transparent;
  border: none;
  outline: none;
  color: #f0f0f0;
  font-family: 'Fira Code', 'Consolas', 'Courier New', monospace;
  font-size: 1rem;
  caret-color: #FFC107;
}

#typing-input::placeholder {
  color: #444;
}

/* ── Round feedback ── */
#round-feedback {
  width: 100%;
  max-width: 680px;
  padding: 14px 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.92rem;
  font-weight: 600;
  animation: fadeSlideIn 0.3s ease-out;
}

#round-feedback.hidden { display: none; }

#round-feedback.good {
  background: rgba(76, 175, 80, 0.1);
  border: 1px solid rgba(76, 175, 80, 0.3);
  color: #66bb6a;
}

#round-feedback.ok {
  background: rgba(255, 193, 7, 0.1);
  border: 1px solid rgba(255, 193, 7, 0.3);
  color: #FFC107;
}

#round-feedback.poor {
  background: rgba(244, 67, 54, 0.1);
  border: 1px solid rgba(244, 67, 54, 0.3);
  color: #ef5350;
}

/* ── Screen overlays ── */
.screen-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
  text-align: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.screen-overlay.hidden { display: none; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.screen-overlay:not(.hidden) > * {
  animation: fadeSlideIn 0.4s ease-out both;
}
.screen-overlay:not(.hidden) > *:nth-child(2) { animation-delay: 0.06s; }
.screen-overlay:not(.hidden) > *:nth-child(3) { animation-delay: 0.12s; }
.screen-overlay:not(.hidden) > *:nth-child(4) { animation-delay: 0.18s; }
.screen-overlay:not(.hidden) > *:nth-child(5) { animation-delay: 0.24s; }
.screen-overlay:not(.hidden) > *:nth-child(6) { animation-delay: 0.30s; }

.screen-title {
  font-size: 1.8rem;
  font-weight: 800;
  color: #FFC107;
  margin-bottom: 8px;
}

.screen-subtitle {
  font-size: 0.95rem;
  color: #aaa;
  margin-bottom: 28px;
  max-width: 460px;
  line-height: 1.6;
}

.screen-score {
  font-size: 2.8rem;
  font-weight: 800;
  color: #FFC107;
  margin-bottom: 4px;
}

.screen-score-label {
  font-size: 0.85rem;
  color: #888;
  margin-bottom: 22px;
}

.screen-stats {
  display: flex;
  gap: 24px;
  margin-bottom: 28px;
  flex-wrap: wrap;
  justify-content: center;
}

.screen-stat { text-align: center; }

.screen-stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
}

.screen-stat-label {
  font-size: 0.72rem;
  color: #777;
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Buttons ── */
.btn-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  padding: 12px 32px;
  font-size: 0.9rem;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-primary {
  background: #FFC107;
  color: #111;
}
.btn-primary:hover {
  background: #ffca28;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(255,193,7,0.3);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: transparent;
  color: #ccc;
  border: 1.5px solid #444;
}
.btn-secondary:hover {
  border-color: #FFC107;
  color: #FFC107;
}

/* ── Question slide-in transition ── */
#game-content.slide-in {
  animation: slideIn 0.35s ease-out;
}
@keyframes slideIn {
  from { opacity: 0.5; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Responsive ── */
@media (max-width: 700px) {
  #game-content { padding: 16px 12px; gap: 14px; }
  #code-display { font-size: 0.92rem; }
  #code-block { padding: 14px 14px; }
  #typing-input { font-size: 0.92rem; padding: 12px 14px; }
}

@media (max-width: 600px) {
  #top-bar { padding: 6px 10px; gap: 3px 6px; }
  .top-left { gap: 8px; }
  .brand { font-size: 0.78rem; }
  .ctrl-btn { width: 26px; height: 26px; }
  .ctrl-btn svg { width: 11px; height: 11px; }
  .game-controls { gap: 4px; }
  .stats { gap: 10px; }
  .stat-item { font-size: 0.68rem; }
  .stat-value { font-size: 0.75rem; min-width: 14px; }
  .screen-title { font-size: 1.35rem; }
  .screen-score { font-size: 2rem; }
  .screen-stats { gap: 16px; }
  .btn { padding: 10px 24px; font-size: 0.82rem; }
  #code-display { font-size: 0.82rem; }
  #typing-input { font-size: 0.85rem; }
}

@media (max-width: 380px) {
  .brand { font-size: 0.7rem; }
  .ctrl-btn { width: 24px; height: 24px; }
  .ctrl-btn svg { width: 10px; height: 10px; }
  .game-controls { gap: 3px; }
  .stats { gap: 8px; }
  .stat-item { font-size: 0.64rem; }
  .stat-value { font-size: 0.7rem; }
  #code-display { font-size: 0.76rem; }
}
