* { box-sizing: border-box; }

:root {
  --bg: #2b1d14;
  --bg-track: #4a3323;
  --wood: #6b4a2f;
  --gold: #f2c14e;
  --green: #6bbf59;
  --red: #d9534f;
  --cream: #f5e9d8;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #4a3323, #201308);
  font-family: 'Trebuchet MS', 'Segoe UI', sans-serif;
  color: var(--cream);
}

.screen {
  width: 100%;
  max-width: 720px;
  padding: 32px 24px;
  text-align: center;
}

.hidden { display: none; }

h1 {
  font-size: 2.6rem;
  margin: 0 0 4px;
  text-shadow: 2px 2px 0 #000;
}

.subtitle {
  margin: 0 0 28px;
  opacity: 0.8;
}

.mode-select {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.mode-btn {
  background: var(--wood);
  border: 3px solid #3a2718;
  border-radius: 12px;
  color: var(--cream);
  padding: 18px 24px;
  min-width: 200px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 0.1s, background 0.15s;
}

.mode-btn:hover { transform: translateY(-2px); background: #7d5636; }

.mode-btn.selected {
  background: var(--gold);
  color: #3a2718;
  border-color: #a97e2b;
}

.mode-title { font-size: 1.3rem; font-weight: bold; }
.mode-detail { font-size: 0.9rem; opacity: 0.85; }

.rules {
  opacity: 0.75;
  margin-bottom: 24px;
}

button#start-btn, button#restart-btn {
  font-size: 1.15rem;
  padding: 14px 32px;
  border-radius: 30px;
  border: none;
  background: var(--green);
  color: #142a10;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}

button#start-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button#start-btn:not(:disabled):hover, button#restart-btn:hover {
  transform: translateY(-2px);
}

/* Game screen */
#game-screen { max-width: 820px; }

.hud {
  display: flex;
  justify-content: space-between;
  background: #1c110a;
  border-radius: 10px;
  padding: 10px 20px;
  margin-bottom: 16px;
}

.hud-item { display: flex; flex-direction: column; }
.hud-label { font-size: 0.7rem; text-transform: uppercase; opacity: 0.6; letter-spacing: 1px; }
.hud-value { font-size: 1.4rem; font-weight: bold; }

.track {
  background: var(--bg-track);
  border-radius: 10px;
  padding: 10px 0;
  margin-bottom: 20px;
  overflow: hidden;
  border: 3px solid #3a2718;
}

.lane {
  position: relative;
  height: 56px;
  border-bottom: 2px dashed rgba(255,255,255,0.08);
}

.lane:last-child { border-bottom: none; }

.lane-name {
  position: absolute;
  left: 6px;
  top: 4px;
  font-size: 0.7rem;
  opacity: 0.6;
  z-index: 2;
}

.finish-flag {
  position: absolute;
  right: 8px;
  top: 0;
  bottom: 0;
  width: 3px;
  background: repeating-linear-gradient(0deg, #fff, #fff 6px, #222 6px, #222 12px);
}

.runner {
  position: absolute;
  top: 18px;
  font-size: 1.8rem;
  transform: translateX(-50%);
  transition: left 0.35s ease-out;
  white-space: nowrap;
  z-index: 1;
}

.runner.player { filter: drop-shadow(0 0 4px var(--gold)); }

.problem-box {
  background: #1c110a;
  border-radius: 12px;
  padding: 28px 20px;
  text-align: center;
}

.problem-text {
  font-size: 3rem;
  font-weight: bold;
  margin-bottom: 16px;
  letter-spacing: 2px;
}

#answer-input {
  font-size: 2rem;
  width: 140px;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  border: 3px solid var(--wood);
  background: var(--cream);
  color: #201308;
}

#answer-input:focus { outline: none; border-color: var(--gold); }

.feedback {
  height: 28px;
  margin-top: 10px;
  font-weight: bold;
  font-size: 1.1rem;
}

.feedback.correct { color: var(--green); }
.feedback.wrong { color: var(--red); }

.problem-box.shake { animation: shake 0.3s; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.end-stats {
  background: #1c110a;
  border-radius: 12px;
  padding: 24px;
  margin: 20px auto;
  max-width: 440px;
  text-align: left;
  font-size: 1.05rem;
  line-height: 1.9;
}

.end-stats .row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding: 4px 0;
}

.end-stats .row:last-child { border-bottom: none; }

.end-stats .highlight { color: var(--gold); font-weight: bold; }
