/* lobby.css — pre-match lobby overlay.
 *
 * Phase 3 Milestone 3.6: full-screen overlay that hides the canvas until
 * a match begins. Hosts a state-machine-driven panel swapper (identity /
 * menu / join / browse / waiting) owned by src/lobby.js. Audio is
 * deferred post-jam so no volume UI here.
 */

/* --- Overlay root ----------------------------------------------------- */

#lobby-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background:
    linear-gradient(rgba(10, 10, 24, 0.55), rgba(10, 10, 24, 0.55)),
    url('../Assets/Art/RubbleKings_BG.png') center center / cover no-repeat,
    radial-gradient(ellipse at center, #1a1a2e 0%, #0a0a18 100%);
  color: #ddd;
  font-family: monospace;
  overflow-y: auto;
  padding: 32px 20px;
  box-sizing: border-box;
}
#lobby-overlay.visible {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* --- Home button (back to Pixel Crown site) ------------------------------ */
#home-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 8px;
  border-radius: 6px;
  background: rgba(20, 20, 40, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #ccc;
  font-family: monospace;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s;
  z-index: 1;
}
#home-btn:hover {
  background: rgba(40, 40, 80, 0.9);
}
#home-btn img {
  image-rendering: pixelated;
}
body[data-lobby-panel="menu"] #home-btn,
body[data-lobby-panel="options"] #home-btn {
  display: flex;
}

/* Shell: default single-column width. Grows wider on the waiting
 * panel so the chat sidebar has room. JS toggles body attrs /
 * .lobby-shell.wide so we don't have to query panel visibility in CSS. */
