/* ============================================
   BASE STYLES
   ============================================ */

body {
  font-family: system-ui, sans-serif;
  background: #240046;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  margin: 0;
  padding-top: 40px;
  padding-bottom: 40px;
}

.container {
  text-align: center;
  background: #e0aaff;
  border-radius: 16px;
  padding: 30px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  max-width: 500px;
}

/* ============================================
   HEADER & LOGO
   ============================================ */
.header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-bottom: 15px;
}

.logo-placeholder {
  width: 60px;
  height: 60px;
  background: #9d4edd;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.logo-placeholder img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

.header h1 {
  margin: 0;
  font-size: 2.5em;
  color: #240046;
}

.challenge-instruction {
  margin: 0 0 20px 0;
  font-size: 0.95em;
  color: #333;
  font-weight: 500;
}

/* ============================================
   SETTINGS & CONTROLS
   ============================================ */

.settings-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.setting-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.setting-group label {
  font-weight: 500;
  white-space: nowrap;
  color: #333;
}

.lockout-toggle {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 12px;
  padding: 10px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.lockout-toggle label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-weight: 500;
  color: #333;
  user-select: none;
}

.lockout-toggle input[type="radio"] {
  width: auto;
  margin: 0;
  cursor: pointer;
  accent-color: #9d4edd;
}

.lockout-toggle input[type="radio"]:disabled + span,
.setting-group select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================
   CHALLENGE TOOLTIP
   ============================================ */

.challenge-tooltip {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  max-width: 280px;
  animation: tooltipFadeIn 0.2s ease-out;
}

.tooltip-content {
  background: rgba(36, 0, 70, 0.95);
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border: 2px solid #9d4edd;
}

.tooltip-content h4 {
  margin: 0 0 8px 0;
  font-size: 1em;
  color: #e0aaff;
  font-weight: bold;
}

.tooltip-content p {
  margin: 0;
  font-size: 0.9em;
  line-height: 1.4;
}

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

.tooltip-hint {
  font-style: italic;
  color: #666;
  margin-top: 10px;
  font-size: 0.9em;
}

/* ============================================
   FORM ELEMENTS
   ============================================ */

.input-section {
  margin-bottom: 20px;
}

input {
  padding: 8px;
  width: 80%;
  margin-top: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
}

input:focus {
  border-color: #9d4edd;
}

.mode-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

select {
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background-color: white;
  cursor: pointer;
}

select:focus {
  border-color: #9d4edd;
  outline: none;
}

button {
  margin-top: 10px;
  margin-right: 5px;
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background-color: #9d4edd;
  color: white;
  transition: background 0.2s;
  display: inline-block;
  vertical-align: middle;
}

button:hover {
  background-color: #7b2cbf;
}

#exchangeBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================
   GAME BOARD
   ============================================ */

.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  margin-top: 15px;
}

.cell {
  background: white;
  padding: 8px;
  border-radius: 6px;
  font-weight: bold;
  border: 1px solid #ccc;
  color: black;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s ease, transform 0.1s ease;
  /* enforce consistent square tiles */
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell:hover {
  transform: scale(1.03);
}

.cell.marked {
  background-color: #a5d6a7;
}

.cell.win {
  outline: 3px solid #00bfa6;
  box-shadow: 0 0 0 3px rgba(0,191,166,0.35);
}

.exchange-mode .cell {
  cursor: crosshair;
  outline: 2px dashed red;
}

.dropdown {
  margin-top: 15px;
  background: white;
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.dropdown p {
  margin: 5px 0;
  font-weight: 500;
}

/* ============================================
   TIMER
   ============================================ */

.timer {
  margin-top: 8px;
  font-weight: 700;
  font-size: 20px;
  display: none;
}

/* ============================================
   VERIFY FEEDBACK
   ============================================ */

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

.verify-fail {
  animation: shake 0.45s ease;
  box-shadow: 0 0 0 4px rgba(220, 0, 0, 0.25) inset;
}

/* ============================================
   LEADERBOARD
   ============================================ */

.leaderboard {
  margin-top: 16px;
  text-align: left;
  background: white;
  border-radius: 8px;
  padding: 12px 16px;
}

.leaderboard h3 {
  margin: 6px 0 10px;
}

.leaderboard ol {
  margin: 0;
  padding-left: 18px;
}

/* ============================================
   MULTIPLAYER UI
   ============================================ */

.multiplayer-section {
  margin-top: 15px;
  position: relative;
  min-height: 0; /* Start with no height, will be calculated */
  width: 100%;
  transition: min-height 0.2s ease;
}

.game-mode-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  justify-content: center;
  position: relative;
  z-index: 10;
}

#lockoutToggle {
  position: absolute;
  top: 50px;
  left: 0;
  right: 0;
  display: none;
  justify-content: center;
  gap: 20px;
  padding: 10px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  z-index: 5;
}

