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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #fff;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ---- Screens ---- */

.screen {
  display: none;
  height: 100%;
  width: 100%;
}

.screen.active {
  display: flex;
}

/* ---- Setup Screen ---- */

#setup-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.6rem, 2vh, 1.5rem);
  padding: 1.5rem 2rem;
}

.title-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 600px;
  position: relative;
}

.title-bar h1 {
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.title-bar .mute-btn {
  position: absolute;
  right: 0;
}

#setup-screen .subtitle {
  font-size: clamp(1rem, 3.5vw, 1.4rem);
  color: #aaa;
  margin: 0;
}

/* ---- Time Picker (Wheel) ---- */

.time-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(0.8rem, 2vh, 1.5rem);
  width: 100%;
  max-width: 600px;
}

.wheel-group {
  display: flex;
  align-items: flex-start;
  gap: clamp(1.5rem, 5vw, 3rem);
}

.wheel-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(0.3rem, 0.8vh, 0.6rem);
}

.wheel-container {
  position: relative;
  height: clamp(48px, 10vh, 90px);
  width: clamp(90px, 20vw, 160px);
  overflow: hidden;
  border-radius: 0.75rem;
  background: #16213e;
}

.wheel {
  height: 100%;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  touch-action: pan-y;
}

.wheel::-webkit-scrollbar {
  display: none;
}

.wheel-item {
  height: clamp(48px, 10vh, 90px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.5rem, 4vh, 3rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #fff;
  scroll-snap-align: center;
}

.wheel-highlight {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: clamp(48px, 10vh, 90px);
  transform: translateY(-50%);
  background: rgba(83, 52, 131, 0.3);
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  pointer-events: none;
  z-index: 2;
}

.wheel-label {
  font-size: clamp(0.9rem, 2vh, 1.3rem);
  color: #aaa;
  font-weight: 500;
}

/* ---- Mute Button ---- */

.mute-btn {
  background: transparent;
  border: 1px solid #555;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  transition: background 0.15s;
}

.mute-btn:hover {
  background: rgba(83, 52, 131, 0.3);
}

.mute-btn:active {
  background: #533483;
}

.mute-btn .icon-sound-off {
  display: none;
}

.mute-btn.muted .icon-sound-on {
  display: none;
}

.mute-btn.muted .icon-sound-off {
  display: block;
}

/* ---- Presets (single column under each wheel) ---- */

.presets-col {
  display: flex;
  flex-direction: column;
  gap: clamp(0.4rem, 1vh, 0.8rem);
  margin-top: clamp(0.5rem, 1vh, 1rem);
  width: 100%;
}

.preset-chip {
  font-size: clamp(0.95rem, 2.5vh, 1.4rem);
  font-weight: 600;
  padding: clamp(0.4rem, 1vh, 0.8rem) clamp(0.9rem, 3vw, 1.8rem);
  border: 1px solid #533483;
  border-radius: 2rem;
  background: transparent;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  text-align: center;
}

.preset-chip:hover {
  background: rgba(83, 52, 131, 0.3);
}

.preset-chip:active {
  transform: scale(0.95);
  background: #533483;
}

/* ---- Start Button ---- */

.start-btn {
  font-size: clamp(1.2rem, 4.5vw, 2rem);
  font-weight: 700;
  padding: clamp(0.7rem, 2vh, 1.2rem) 2rem;
  border: none;
  border-radius: 1rem;
  background: #1a4731;
  color: #fff;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
  width: 100%;
  max-width: 400px;
}

.start-btn:hover {
  background: #1e5a3a;
}

.start-btn:active {
  transform: scale(0.96);
  background: #247547;
}

/* ---- Game Screen ---- */

#game-screen {
  flex-direction: column;
  position: relative;
}

.player-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s;
  position: relative;
  -webkit-appearance: none;
  appearance: none;
  font-family: inherit;
}

/* Player 2 (top) is rotated 180° so it faces the opposite player */
.player-area.top {
  background: #0f3460;
  color: #fff;
  transform: rotate(180deg);
}

.player-area.bottom {
  background: #16213e;
  color: #fff;
}

