/* === Theme: Milano Cortina 2026 === */
:root {
  --color-snow: #F0F4F8;
  --color-ice-blue: #A8D5E2;
  --color-alpine-blue: #1B4965;
  --color-italian-red: #E63946;
  --color-deep-navy: #0B2545;
  --color-gold: #FFD700;
  --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font-main);
  background: var(--color-deep-navy);
  color: var(--color-snow);
  min-height: 100vh;
  overflow: hidden;
}

/* === Screens === */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* === Entry Screen === */
.entry-container {
  width: 100%;
  max-width: 480px;
  padding: 24px;
  max-height: 100vh;
  overflow-y: auto;
}

.title-block {
  text-align: center;
  margin-bottom: 32px;
}

.title-block h1 {
  font-size: 2.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--color-snow), var(--color-ice-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  font-size: 1.1rem;
  color: var(--color-ice-blue);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-top: 4px;
}

.olympic-rings {
  font-size: 2rem;
  margin-top: 8px;
}

.names-section h2 {
  font-size: 1.2rem;
  color: var(--color-ice-blue);
  margin-bottom: 4px;
}

.hint {
  font-size: 0.85rem;
  color: #8899aa;
  margin-bottom: 12px;
}

.name-inputs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  max-height: 50vh;
  overflow-y: auto;
  padding-right: 4px;
}

.name-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-num {
  width: 24px;
  text-align: right;
  font-size: 0.8rem;
  color: #667;
  flex-shrink: 0;
}

.name-input {
  flex: 1;
  padding: 10px 12px;
  border: 2px solid #2a3a50;
  border-radius: 8px;
  background: #0d1f35;
  color: var(--color-snow);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.name-input:focus {
  border-color: var(--color-ice-blue);
}

.name-input::placeholder {
  color: #556;
}

.btn-remove {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #667;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.btn-remove:hover {
  background: var(--color-italian-red);
  color: white;
}

/* === Buttons === */
.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--color-italian-red), #c0392b);
  color: white;
}

.btn-primary:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(230, 57, 70, 0.4);
}

.btn-secondary {
  background: #1a2d45;
  color: var(--color-ice-blue);
  border: 2px dashed #2a3d55;
}

.btn-secondary:hover {
  border-color: var(--color-ice-blue);
}

.btn-secondary:disabled {
  display: none;
}

/* === Race Screen === */
#screen-race {
  background: #0B2545;
}

#race-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* === Countdown === */
.countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 37, 69, 0.7);
  z-index: 10;
}

.countdown-overlay.hidden {
  display: none;
}

.countdown-text {
  font-size: 8rem;
  font-weight: 900;
  color: var(--color-gold);
  text-shadow: 0 0 40px rgba(255, 215, 0, 0.6);
  animation: countPulse 0.6s ease-out;
}

@keyframes countPulse {
  0% { transform: scale(1.8); opacity: 0; }
  50% { opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* === Celebration Screen === */
#screen-celebration {
  background: transparent;
}

.celebration-container {
  text-align: center;
  padding: 24px;
  width: 100%;
  max-width: 600px;
  max-height: 100vh;
  overflow-y: auto;
}

.trophy {
  font-size: 6rem;
  animation: trophyBounce 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
}

@keyframes trophyBounce {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.winner-name {
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--color-gold);
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
  margin: 16px 0 32px;
  min-height: 3.5rem;
}

/* Podium */
.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  margin: 24px 0;
}

.podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: podiumRise 0.5s ease-out forwards;
  opacity: 0;
}

.podium-place:nth-child(1) { animation-delay: 0.3s; }
.podium-place:nth-child(2) { animation-delay: 0.1s; }
.podium-place:nth-child(3) { animation-delay: 0.5s; }

