:root {
  --bg-primary: #0a0c16;
  --bg-card: #121626;
  --bg-card-hover: #181d32;
  --text-primary: #f0f4fc;
  --text-muted: #828ca0;
  --accent-cyan: #00e5ff;
  --accent-magenta: #ff007f;
  --accent-yellow: #ffd600;
  --accent-purple: #7928ca;
  --accent-green: #00e676;
  --accent-red: #ff1744;
  --border-color: rgba(255, 255, 255, 0.1);
  --border-glow: rgba(0, 229, 255, 0.4);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Monaco", "Inconsolata", "Fira Mono", "Droid Sans Mono", monospace;
}

html, body {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(circle at 50% 0%, rgba(0, 229, 255, 0.08) 0%, transparent 70%),
    radial-gradient(circle at 100% 100%, rgba(121, 40, 202, 0.08) 0%, transparent 60%);
  color: var(--text-primary);
  font-family: var(--font-family);
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* App Header */
.app-header {
  width: 100%;
  max-width: 900px;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-icon {
  font-size: 1.5rem;
  filter: drop-shadow(0 0 8px var(--accent-cyan));
}

.logo-title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 2px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-magenta));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-actions {
  display: flex;
  gap: 0.75rem;
}

.icon-btn {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-cyan);
}

.icon-btn.muted {
  color: var(--text-muted);
}

/* Main Container & Screens */
.main-content {
  flex: 1;
  width: 100%;
  max-width: 960px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
}

.screen {
  display: none;
  width: 100%;
  flex-direction: column;
  align-items: center;
  animation: fadeIn 0.25s ease forwards;
}

.screen.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Menu Screen */
.menu-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  max-width: 460px;
  width: 100%;
  text-align: center;
}

.menu-title {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.menu-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 2rem;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.menu-btn {
  display: flex;
  align-items: center;
  padding: 1.2rem 1.5rem;
  border-radius: 12px;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  text-align: left;
}

.menu-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 229, 255, 0.15);
}

.menu-btn.primary:hover {
  border-color: var(--accent-cyan);
}

.menu-btn.secondary:hover {
  border-color: var(--accent-magenta);
}

.btn-icon {
  font-size: 2rem;
  margin-right: 1.2rem;
}

.btn-text h3 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.btn-text p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Lobby Screen */
.lobby-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 2rem;
  max-width: 500px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.lobby-title {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 1.5rem;
  color: var(--accent-magenta);
}

.lobby-section {
  display: none;
  flex-direction: column;
  gap: 1.2rem;
}

.lobby-section.active {
  display: flex;
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.host-box {
  background: rgba(0, 229, 255, 0.05);
  border: 1px dashed var(--accent-cyan);
  padding: 1.2rem;
  border-radius: 10px;
}

.join-box {
  background: rgba(255, 0, 127, 0.05);
  border: 1px dashed var(--accent-magenta);
  padding: 1.2rem;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.input-code {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1.4rem;
  letter-spacing: 4px;
  text-align: center;
  text-transform: uppercase;
  padding: 0.8rem;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s;
}

.input-code:focus {
  border-color: var(--accent-magenta);
  box-shadow: 0 0 10px rgba(255, 0, 127, 0.3);
}

.action-btn {
  background: linear-gradient(135deg, var(--accent-cyan), #0099ff);
  border: none;
  color: #000;
  font-weight: 700;
  font-size: 1rem;
  padding: 0.85rem 1.5rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
  box-shadow: 0 4px 15px rgba(0, 229, 255, 0.3);
}

.action-btn.secondary {
  background: linear-gradient(135deg, var(--accent-magenta), #cc0066);
  color: #fff;
}

.action-btn.secondary:hover {
  box-shadow: 0 4px 15px rgba(255, 0, 127, 0.3);
}

/* Waiting / Room Code Display */
.code-display-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-primary);
  padding: 1.2rem;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.code-display-box label {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.room-code-badge {
  font-family: var(--font-mono);
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--accent-yellow);
  letter-spacing: 6px;
  filter: drop-shadow(0 0 8px rgba(255, 214, 0, 0.4));
}

.code-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  background: #fff;
  padding: 0.8rem;
  border-radius: 12px;
  width: fit-content;
  margin: 0.5rem auto;
}

.network-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  word-break: break-all;
}

.pulse-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--accent-cyan);
  font-weight: 600;
  font-size: 0.95rem;
  margin-top: 0.5rem;
}

.dot-pulse {
  width: 8px;
  height: 8px;
  background-color: var(--accent-cyan);
  border-radius: 50%;
  animation: pulseAnimation 1.2s infinite ease-in-out;
}

@keyframes pulseAnimation {
  0%, 100% { transform: scale(0.6); opacity: 0.4; }
  50% { transform: scale(1.2); opacity: 1; filter: drop-shadow(0 0 6px var(--accent-cyan)); }
}

/* Solo Screen Layout */
.game-container {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  justify-content: center;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 110px;
}

.panel-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.6rem;
  text-align: center;
}

.panel-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.4rem;
}