.player-area.active-turn {
  animation: pulse-glow 1.2s ease-in-out infinite;
}

.player-area.top.active-turn {
  background: #1a5276;
}

.player-area.bottom.active-turn {
  background: #1a4731;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.85; }
}

.player-area.time-up {
  background: #8b0000 !important;
  animation: none;
}

.player-area:active:not(.paused):not(.time-up) {
  filter: brightness(1.2);
}

.timer {
  font-size: clamp(4rem, 20vw, 10rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1;
}

.player-label {
  font-size: clamp(1rem, 3.5vw, 1.6rem);
  opacity: 0.6;
  margin-top: 0.5rem;
  font-weight: 500;
}

/* ---- Controls Bar ---- */

#controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding: 0.6rem 1rem;
  background: #1a1a2e;
  z-index: 10;
  flex-shrink: 0;
}

.control-btn {
  font-size: clamp(1.4rem, 4vw, 2rem);
  padding: 0.6rem 1.6rem;
  border: 2px solid #555;
  border-radius: 0.75rem;
  background: transparent;
  color: #fff;
  cursor: pointer;
  min-width: 4rem;
  min-height: 3rem;
  transition: background 0.15s, border-color 0.15s;
}

.control-btn:hover {
  background: #333;
  border-color: #888;
}

.control-btn:active {
  background: #533483;
  border-color: #533483;
}

/* ---- Move Counter ---- */

.move-counter {
  font-size: clamp(1rem, 3vw, 1.3rem);
  font-weight: 600;
  color: #aaa;
  padding: 0 0.5rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---- Responsive tweaks ---- */

/* Compact setup for shorter viewports */
@media (max-height: 768px) {
  #setup-screen {
    padding: 1rem 1.5rem;
  }
  .title-bar h1 {
    font-size: clamp(1.8rem, 6vw, 2.5rem);
  }
  .mute-btn {
    width: 36px;
    height: 36px;
  }
  .mute-btn svg {
    width: 22px;
    height: 22px;
  }
}

@media (max-height: 600px) {
  #setup-screen {
    padding: 0.6rem 1rem;
  }
  .title-bar h1 {
    font-size: 1.6rem;
  }
  #setup-screen .subtitle {
    font-size: 0.95rem;
  }
}

@media (max-height: 500px) {
  .timer {
    font-size: clamp(2.5rem, 14vw, 5rem);
  }
  #controls {
    padding: 0.3rem 0.5rem;
  }
}

/* ---- Install Button ---- */

.install-btn {
  font-size: clamp(1rem, 3.5vw, 1.3rem);
  font-weight: 600;
  padding: 0.6rem 1.5rem;
  border: 2px solid #533483;
  border-radius: 0.75rem;
  background: #533483;
  color: #fff;
  cursor: pointer;
  margin-top: 0.5rem;
  transition: transform 0.1s, background 0.15s;
}

.install-btn:hover {
  background: #6a42a0;
}

.install-btn:active {
  transform: scale(0.96);
  background: #0f3460;
}

/* ---- Update Toast ---- */

.update-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #16213e;
  border: 1px solid #533483;
  border-radius: 0.75rem;
  padding: 0.8rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  animation: slide-up 0.3s ease-out;
}

.update-toast[hidden] {
  display: none;
}

.update-toast span {
  font-size: clamp(0.9rem, 3vw, 1.1rem);
  color: #fff;
}

.update-toast button {
  font-size: clamp(0.9rem, 3vw, 1.1rem);
  font-weight: 600;
  padding: 0.4rem 1rem;
  border: none;
  border-radius: 0.5rem;
  background: #533483;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.update-toast button:hover {
  background: #6a42a0;
}

@keyframes slide-up {
  from { transform: translateX(-50%) translateY(100%); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* Landscape: side-by-side layout */
@media (orientation: landscape) and (max-height: 500px) {
  #game-screen {
    flex-direction: row;
  }

  .player-area.top {
    transform: none;
  }

  #controls {
    flex-direction: column;
    padding: 0.5rem;
    gap: 1rem;
  }
}
