body { overflow: hidden; }

/* ---------- Screens ---------- */
.screen { display: none; width: 100%; max-width: 500px; padding: 20px; text-align: center; }
.screen.active { display: flex; flex-direction: column; align-items: center; }

/* ---------- Menu ---------- */
#menu h1 { font-size: 2rem; margin-bottom: 8px; }
#menu p { opacity: .8; margin-bottom: 24px; }

.table-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 320px;
  margin-bottom: 24px;
}

.table-btn {
  background: rgba(255,255,255,.15);
  border: 2px solid rgba(255,255,255,.3);
  border-radius: 12px;
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  padding: 14px 0;
  cursor: pointer;
  transition: .2s;
}
.table-btn:hover { background: rgba(255,255,255,.3); transform: scale(1.08); }
.table-btn.selected { background: #fff; color: #764ba2; border-color: #fff; }

.start-btn {
  background: #fff;
  color: #764ba2;
  border: none;
  border-radius: 50px;
  padding: 14px 48px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: .2s;
  opacity: .4;
  pointer-events: none;
}
.start-btn.ready { opacity: 1; pointer-events: auto; }
.start-btn.ready:hover { transform: scale(1.05); box-shadow: 0 4px 20px rgba(0,0,0,.25); }

/* ---------- Game ---------- */
#game { height: 100vh; max-width: 100%; padding: 0; justify-content: space-between; }

.game-header {
  width: 100%;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.1rem;
  z-index: 10;
}
.game-header .timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.3rem; }
.game-header .counter { opacity: .85; }

/* ---------- Falling calculations ---------- */
.calc-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  width: 100%;
  overflow: hidden;
}

.calc-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform .25s cubic-bezier(.4, 0, .2, 1);
  padding-top: 20px;
}

.calc-item {
  padding: 10px 0;
  font-weight: 800;
  text-shadow: 0 2px 10px rgba(0,0,0,.15);
  transition: all .2s ease;
  white-space: nowrap;
}
.calc-item.done {
  font-size: 1.4rem;
  opacity: .2;
  color: #6bff8e;
}
.calc-item.current {
  font-size: 3.2rem;
  opacity: 1;
  padding: 16px 0;
}
.calc-item.current.correct-flash {
  color: #6bff8e;
  animation: popCorrect .4s ease;
}
.calc-item.current.wrong-flash {
  animation: shake .4s ease;
}
.calc-item.upcoming {
  font-size: 1.8rem;
  opacity: .35;
}
.calc-item.upcoming:nth-child(n+2) {
  opacity: .2;
}
.calc-item.far {
  font-size: 1.3rem;
  opacity: .1;
}

@keyframes popCorrect {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-12px); }
  75% { transform: translateX(12px); }
}

/* ---------- Bottom area ---------- */
.bottom-area {
  width: 100%;
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.heard-answer {
  font-size: 1.6rem;
  font-weight: 700;
  min-height: 40px;
  color: rgba(255,255,255,.9);
}

.keyboard-input {
  background: rgba(255,255,255,.15);
  border: 2px solid rgba(255,255,255,.3);
  border-radius: 12px;
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  padding: 10px 20px;
  width: 160px;
  outline: none;
  transition: .2s;
  -moz-appearance: textfield;
}
.keyboard-input::-webkit-outer-spin-button,
.keyboard-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.keyboard-input:focus { border-color: rgba(255,255,255,.7); background: rgba(255,255,255,.25); }
.keyboard-input::placeholder { color: rgba(255,255,255,.4); font-weight: 400; font-size: 1rem; }

.mic-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .9rem;
  opacity: .8;
}
.mic-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #f44;
  animation: pulse 1s infinite;
}
.mic-dot.off { background: #888; animation: none; }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(1.3); }
}

/* ---------- Track ---------- */
.track-area { width: 100%; margin-top: 8px; }

.track {
  position: relative;
  width: 100%;
  height: 48px;
  background: rgba(255,255,255,.12);
  border-radius: 24px;
  overflow: hidden;
}

.track-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, #6bff8e, #00d4aa);
  border-radius: 24px;
  transition: width .3s ease;
}

.avatar {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  font-size: 2rem;
  transition: left .3s ease;
  z-index: 2;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.3));
}

.avatar.opponent {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.3)) grayscale(.3);
  opacity: .8;
}

.finish-flag {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.4rem;
  z-index: 2;
}

/* ---------- Round transition ---------- */
#roundTransition {
  justify-content: center;
  gap: 16px;
}
.round-medal { font-size: 4rem; }
.round-message { font-size: 1.6rem; font-weight: 700; }
.round-time { font-size: 1.2rem; opacity: .85; }
.round-next { font-size: 1rem; opacity: .6; margin-top: 12px; }

/* ---------- Results ---------- */
#results h2 { font-size: 2rem; margin-bottom: 8px; }
#results .final-time { font-size: 3rem; font-weight: 800; margin: 16px 0; }
#results .stats { opacity: .85; margin-bottom: 24px; line-height: 1.8; font-size: 1.1rem; }

.medals-earned {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 2.5rem;
}
.medal-slot { opacity: .2; }
.medal-slot.won { opacity: 1; }

.replay-btn {
  background: #fff;
  color: #764ba2;
  border: none;
  border-radius: 50px;
  padding: 14px 48px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: .2s;
}
.replay-btn:hover { transform: scale(1.05); }

/* ---------- Speech not supported ---------- */
.no-speech {
  background: rgba(255,0,0,.2);
  border: 1px solid rgba(255,0,0,.4);
  border-radius: 12px;
  padding: 16px;
  margin-top: 20px;
  max-width: 400px;
}
