/* CSS Variables */
:root {
  --color-red: #FF0000;
  --color-blue: #0000FF;
  --color-yellow: #FFFF00;
  --color-green: #00FF00;
  --color-white: #FFFFFF;
  --color-black: #222222;
  --color-bg: #0a0a12;
  --color-surface: #12121f;
  --color-surface-alt: #1a1a2a;
  --color-text: #f0f0f0;
  --color-text-dim: #777;
  --color-accent: #1a1a3a;
  --color-border: #2a2a4a;
}

/* Reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  background-image:
    radial-gradient(ellipse at top left, rgba(255, 0, 0, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at top right, rgba(0, 0, 255, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at bottom left, rgba(0, 255, 0, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(255, 255, 0, 0.08) 0%, transparent 50%);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  height: 100%;
  width: 100%;
}

/* Screens */
.screen {
  display: none;
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.active {
  display: flex;
}

/* Home Screen */
.home-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 20px;
  gap: 40px;
}

.home-container h1 {
  font-size: 2.5rem;
  text-align: center;
  line-height: 1.2;
}

.home-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 300px;
}

/* Buttons */
.btn {
  padding: 16px 32px;
  font-size: 1.1rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-primary {
  background: var(--color-blue);
  color: white;
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-accent);
}

.btn-small {
  padding: 8px 16px;
  font-size: 0.9rem;
}

.btn-large {
  padding: 20px 40px;
  font-size: 1.2rem;
}

/* Setup/Create Screen */
.setup-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 20px;
  gap: 20px;
  overflow-y: auto;
}

.setup-container h2 {
  text-align: center;
  font-size: 1.5rem;
  margin-bottom: 10px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 0.9rem;
  color: var(--color-text-dim);
}

/* Color Picker */
.color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-btn {
  flex: 1;
  min-width: 70px;
  padding: 12px 8px;
  font-size: 0.9rem;
  font-weight: 600;
  border: 3px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  color: white;
  transition: border-color 0.2s, transform 0.1s;
}

.color-btn.selected {
  border-color: white;
  transform: scale(1.05);
}

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

/* Select */
.select, .input {
  width: 100%;
  padding: 12px 16px;
  font-size: 1rem;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-accent);
  border-radius: 8px;
}

/* Turn Order */
.turn-order {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.turn-slot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--color-surface);
  border-radius: 8px;
}

.turn-number {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent);
  border-radius: 50%;
  font-weight: bold;
  font-size: 0.9rem;
}

.turn-color {
  flex: 1;
  font-weight: 500;
}

.turn-select {
  flex: 1;
  padding: 8px;
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-accent);
  border-radius: 6px;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: auto;
  padding-top: 20px;
}

.form-actions .btn {
  flex: 1;
}

/* Lobby Screen */
.lobby-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 20px;
  gap: 20px;
  align-items: center;
  overflow-y: auto;
}

.lobby-container h2 {
  font-size: 1.5rem;
}

.qr-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.qr-code {
  width: 200px;
  height: 200px;
  background: white;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

.qr-code img {
  width: 100%;
  height: 100%;
}

.join-url {
  font-size: 0.85rem;
  color: var(--color-text-dim);
  word-break: break-all;
  text-align: center;
}

.players-list {
  width: 100%;
  max-width: 350px;
}

.players-list h3 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--color-text-dim);
}

.lobby-players {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lobby-player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--color-surface);
  border-radius: 8px;
}

.player-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.player-name {
  flex: 1;
  font-weight: 500;
}

.player-status {
  font-size: 0.85rem;
  color: var(--color-text-dim);
}

.player-status.connected {
  color: var(--color-green);
}

.lobby-info {
  text-align: center;
  font-size: 0.9rem;
  color: var(--color-text-dim);
}

.lobby-info p {
  margin: 4px 0;
}

/* Game Screen */
.game-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: relative;
}

/* Other players section (top 20%) */
.other-players {
  height: 20%;
  display: flex;
  gap: 4px;
  padding: 8px;
}

.other-player {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  border-radius: 12px;
  padding: 8px;
  transition: all 0.3s;
  border: 3px solid transparent;
}