.lobby-shell {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.lobby-shell.wide {
  max-width: 1080px;
}

/* --- Header ----------------------------------------------------------- */

.lobby-header {
  text-align: center;
  display: none; /* default hidden — shown only while menu panel is active */
}
/* JS toggles <body data-lobby-panel="..."> so we can gate the header to
 * the main menu exclusively. Other panels have their own h2 headers. */
body[data-lobby-panel="menu"] .lobby-header {
  display: block;
}
#lobby-title-sprite {
  display: block;
  margin: 0 auto;
  max-width: min(480px, 90vw);
  max-height: 180px;
  width: auto;
  height: auto;
  filter: drop-shadow(-25px 25px 20px rgba(0, 0, 0, 0.7));
}
.lobby-subtitle {
  margin-top: 4px;
  font-size: 12px;
  opacity: 0.6;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* --- Panel ------------------------------------------------------------ */

.lobby-panel {
  background: rgba(30, 30, 50, 0.9);
  border: 1px solid rgba(200, 200, 220, 0.25);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.lobby-panel[hidden] {
  display: none !important;
}
.lobby-panel h2 {
  margin: 0;
  font-size: 18px;
  font-weight: normal;
  color: #fff;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* --- Field (label + input) ------------------------------------------- */

.lobby-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}
.lobby-field span {
  color: #aaa;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.lobby-field input[type="text"],
.lobby-field input[type="number"] {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(200, 200, 220, 0.35);
  color: #eee;
  padding: 8px 10px;
  font-family: monospace;
  font-size: 14px;
  width: 100%;
  box-sizing: border-box;
}
.lobby-field select {
  color: #eee;
  padding: 8px 10px;
  font-family: monospace;
  font-size: 14px;
  width: 100%;
  box-sizing: border-box;
  /* PanelElement02.png 9-slice background */
  border: none;
  border-image: url('../Assets/UI/Windows/PanelElement02.png') 6 8 6 8 fill / 6px 8px 6px 8px / 0 stretch;
  -webkit-appearance: none;
  appearance: none;
  /* Custom dropdown arrow (▼ via inline SVG) */
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23aaa' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 10px center;
  cursor: pointer;
}
.lobby-field select option {
  background: #1a1a2e;
  color: #ddd;
}
.lobby-field select option:checked {
  background: #2a2a3e;
}
.lobby-field input[type="checkbox"] {
  width: auto;
  margin: 0;
}
.lobby-field input:focus,
.lobby-field select:focus {
  outline: none;
}

/* --- Slider fields (Human Players, AI Opponents) ----------------------- */
.slider-wrap {
  position: relative;
  width: 100%;
  height: 36px;
}
.slider-wrap input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 36px;
  margin: 0;
  background: transparent;
  border: none;
  outline: none;
  cursor: pointer;
  /* PanelElement02.png as 9-slice track behind the native slider */
  border-image: url('../Assets/UI/Windows/PanelElement02.png') 6 8 6 8 fill / 6px 8px 6px 8px / 0 stretch;
}
/* Webkit (Chrome, Edge, Safari) track — transparent so border-image shows */
.slider-wrap input[type="range"]::-webkit-slider-runnable-track {
  height: 36px;
  background: transparent;
  border: none;
}
/* Webkit thumb — square Box03.png */
.slider-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 32px;
  height: 32px;
  margin-top: 0;
  border: none;
  border-radius: 0;
  background: url('../Assets/UI/Windows/Box03.png') center / contain no-repeat;
  cursor: pointer;
  image-rendering: pixelated;
}
/* Firefox track */
.slider-wrap input[type="range"]::-moz-range-track {
  height: 36px;
  background: transparent;
  border: none;
}
/* Firefox thumb — square Box03.png */
.slider-wrap input[type="range"]::-moz-range-thumb {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 0;
  background: url('../Assets/UI/Windows/Box03.png') center / contain no-repeat;
  cursor: pointer;
  image-rendering: pixelated;
}
.slider-thumb-label {
  position: absolute;
  top: 0;
  left: 0;
  width: 32px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: monospace;
  font-size: 13px;
  font-weight: bold;
  color: #fff;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}

/* --- Public Room toggle (art-based) ----------------------------------- */
.lobby-field-toggle {
  /* Inherits row layout from .lobby-host-settings .lobby-field */
}
.lobby-field-toggle input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 0;
  background: url('../Assets/UI/Windows/Box02.png') center / contain no-repeat;
  image-rendering: pixelated;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  flex-grow: 0;
}
.lobby-field-toggle input[type="checkbox"]:checked {
  background: url('../Assets/UI/Windows/Box01.png') center / contain no-repeat;
  image-rendering: pixelated;
}

.lobby-field-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
}
.lobby-field-block > span {
  color: #aaa;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* Section divider inside a single panel (e.g. Options has Identity + Audio). */
.lobby-section-header {
  font-size: 11px;
  color: #ffdd44;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-top: 4px;
  padding: 6px 12px;
  border: none;
  border-image: url('../Assets/UI/Windows/MenuItemTite.png') 6 12 6 12 fill / 6px 12px 6px 12px / 0 stretch;
}

/* Volume sliders — same field frame but sized to fill the row.
 * Scoped to avoid colliding with .slider-wrap range inputs. */
.lobby-field > input[type="range"] {
  width: 100%;
  accent-color: #ffdd44;
  height: 22px;
  padding: 0;
  background: transparent;
  border: none;
}

/* --- Join code inline row (input + button side by side) --------------- */
.lobby-field-join-code {
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
}
.lobby-field-join-code input[type="text"] {
  flex: 1;
}

/* --- Swatch grid (color + shape) ------------------------------------- */

/* Fixed 10-column grid so the palette always fits on one row. Swatches
 * fill the row width, so they shrink naturally to match the panel
 * width. Min swatch size floors at ~28px for playable touch targets. */
.lobby-swatch-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
}
.lobby-swatch {
  width: 100%;
  aspect-ratio: 1 / 1;
  min-width: 28px;
  border: 2px solid rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s, opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  padding: 0;
  position: relative; /* anchor for the .taken ::after X overlay */
}
.lobby-swatch:hover {
  transform: scale(1.05);
}
.lobby-swatch.selected {
  border-color: #ffdd44;
  box-shadow: 0 0 0 2px rgba(255, 220, 80, 0.6);
}
.lobby-swatch.taken {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(1);
}
.lobby-swatch.taken:hover {
  transform: none;
}
/* Black X drawn over taken swatches via two crossed diagonal bars.
 * Pointer-events off so the click handler still fires (it short-circuits
 * the pick) without the overlay swallowing events. */