@keyframes podiumRise {
  0% { transform: translateY(30px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

.podium-medal {
  font-size: 2rem;
}

.podium-name {
  font-size: 1rem;
  font-weight: 700;
  margin: 4px 0;
  color: var(--color-snow);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.podium-bar {
  width: 100px;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(180deg, var(--color-alpine-blue), #13344d);
  border: 2px solid var(--color-ice-blue);
  border-bottom: none;
}

.podium-bar.gold {
  height: 120px;
  background: linear-gradient(180deg, #ffd700, #b8860b);
  border-color: #ffd700;
}

.podium-bar.silver {
  height: 90px;
  background: linear-gradient(180deg, #c0c0c0, #808080);
  border-color: #c0c0c0;
}

.podium-bar.bronze {
  height: 65px;
  background: linear-gradient(180deg, #cd7f32, #8b4513);
  border-color: #cd7f32;
}

#btn-again {
  margin-top: 24px;
  max-width: 300px;
  margin-left: auto;
  margin-right: auto;
}

/* === Mode Selection === */
.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 24px;
}

.btn-play {
  background: linear-gradient(135deg, var(--color-alpine-blue), #13344d);
}

.btn-play:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(27, 73, 101, 0.4);
}

.btn-back {
  background: transparent;
  border: 2px solid #2a3d55;
  color: var(--color-ice-blue);
  margin-top: 16px;
}

.btn-back:hover {
  border-color: var(--color-ice-blue);
}

/* === Play Menu === */
.play-name-section {
  margin-bottom: 8px;
}

.input-label {
  display: block;
  font-size: 0.85rem;
  color: var(--color-ice-blue);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* === Join Screen === */
.join-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.room-code-input {
  text-align: center;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 12px;
  text-transform: uppercase;
  padding: 16px;
}

/* === Lobby === */
.lobby-players {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0;
  max-height: 50vh;
  overflow-y: auto;
}

.lobby-player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #0d1f35;
  border: 2px solid #2a3a50;
  border-radius: 8px;
}

.lobby-player.is-creator {
  border-color: var(--color-gold);
}

.lobby-avatar {
  font-size: 1.5rem;
}

.lobby-name {
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
}

.lobby-badge {
  font-size: 0.75rem;
  color: var(--color-gold);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* === Avatar Picker === */
.lobby-avatar.clickable {
  cursor: pointer;
  transition: transform 0.1s;
}
.lobby-avatar.clickable:hover {
  transform: scale(1.3);
}

.avatar-picker {
  z-index: 100;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 10px;
  background: #0d1f35;
  border: 2px solid var(--color-gold);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.avatar-option {
  font-size: 1.5rem;
  padding: 6px;
  cursor: pointer;
  border-radius: 4px;
  text-align: center;
  transition: transform 0.1s;
}
.avatar-option:hover {
  transform: scale(1.3);
  background: rgba(255,255,255,0.1);
}
.avatar-option.taken {
  opacity: 0.3;
  pointer-events: none;
}
.avatar-option.current {
  outline: 2px solid var(--color-gold);
  border-radius: 4px;
}

/* === Toggle Row === */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  margin-top: 12px;
  background: #0d1f35;
  border: 2px solid #2a3a50;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-italian-red);
  cursor: pointer;
}

.toggle-label {
  font-size: 0.95rem;
  color: var(--color-ice-blue);
}

/* === How to Play === */
.how-to-play-container {
  max-width: 600px;
  max-height: 100vh;
  overflow-y: auto;
  padding-bottom: 40px;
}

.how-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.how-card {
  background: #0d1f35;
  border: 2px solid #2a3a50;
  border-radius: 12px;
  padding: 20px;
  text-align: left;
}

.how-card-icon {
  font-size: 2rem;
  margin-bottom: 8px;
}

.how-card h3 {
  font-size: 1.2rem;
  color: var(--color-gold);
  margin-bottom: 8px;
}

.how-card p {
  font-size: 0.9rem;
  color: var(--color-ice-blue);
  line-height: 1.5;
  margin-bottom: 12px;
}

.how-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.how-list li {
  font-size: 0.85rem;
  color: var(--color-snow);
  padding-left: 20px;
  position: relative;
}

.how-list li::before {
  content: '⛷️';
  position: absolute;
  left: 0;
  font-size: 0.75rem;
}

.controls-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.control-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  padding: 6px 10px;
  background: var(--color-deep-navy);
  border: 2px solid #2a3a50;
  border-radius: 6px;
  font-size: 1.1rem;
  color: var(--color-snow);
  font-weight: 700;
}

.control-desc {
  font-size: 0.85rem;
  color: var(--color-ice-blue);
}

/* === Terms Footer === */
.terms-footer {
  text-align: center;
  margin-top: 24px;
}

.terms-footer a {
  font-size: 0.8rem;
  color: #667788;
  text-decoration: none;
  transition: color 0.2s;
}

.terms-footer a:hover {
  color: var(--color-ice-blue);
  text-decoration: underline;
}

.terms-footer .copyright {
  font-size: 0.7rem;
  color: #667788;
  margin-top: 8px;
}

/* === Terms & Conditions === */
.terms-container {
  max-width: 600px;
  max-height: 100vh;
  overflow-y: auto;
  padding-bottom: 40px;
}

.terms-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.terms-section {
  background: #0d1f35;
  border: 2px solid #2a3a50;
  border-radius: 12px;
  padding: 20px;
  text-align: left;
}

.terms-section h3 {
  font-size: 1.1rem;
  color: var(--color-gold);
  margin-bottom: 8px;
}

.terms-section p {
  font-size: 0.9rem;
  color: var(--color-ice-blue);
  line-height: 1.6;
}

.terms-section a {
  color: var(--color-gold);
  text-decoration: underline;
}

/* === Touch Drag Zone === */
.touch-drag-zone {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 20vh;
  background: rgba(11, 37, 69, 0.15);
  border-top: 1px solid rgba(100, 130, 160, 0.3);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 5;
  touch-action: none;
}

.touch-drag-hint {
  font-size: 0.85rem;
  color: rgba(200, 220, 240, 0.4);
  text-transform: uppercase;
  letter-spacing: 2px;
}

/* === Sound Toggle === */
.sound-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 100;
  background: rgba(11, 37, 69, 0.7);
  border: 1px solid rgba(168, 213, 226, 0.3);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  transition: background 0.2s, transform 0.15s;
  backdrop-filter: blur(8px);
}

.sound-toggle:hover {
  background: rgba(11, 37, 69, 0.9);
  transform: scale(1.1);
}

.sound-toggle:active {
  transform: scale(0.95);
}

.sound-toggle .sound-icon {
  line-height: 1;
}

/* === Responsive === */
@media (max-width: 600px) {
  .title-block h1 { font-size: 2rem; }
  .countdown-text { font-size: 5rem; }
  .winner-name { font-size: 1.8rem; margin: 8px 0 16px; }
  .trophy { font-size: 4rem; }
  .podium { margin: 12px 0; gap: 4px; }
  .podium-bar { width: min(70px, 28vw); }
  .podium-bar.gold { height: 80px; }
  .podium-bar.silver { height: 55px; }
  .podium-bar.bronze { height: 40px; }
  .podium-medal { font-size: 1.5rem; }
  .podium-name { font-size: 0.85rem; max-width: 80px; }
  #btn-again { margin-top: 12px; }
}