.other-player.active {
  border-color: white;
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

.other-player-color {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.other-player-time {
  font-size: 1.5rem;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}

.other-player.low-time .other-player-time {
  color: var(--color-red);
}

/* Main clock button (bottom 80%) */
.main-clock {
  height: 80%;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.main-clock.my-turn {
  background: var(--color-green);
}

.main-clock.my-turn .clock-label {
  color: rgba(255, 255, 255, 0.9);
}

.main-clock.waiting {
  background: var(--color-surface);
  cursor: default;
}

.main-clock.paused {
  background: var(--color-accent);
}

.main-clock.low-time {
  background: var(--color-red);
}

.main-clock:active.my-turn {
  transform: scale(0.99);
  opacity: 0.9;
}

.clock-time {
  font-size: 5rem;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.clock-label {
  font-size: 1rem;
  color: var(--color-text-dim);
  margin-top: 12px;
}

/* Pause button */
.btn-pause {
  position: absolute;
  top: 22%;
  right: 12px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-accent);
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 10;
}

.btn-pause:active {
  transform: scale(0.95);
}

/* Game Over Screen */
.gameover-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 20px;
  gap: 24px;
  text-align: center;
}

.gameover-container h2 {
  font-size: 2rem;
  color: var(--color-red);
}

/* Color-specific backgrounds */
.main-clock[data-color="red"].my-turn,
.other-player[data-active-color="red"].active {
  background: var(--color-red);
}

.main-clock[data-color="blue"].my-turn,
.other-player[data-active-color="blue"].active {
  background: var(--color-blue);
}

.main-clock[data-color="yellow"].my-turn,
.other-player[data-active-color="yellow"].active {
  background: var(--color-yellow);
  color: #000;
}

.main-clock[data-color="yellow"].my-turn .clock-label {
  color: rgba(0, 0, 0, 0.7);
}

.main-clock[data-color="green"].my-turn,
.other-player[data-active-color="green"].active {
  background: var(--color-green);
}

/* Utility */
.hidden {
  display: none !important;
}

/* Animations */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.main-clock.my-turn {
  animation: pulse 1.5s ease-in-out infinite;
}

.main-clock.my-turn:active {
  animation: none;
}

/* Responsive adjustments */
@media (min-width: 600px) {
  .clock-time {
    font-size: 8rem;
  }

  .other-player-time {
    font-size: 2rem;
  }

  .home-container h1 {
    font-size: 3.5rem;
  }
}

@media (min-height: 800px) {
  .clock-time {
    font-size: 7rem;
  }
}

/* Safe area for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
  .game-container {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* White/Black colors for 2-player mode */
.main-clock[data-color="white"].my-turn,
.other-player[data-active-color="white"].active {
  background: var(--color-white);
  color: #000;
}

.main-clock[data-color="white"].my-turn .clock-label {
  color: rgba(0, 0, 0, 0.7);
}

.main-clock[data-color="black"].my-turn,
.other-player[data-active-color="black"].active {
  background: var(--color-black);
}

/* Eliminated player styles */
.other-player.eliminated {
  opacity: 0.4;
  border-color: transparent !important;
  box-shadow: none !important;
}

.other-player.eliminated .other-player-time {
  text-decoration: line-through;
  color: var(--color-text-dim);
}

.main-clock.eliminated {
  background: #330000 !important;
  animation: none !important;
}

.main-clock.eliminated .clock-time {
  color: var(--color-red);
  opacity: 0.6;
}

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--color-surface-alt);
  color: var(--color-text);
  padding: 12px 24px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  font-weight: 500;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* 2-player mode adjustments */
.other-players.two-player {
  justify-content: center;
}

.other-players.two-player .other-player[data-color="across"] {
  flex: 0 0 60%;
  max-width: 300px;
}

/* Surface borders for better definition */
.other-player,
.lobby-player,
.turn-slot {
  border: 1px solid var(--color-border);
}

/* Brighter button borders */
.btn-secondary {
  border: 1px solid var(--color-border);
}

.select, .input {
  border: 1px solid var(--color-border);
}

/* Color picker adjustments for visibility */
.color-btn[data-color="blue"] {
  background: linear-gradient(135deg, #0000FF 0%, #3333FF 100%) !important;
}

.color-btn[data-color="green"] {
  background: linear-gradient(135deg, #00CC00 0%, #00FF00 100%) !important;
}