#lockoutToggle:not(.hidden) {
  display: flex;
}

#singlePlayerControls,
#multiplayerControls {
  position: absolute;
  top: 50px;
  left: 0;
  right: 0;
  margin-top: 0;
  z-index: 1;
  overflow: hidden; 
}

#singlePlayerControls {
  display: block;
}

#multiplayerControls {
  display: none;
  max-height: 200px;
}

#multiplayerControls:not(.hidden) {
  display: block;
  overflow: visible;
  max-height: none;
}

/* When lockout toggle is visible, push controls down */
#lockoutToggle:not(.hidden) ~ #singlePlayerControls,
#lockoutToggle:not(.hidden) ~ #multiplayerControls {
  top: 120px;
}

/* Explicitly reset controls when lockout toggle is hidden */
#lockoutToggle.hidden ~ #singlePlayerControls,
#lockoutToggle.hidden ~ #multiplayerControls {
  top: 50px;
}

.mode-toggle {
  flex: 1;
  padding: 8px 16px;
  border: 2px solid #9d4edd;
  background-color: white;
  color: #9d4edd;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-toggle.active {
  background-color: #9d4edd;
  color: white;
}

.mode-toggle:hover {
  background-color: #7b2cbf;
  color: white;
  border-color: #7b2cbf;
}

/* ============================================
   VISIBILITY SYSTEM
   ============================================ */

.hidden {
  display: none !important;
}

#roomInfo,
#challengeTooltip {
  display: none;
}

#roomInfo:not(.hidden),
#challengeTooltip:not(.hidden),
#lobby:not(.hidden),
#startGameBtn:not(.hidden),
#waitingForHost:not(.hidden),
#lockOutStats:not(.hidden),
#countdownMode:not(.hidden),
#lockConfirm:not(.hidden),
#recapLog:not(.hidden),
.timer:not(.hidden),
#welcome:not(.hidden) {
  display: block;
}

/* ============================================
   LOBBY
   ============================================ */

.join-room-section {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
}

.join-room-section input {
  flex: 1;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 4px;
}

#roomInfo {
  margin-top: 12px;
  padding: 10px;
  background: white;
  border-radius: 8px;
  text-align: center;
}

#roomInfo p {
  margin: 5px 0;
}

#roomCodeDisplay {
  font-size: 24px;
  font-weight: bold;
  color: #9d4edd;
  letter-spacing: 4px;
}

#lobby {
  margin-top: 15px;
  padding: 15px;
  background: white;
  border-radius: 8px;
  text-align: center;
  display: none;
}

#lobby h3 {
  margin-top: 0;
  color: #9d4edd;
}

#lobbyPlayers {
  list-style: none;
  padding: 12px;
  margin: 10px 0;
  background: white;
  border-radius: 8px;
  max-height: 200px;
  overflow-y: auto;
  text-align: left;
}

#lobbyPlayers li {
  padding: 8px;
  margin: 4px 0;
  background: #f5f5f5;
  border-radius: 4px;
}