.panel-value {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.board-wrapper {
  position: relative;
  background: #06070c;
  border: 2px solid rgba(0, 229, 255, 0.4);
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.15);
  border-radius: 8px;
  overflow: hidden;
}

/* Battle Arena Layout */
.battle-arena {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  justify-content: center;
  position: relative;
}

.match-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 760px;
  padding: 0.5rem 1rem;
  margin-bottom: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

.match-score-text {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--accent-yellow);
  letter-spacing: 2px;
}

.ping-indicator {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--accent-green);
}

.player-station {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.station-label {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.station-label.player {
  color: var(--accent-cyan);
}

.station-label.opponent {
  color: var(--accent-magenta);
}

.battle-board-group {
  display: flex;
  gap: 0.8rem;
  align-items: flex-start;
}

.garbage-meter-track {
  width: 8px;
  height: 520px;
  background: rgba(255, 23, 68, 0.15);
  border: 1px solid rgba(255, 23, 68, 0.3);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
}

.garbage-meter-fill {
  width: 100%;
  height: 0%;
  background: linear-gradient(to top, var(--accent-red), #ff7961);
  box-shadow: 0 0 10px var(--accent-red);
  transition: height 0.15s ease-out;
}

.opponent-board-wrapper {
  background: #06070c;
  border: 2px solid rgba(255, 0, 127, 0.4);
  box-shadow: 0 0 20px rgba(255, 0, 127, 0.15);
  border-radius: 8px;
  overflow: hidden;
}

/* Countdown Overlay */
.countdown-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.countdown-overlay.active {
  display: flex;
}

.countdown-num {
  font-family: var(--font-mono);
  font-size: 7rem;
  font-weight: 900;
  color: var(--accent-yellow);
  text-shadow: 0 0 30px rgba(255, 214, 0, 0.8);
}

.countdown-num.go {
  color: var(--accent-green);
  text-shadow: 0 0 30px rgba(0, 230, 118, 0.8);
}

.pulse {
  animation: numPulse 0.8s ease-out forwards;
}

@keyframes numPulse {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* Game Over / Victory Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 110;
}

.modal-backdrop.active {
  display: flex;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
  border-radius: 16px;
  padding: 2rem;
  max-width: 400px;
  width: 90%;
  text-align: center;
}

.victory-text {
  color: var(--accent-yellow);
  font-size: 2.2rem;
  font-weight: 900;
  filter: drop-shadow(0 0 12px rgba(255, 214, 0, 0.5));
}

.defeat-text {
  color: var(--accent-red);
  font-size: 2.2rem;
  font-weight: 900;
  filter: drop-shadow(0 0 12px rgba(255, 23, 68, 0.5));
}

.modal-stats {
  margin: 1.5rem 0;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.rematch-alert {
  color: var(--accent-green);
  font-weight: 700;
  font-size: 0.95rem;
  margin-top: 0.5rem;
  animation: pulseAnimation 1s infinite;
}

/* Opponent View Panel (Outside Play Window) */
.opponent-view-panel {
  background: var(--bg-card);
  border: 1.5px solid rgba(255, 0, 127, 0.45);
  box-shadow: 0 0 14px rgba(255, 0, 127, 0.15);
  border-radius: 8px;
  padding: 0.45rem 0.35rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.opponent-title {
  color: var(--accent-magenta) !important;
  font-weight: 800;
  letter-spacing: 1px;
}

.opponent-stats-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0 2px;
  font-size: 0.7rem;
  margin-bottom: 2px;
}

.opponent-score-label {
  color: var(--text-muted);
  font-size: 0.6rem;
  font-weight: 700;
}

.pip-score {
  color: var(--accent-yellow);
  font-family: var(--font-mono);
  font-weight: 800;
}

.opponent-board-wrapper {
  background: #06070c;
  border: 1.5px solid rgba(255, 0, 127, 0.4);
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8), 0 0 10px rgba(255, 0, 127, 0.2);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Hold Box Interaction */
.panel-box.hold-box {
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.panel-box.hold-box:hover {
  border-color: var(--accent-purple);
  box-shadow: 0 0 12px rgba(121, 40, 202, 0.35);
}

.panel-box.hold-box:active {
  transform: scale(0.94);
  border-color: var(--accent-purple);
  background: rgba(121, 40, 202, 0.25);
  box-shadow: 0 0 16px rgba(121, 40, 202, 0.6);
}

.hold-hint {
  font-size: 0.6rem;
  color: #c084fc;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* Floating Mobile Touch Controls Overlay */
.touch-overlay {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  top: 0;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 12px max(14px, env(safe-area-inset-bottom)) 12px;
  pointer-events: none;
  z-index: 60;
}

.touch-overlay.active {
  display: flex;
}

.touch-cluster {
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

.touch-left {
  align-items: flex-start;
}

.touch-right {
  align-items: flex-end;
}

.touch-btn {
  width: clamp(68px, 18vw, 84px);
  height: clamp(58px, 8.5vh, 74px);
  background: rgba(18, 22, 38, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  transition: transform 0.08s ease, background-color 0.08s ease, border-color 0.08s ease, box-shadow 0.08s ease;
  position: relative;
  overflow: hidden;
}

.touch-btn-icon {
  font-size: 1.65rem;
  line-height: 1;
  pointer-events: none;
}

.touch-btn-text {
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.8px;
  margin-top: 3px;
  pointer-events: none;
  text-transform: uppercase;
}

/* Button Variants */
/* 1. Left & Right Directional Buttons */
.touch-btn.touch-btn-dir {
  background: rgba(0, 229, 255, 0.12);
  border-color: rgba(0, 229, 255, 0.45);
  color: var(--accent-cyan);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5), 0 0 12px rgba(0, 229, 255, 0.2);
}
.touch-btn.touch-btn-dir:active {
  background: var(--accent-cyan);
  color: #000;
  border-color: #fff;
  transform: scale(0.92);
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.8);
}

/* 2. Rotate Buttons (Above Left & Right) */
.touch-btn.touch-btn-rotate {
  background: rgba(255, 0, 127, 0.12);
  border-color: rgba(255, 0, 127, 0.45);
  color: var(--accent-magenta);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5), 0 0 12px rgba(255, 0, 127, 0.2);
}
.touch-btn.touch-btn-rotate:active {
  background: var(--accent-magenta);
  color: #fff;
  border-color: #fff;
  transform: scale(0.92);
  box-shadow: 0 0 20px rgba(255, 0, 127, 0.8);
}

/* 3. Drop Buttons (Beneath Left & Right) */
.touch-btn.drop-soft {
  background: rgba(0, 230, 118, 0.12);
  border-color: rgba(0, 230, 118, 0.45);
  color: var(--accent-green);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5), 0 0 12px rgba(0, 230, 118, 0.2);
}
.touch-btn.drop-soft:active {
  background: var(--accent-green);
  color: #000;
  border-color: #fff;
  transform: scale(0.92);
  box-shadow: 0 0 20px rgba(0, 230, 118, 0.8);
}

.touch-btn.drop-hard {
  background: rgba(255, 214, 0, 0.16);
  border-color: rgba(255, 214, 0, 0.55);
  color: var(--accent-yellow);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5), 0 0 14px rgba(255, 214, 0, 0.3);
}
.touch-btn.drop-hard:active {
  background: var(--accent-yellow);
  color: #000;
  border-color: #fff;
  transform: scale(0.92);
  box-shadow: 0 0 24px rgba(255, 214, 0, 0.9);
}

/* Toast Notification Styles */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: 90%;
  max-width: 380px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--accent-cyan);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  animation: toastSlideDown 0.25s ease-out forwards;
  text-align: center;
  pointer-events: auto;
}

.toast.error {
  border-color: var(--accent-red);
  color: #ff80ab;
}

@keyframes toastSlideDown {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Responsive Media Queries */
@media (max-width: 800px), (pointer: coarse) {
  .touch-overlay.active {
    display: flex;
  }

  .main-content {
    padding: 0.25rem;
  }

  .app-header {
    padding: 0.4rem 0.8rem;
  }

  .logo-title {
    font-size: 1.2rem;
  }

  .game-container, .battle-arena {
    gap: 0.5rem;
  }

  .board-wrapper canvas {
    max-height: 65vh;
    width: auto !important;
    height: auto !important;
  }

  .garbage-meter-track {
    height: 100%;
    max-height: 520px;
  }
}

@media (max-width: 600px) {
  .app-header {
    padding: 0.25rem 0.6rem;
  }
  .logo-title {
    font-size: 1.1rem;
    letter-spacing: 1px;
  }
  .icon-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
  }

  .game-container, .battle-board-group {
    gap: 4px !important;
    align-items: center;
  }

  .side-panel {
    width: 58px !important;
    gap: 4px !important;
  }

  .panel-box {
    padding: 3px !important;
    border-radius: 6px;
  }

  .panel-title {
    font-size: 0.6rem !important;
    margin-bottom: 2px !important;
  }

  .panel-value {
    font-size: 0.95rem !important;
  }

  #solo-board, #player-board {
    width: 220px !important;
    height: 440px !important;
  }

  #solo-hold, #player-hold {
    width: 52px !important;
    height: 52px !important;
  }

  #solo-next, #player-next {
    width: 52px !important;
    height: 156px !important;
  }

  .battle-side-panel-right {
    width: 58px !important;
    gap: 4px !important;
  }

  .opponent-view-panel {
    padding: 3px 2px !important;
    border-radius: 6px !important;
    gap: 1px !important;
  }

  #opponent-board {
    width: 52px !important;
    height: 104px !important;
  }

  .touch-overlay {
    padding: 0 8px max(12px, env(safe-area-inset-bottom)) 8px;
  }

  .touch-cluster {
    gap: 8px;
  }

  .touch-btn {
    width: clamp(66px, 18vw, 76px);
    height: clamp(54px, 7.8vh, 66px);
    border-radius: 12px;
  }

  .touch-btn-icon {
    font-size: 1.45rem;
  }

  .touch-btn-text {
    font-size: 0.52rem;
    letter-spacing: 0.6px;
  }
}