.lobby-swatch.taken::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to top right,
      transparent calc(50% - 2px),
      rgba(0, 0, 0, 0.85) calc(50% - 2px),
      rgba(0, 0, 0, 0.85) calc(50% + 2px),
      transparent calc(50% + 2px)),
    linear-gradient(to top left,
      transparent calc(50% - 2px),
      rgba(0, 0, 0, 0.85) calc(50% - 2px),
      rgba(0, 0, 0, 0.85) calc(50% + 2px),
      transparent calc(50% + 2px));
}
.lobby-swatch canvas {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

/* --- Buttons ---------------------------------------------------------- */

.lobby-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.lobby-btn-back {
  margin-right: auto;
}

/* Main-menu vertical column. All buttons same width, centered in the
 * viewport so the menu doesn't hug the top. The title header sits
 * directly above — we leave a modest gap rather than pushing the
 * menu panel down independently, so title + menu read as a unit. */
.lobby-panel-menu {
  align-items: center;
  background: transparent;
  border: none;
}
.lobby-panel-menu h2 {
  display: none;
}
body[data-lobby-panel="menu"] .lobby-shell {
  padding-top: 4vh;
}
.lobby-menu-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 260px;
  max-width: 100%;
}
.lobby-menu-column .lobby-btn {
  width: 100%;
  padding: 14px 20px;
  font-size: 15px;
  box-shadow: -25px 25px 20px rgba(0, 0, 0, 0.7);
  border-image: url('../Assets/UI/Windows/Button03.png') 8 12 8 12 fill / 8px 12px 8px 12px / 0 stretch;
  color: #fff;
}
.lobby-menu-column .lobby-btn:hover:not(:disabled) {
  filter: brightness(1.3);
  color: #ddd;
}

.lobby-btn {
  padding: 10px 16px;
  border: none;
  border-image: url('../Assets/UI/Windows/Button04.png') 6 10 6 10 fill / 6px 10px 6px 10px / 0 stretch;
  color: #ddd;
  font-family: monospace;
  font-size: 14px;
  letter-spacing: 1px;
  cursor: pointer;
  transition: filter 0.15s, color 0.15s;
  background: transparent;
}
.lobby-btn:hover:not(:disabled) {
  filter: brightness(1.3);
  color: #fff;
}
.lobby-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.lobby-btn-primary {
  border-image: url('../Assets/UI/Windows/Button03.png') 8 12 8 12 fill / 8px 12px 8px 12px / 0 stretch;
  padding: 12px 20px;
  color: #fff;
}
.lobby-btn-primary:hover:not(:disabled) {
  filter: brightness(1.25);
}
.lobby-btn-text {
  border: none;
  background: transparent;
  color: #999;
  padding: 6px 10px;
  text-align: left;
}
.lobby-btn-text:hover {
  color: #ddd;
  background: transparent;
}

.lobby-secondary {
  margin-top: 4px;
  display: flex;
  justify-content: center;
}

/* --- Error + hint ----------------------------------------------------- */

.lobby-error {
  color: #ff8888;
  font-size: 12px;
  min-height: 16px;
}
.lobby-hint {
  font-size: 11px;
  color: #888;
  text-align: center;
  min-height: 14px;
}

/* --- Rooms list ------------------------------------------------------- */

.lobby-rooms-list {
  min-height: 120px;
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(200, 200, 220, 0.15);
  padding: 8px;
}
.lobby-room-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.lobby-room-row:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(200, 200, 220, 0.3);
}
.lobby-room-row .name {
  font-size: 13px;
  color: #eee;
}
.lobby-room-row .meta {
  font-size: 11px;
  color: #888;
}
.lobby-room-row button {
  padding: 6px 12px;
  font-size: 12px;
}
.lobby-empty-state {
  font-size: 12px;
  color: #777;
  text-align: center;
  padding: 24px;
  font-style: italic;
}

/* --- Waiting room ----------------------------------------------------- */

.lobby-room-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(200, 200, 220, 0.2);
}
.lobby-room-info[hidden] {
  display: none;
}
.lobby-code {
  font-size: 22px;
  font-weight: bold;
  letter-spacing: 4px;
  color: #ffdd44;
}