#startGameBtn {
  background-color: #00bfa6;
  font-size: 16px;
  padding: 12px 24px;
  margin-top: 15px;
  display: none;
  position: relative;
  z-index: 10;
}

#startGameBtn:hover {
  background-color: #009688;
}

#startGameBtn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#waitingForHost {
  color: #666;
  font-style: italic;
  margin-top: 15px;
  display: none;
}

/* ============================================
   LOCK-OUT MODE
   ============================================ */

.cell.locked-by-opponent {
  background-color: #ffb3ba;
  border: 2px solid #ff6b6b;
}

.cell.confirming {
  background-color: #fff9c4;
  border: 2px solid #ffd700;
  transform: scale(1.05);
}

#lockOutStats {
  margin-top: 15px;
  padding: 10px;
  background: white;
  border-radius: 8px;
  text-align: center;
  font-weight: bold;
  display: none;
}

#lockStatsText {
  margin: 0;
  font-weight: bold;
}

#countdownMode {
  margin-top: 15px;
  padding: 10px;
  background: #fff9c4;
  border-radius: 8px;
  border: 2px solid #ffd700;
  text-align: center;
  display: none;
}

#countdownMode p:first-child {
  margin: 0;
  font-weight: bold;
  color: #d32f2f;
}

#countdownTimer {
  margin: 5px 0 0 0;
  font-size: 18px;
  font-weight: bold;
  font-family: monospace;
}


#lockConfirm {
  margin-top: 15px;
  padding: 10px;
  background: #fff9c4;
  border-radius: 8px;
  text-align: center;
  display: none;
}

#lockConfirm p {
  margin: 0;
}

#lockConfirm button {
  margin: 8px 4px 0 4px;
}

#confirmLockBtn {
  background-color: #00bfa6;
}

#confirmLockBtn:hover {
  background-color: #009688;
}

#cancelLockBtn {
  background-color: #ccc;
  color: #333;
}

#cancelLockBtn:hover {
  background-color: #bbb;
}

#recapLog {
  margin-top: 15px;
  padding: 15px;
  background: white;
  border-radius: 8px;
  max-height: 300px;
  overflow-y: auto;
  text-align: left;
  display: none;
}

#recapLog h3 {
  margin-top: 0;
  color: #9d4edd;
}

#recapList {
  margin: 10px 0;
  padding-left: 20px;
  text-align: left;
}

#recapList li {
  padding: 4px 0;
  border-bottom: 1px solid #eee;
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid #9d4edd;
  outline-offset: 2px;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 600px) {
  body {
    padding-top: 20px;
  }
  
  .container { 
    max-width: 95vw; 
    padding: 15px; 
  }
  
  .header { 
    flex-direction: column; 
    gap: 10px; 
  }
  
  .header h1 { 
    font-size: 2em; 
  }
  
  .logo-placeholder { 
    width: 50px; 
    height: 50px; 
  }
  
  .settings-row { 
    flex-direction: column; 
    gap: 10px; 
  }
  
  .setting-group { 
    width: 100%; 
    justify-content: space-between; 
  }
  
  .lockout-toggle { 
    flex-direction: column; 
    gap: 10px; 
    align-items: flex-start; 
  }
  
  .board { 
    gap: 4px; 
  }
  
  .cell { 
    font-size: 11px;
    padding: 8px 4px;
  }
  
  input { 
    width: 100%; 
    min-height: 44px;
  }
  
  button { 
    min-height: 44px;
    padding: 12px 16px;
  }
  
  select {
    min-height: 44px;
  }
  
  .join-room-section { 
    flex-direction: column; 
  }
  
  .join-room-section input { 
    width: 100%; 
  }
  
  #startGameBtn {
    min-height: 48px;
  }
  
  .challenge-tooltip {
    max-width: 90vw;
  }
  
  .tooltip-content {
    padding: 10px 12px;
    font-size: 0.85em;
  }
}