.lobby-roster-header,
.lobby-settings-header {
  font-size: 11px;
  color: #aaa;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-top: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(200, 200, 220, 0.15);
}

.lobby-roster {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.lobby-roster-row {
  display: grid;
  grid-template-columns: 28px 28px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.03);
}
.lobby-roster-row canvas.swatch {
  width: 24px;
  height: 24px;
}
.lobby-roster-row .name {
  font-size: 13px;
  color: #eee;
}
.lobby-roster-row .host-tag {
  font-size: 10px;
  color: #ffdd44;
  letter-spacing: 1px;
}
.lobby-roster-row .ready-tag {
  font-size: 11px;
}
.lobby-roster-row .ready-tag.ready {
  color: #7fdd7f;
}
.lobby-roster-row .ready-tag.not-ready {
  color: #888;
}

.lobby-host-settings {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lobby-host-settings .lobby-field {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}
.lobby-host-settings .lobby-field span {
  flex-basis: 140px;
  flex-shrink: 0;
}
.lobby-host-settings .lobby-field input:not([type="checkbox"]),
.lobby-host-settings .lobby-field select,
.lobby-host-settings .lobby-field .slider-wrap {
  flex: 1;
}

/* --- Chat ------------------------------------------------------------- */

/* Waiting-room side-by-side: shell becomes flex-row so the right
 * sidebar (chat + players + AI seats) sits beside the waiting panel. */
body[data-lobby-panel="waiting"] .lobby-shell {
  max-width: 1080px;
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap; /* narrow viewports stack the sidebar below */
  gap: 16px;
}
body[data-lobby-panel="waiting"] .lobby-panel-waiting {
  flex: 0 1 520px;
  min-width: 320px;
  min-height: 480px;
}
.lobby-panel-waiting .lobby-buttons {
  margin-top: auto;
}

/* Right sidebar — stacks Chat, Players roster, and AI seats in a
 * column. Chat is at the top so its position is anchored regardless
 * of how the player roster grows or shrinks. Only visible while the
 * waiting-room panel is active. */
.lobby-sidebar-right {
  display: none;
  flex-direction: column;
  gap: 16px;
  flex: 1 1 280px;
  max-width: 360px;
  min-width: 260px;
  align-self: flex-start;
}
body[data-lobby-panel="waiting"] .lobby-sidebar-right {
  display: flex;
}
.lobby-roster-panel h2 {
  margin-bottom: 8px;
}
.lobby-ai-seats-panel h2 {
  margin-bottom: 8px;
}
.lobby-ai-seats-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lobby-ai-seat-row {
  display: grid;
  /* label  color  heraldry  skill  personality */
  grid-template-columns: 32px 18px 18px 1fr 1fr;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}
.lobby-ai-seat-row .seat-label {
  font-size: 12px;
  color: #bbb;
  font-family: monospace;
}
.lobby-ai-seat-row .ai-seat-swatch {
  display: block;
  width: 18px;
  height: 18px;
}
.lobby-ai-seat-row select {
  width: 100%;
  padding: 4px 6px;
  font-family: monospace;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.3);
  color: #eee;
  border: 1px solid rgba(200, 200, 220, 0.2);
}
.lobby-ai-seat-row select option {
  background: #1a1a2e;
  color: #ddd;
}
.lobby-chat-log {
  min-height: 180px;
  max-height: 260px;
  overflow-y: auto;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(200, 200, 220, 0.15);
  font-size: 12px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.lobby-chat-line {
  word-break: break-word;
}
.lobby-chat-line .author {
  font-weight: bold;
}
.lobby-chat-line .sys {
  color: #888;
  font-style: italic;
}

.lobby-chat-form {
  display: flex;
  gap: 6px;
}
.lobby-chat-form input[type="text"] {
  flex: 1;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(200, 200, 220, 0.35);
  color: #eee;
  padding: 8px 10px;
  font-family: monospace;
  font-size: 13px;
}
.lobby-chat-form input[type="text"]:focus {
  outline: none;
  border-color: rgba(255, 220, 120, 0.8);
}
.lobby-chat-form button {
  padding: 8px 16px;
}
