body {
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 800px;
  padding: 40px;
}

h1 {
  margin-bottom: 28px;
  font-size: 2.5em;
  text-align: center;
}

/* ── Name overlay ──────────────────────────────────────── */

#nameOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: overlay-in 0.2s ease;
}

#nameOverlay.closing {
  animation: overlay-out 0.2s ease forwards;
}

@keyframes overlay-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes overlay-out {
  to {
    opacity: 0;
  }
}

.name-modal {
  position: relative;
  background: white;
  border-radius: 18px;
  padding: 36px 32px 24px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  text-align: center;
  animation: modal-in 0.25s cubic-bezier(0.34, 1.2, 0.64, 1);
}

.name-modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: #777;
  font: inherit;
  font-size: 1.55rem;
  line-height: 1;
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.name-modal-close:hover {
  color: var(--color-text);
  background: #f0f0f0;
}

.name-modal-close:focus-visible {
  color: var(--color-text);
  background: #f0f0f0;
  outline: 3px solid color-mix(in srgb, var(--color-primary) 45%, transparent);
  outline-offset: 2px;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.88) translateY(-16px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.name-modal h2 {
  color: var(--color-text);
  font-size: 1.5em;
  margin: 0 0 24px;
}

.name-dialog-error {
  margin: -8px 0 16px;
  padding: 10px 12px;
  color: var(--color-team-2);
  font-size: 0.88em;
  line-height: 1.35;
  text-align: left;
  background: #fff0f1;
  border: 1px solid color-mix(in srgb, var(--color-danger) 35%, transparent);
  border-radius: 8px;
}

.name-modal p {
  color: #777;
  font-size: 0.95em;
  margin-bottom: 24px;
}

.name-modal .room-input {
  width: 100%;
  height: 50px;
  padding-inline: 8px;
  margin-bottom: 0;
  text-align: center;
  font-size: 0.95em;
}

.name-entry-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 0 10px;
}

.name-input-error {
  display: none;
  grid-column: 1 / -1;
  margin: 7px 0 0;
  color: var(--color-team-2);
  font-size: 0.88em;
  line-height: 1.35;
  text-align: left;
}

.name-input-error.visible {
  display: block;
}

.name-modal .btn {
  width: 100%;
  font-size: 1.05em;
  padding: 14px;
  margin-top: 14px;
  margin-bottom: 12px;
}

.name-entry-row .btn {
  width: auto;
  height: 50px;
  margin: 0;
  padding-inline: 18px;
}

.name-modal .modal-skip {
  font-size: 0.88em;
  color: #999;
  margin: 20px 0 0;
}

.modal-skip button {
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
}

.modal-skip button:hover {
  color: var(--color-primary-dark);
}

/* ── Player badge (shown in lobby after name is set) ──── */

#playerBadge {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f0f0ff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  margin-bottom: 28px;
  font-size: 0.95em;
  color: #444;
}

#badgeLabel {
  flex: 1;
}

.player-badge-icon {
  width: 19px;
  height: 19px;
  object-fit: contain;
  flex: 0 0 auto;
}

#playerBadge .rename-icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  padding: 0;
  border-radius: 50%;
}

#playerBadge .rename-icon-btn svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

#playerBadge .rename-icon-btn:hover,
#playerBadge .rename-icon-btn:focus-visible {
  color: var(--color-primary-dark);
  background: rgba(102, 126, 234, 0.12);
}

#playerBadge .rename-icon-btn:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--color-primary) 45%, transparent);
  outline-offset: 2px;
}

#playerBadge .rename-icon-btn::after {
  content: attr(aria-label);
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 10;
  padding: 5px 8px;
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  border-radius: 6px;
  background: rgba(44, 62, 80, 0.94);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition:
    opacity 0.15s ease,
    transform 0.15s ease;
}

#playerBadge .rename-icon-btn:hover::after,
#playerBadge .rename-icon-btn:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

/* Rename modal (hidden by default) */
#renameModal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.42);
}

#renameModal.visible {
  display: flex;
}

.rename-dialog {
  width: min(380px, 100%);
  padding: 24px;
  border-radius: 14px;
  background: white;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.26);
}

.rename-dialog h3 {
  margin: 0 0 14px;
  color: var(--color-text);
}

.rename-dialog .room-input {
  width: 100%;
}

.rename-error {
  height: 1.3em;
  margin-top: 7px;
  color: var(--color-team-2);
  font-size: 0.82rem;
  line-height: 1.3;
  visibility: hidden;
}

.rename-error.visible {
  visibility: visible;
}

.rename-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.rename-cancel {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-weight: 700;
}

/* ── Shared form elements ───────────────────────────────── */

.create-room-section {
  background: var(--color-surface-subtle);
  border-radius: 15px;
  padding: 30px;
  margin-bottom: 30px;
  text-align: center;
}

.create-room-section h3 {
  color: var(--color-text);
  margin-bottom: 20px;
}

.room-form {
  display: grid;
  grid-template-columns: minmax(0, 330px) auto;
  gap: 7px 15px;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  align-items: stretch;
}

.room-name-error {
  display: none;
  grid-column: 1 / -1;
  color: var(--color-team-2);
  font-size: 0.82rem;
  line-height: 1.3;
  text-align: left;
}

.room-name-error.visible {
  display: block;
}

.room-input {
  box-sizing: border-box;
  padding: 12px 16px;
  border: 2px solid var(--color-border);
  border-radius: 8px;
  font-size: 1em;
  min-width: 200px;
}

.room-form .room-input {
  width: 100%;
  min-width: 0;
}

.room-input:focus {
  border-color: var(--color-primary);
  outline: 3px solid color-mix(in srgb, var(--color-primary) 30%, transparent);
  outline-offset: 1px;
}

.btn {
  background: linear-gradient(45deg, var(--color-primary), var(--color-primary-dark));
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1em;
  transition: transform 0.2s ease;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:focus-visible,
.rename-cancel:focus-visible,
.modal-skip button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--color-primary) 45%, transparent);
  outline-offset: 2px;
}

.btn:disabled {
  background: var(--color-neutral);
  cursor: not-allowed;
  transform: none;
}

/* ── Rooms list ─────────────────────────────────────────── */

.rooms-section {
  background: var(--color-surface-subtle);
  border-radius: 15px;
  padding: 30px;
}

.rooms-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
}

.rooms-heading h3 {
  grid-column: 2;
  color: var(--color-text);
  margin: 0;
  text-align: center;
}

.rooms-sort {
  grid-column: 1;
  justify-self: start;
  position: relative;
  width: 120px;
  max-width: 100%;
}

.rooms-sort-icon {
  position: absolute;
  top: 50%;
  left: 9px;
  z-index: 1;
  width: 15px;
  height: 15px;
  color: var(--color-text-muted);
  pointer-events: none;
  transform: translateY(-50%);
}

.rooms-sort-select {
  appearance: none;
  width: 100%;
  min-width: 0;
  padding-right: 8px;
  padding-left: 29px;
  background: white;
  font-size: calc(1em - 1pt);
  cursor: pointer;
}

.rooms-search {
  grid-column: 3;
  justify-self: end;
  position: relative;
  width: 205px;
  max-width: 100%;
}

.rooms-search-icon {
  position: absolute;
  top: 50%;
  left: 10px;
  z-index: 1;
  width: 15px;
  height: 15px;
  color: #777;
  pointer-events: none;
  transform: translateY(-50%);
}

.rooms-search-input {
  width: 100%;
  min-width: 0;
  padding-right: 12px;
  padding-left: 32px;
  background: white;
  font-size: calc(1em - 1pt);
}

.rooms-list {
  display: grid;
  gap: 15px;
}

.room-card {
  background: white;
  border: 2px solid var(--color-border);
  border-radius: 10px;
  padding: 20px;
  transition: all 0.3s ease;
  cursor: default;
}

.room-card[data-room-id] {
  cursor: pointer;
}

.room-card[data-room-id]:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  border-color: var(--color-primary);
}

.room-card:focus-visible {
  border-color: var(--color-primary);
  outline: 3px solid color-mix(in srgb, var(--color-primary) 35%, transparent);
  outline-offset: 2px;
}

.room-card.in-progress {
  border-color: #ffc107;
  background: #fff3cd;
  cursor: default;
}

.room-card.in-progress:hover {
  transform: none;
  box-shadow: none;
}

.room-card.rejoin {
  border-color: var(--color-success);
  background: #d4edda;
}

.room-card.closing {
  border-color: #dc3545;
  background: #f8d7da;
}

.room-card.rejoin:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  border-color: #1e7e34;
}

.room-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.room-name {
  font-weight: bold;
  font-size: 1.2em;
  color: var(--color-text);
}

.room-status {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8em;
  font-weight: bold;
}

.status-open {
  background: #d4edda;
  color: #155724;
}
.status-in-game {
  background: #fff3cd;
  color: #856404;
}
.status-finishing {
  background: #dbeafe;
  color: #1e3a8a;
}
.status-closing {
  background: #f8d7da;
  color: #721c24;
}

.room-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--color-text-muted);
}

.room-players {
  display: flex;
  gap: 5px;
}

.player-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-border);
}

.player-dot.filled {
  background: var(--color-success);
}

.no-rooms {
  text-align: center;
  color: var(--color-text-muted);
  padding: 40px;
  font-style: italic;
}

.loading {
  text-align: center;
  color: var(--color-text-muted);
  padding: 20px;
}

.rooms-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}

.rooms-pagination[hidden] {
  display: none;
}

.pagination-summary {
  color: var(--color-text-muted);
  font-size: 0.9em;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pagination-button {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid #cfd4da;
  border-radius: 7px;
  background: white;
  color: #555;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.pagination-button:hover:not(:disabled),
.pagination-button:focus-visible {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.pagination-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--color-primary) 35%, transparent);
  outline-offset: 2px;
}

.pagination-button.active {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: white;
  cursor: default;
}

.pagination-button:disabled {
  color: #aaa;
  background: #f1f3f5;
  cursor: not-allowed;
}

.pagination-ellipsis {
  min-width: 20px;
  color: #777;
  text-align: center;
}

@media (max-width: 560px) {
  .rooms-heading {
    grid-template-columns: 1fr;
  }
  .rooms-heading h3 {
    grid-column: 1;
    grid-row: 1;
  }
  .rooms-sort {
    grid-column: 1;
    grid-row: 2;
    justify-self: center;
  }
  .rooms-search {
    grid-column: 1;
    grid-row: 3;
    justify-self: center;
  }
  .rooms-pagination {
    justify-content: center;
  }
  .pagination-summary {
    width: 100%;
    text-align: center;
  }
  .pagination-button {
    min-width: 32px;
    padding: 0 8px;
  }
}

/* ── Instructions ───────────────────────────────────────── */

.instructions {
  background: var(--color-surface-subtle);
  border-radius: 10px;
  padding: 20px;
  margin-top: 30px;
  text-align: left;
}

.instructions h3 {
  color: var(--color-text);
  margin-bottom: 10px;
}
.instructions ol {
  color: var(--color-text-muted);
  line-height: 1.6;
  padding-left: 22px;
}
.instructions li {
  margin-bottom: 5px;
}

/* ── Footer ─────────────────────────────────────────────── */

.site-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  margin-top: auto;
  padding-top: 40px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.85rem;
}

.site-footer a {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: white;
  font-weight: 600;
  text-decoration-color: rgba(255, 255, 255, 0.65);
  text-underline-offset: 2px;
}

.site-footer a:hover {
  text-decoration-color: white;
}

.site-footer a:focus-visible {
  border-radius: 2px;
  outline: 3px solid rgba(255, 255, 255, 0.75);
  outline-offset: 2px;
}

.github-icon {
  width: 1rem;
  height: 1rem;
  fill: currentColor;
}

/* ── Feedback messages ──────────────────────────────────── */

.error-message {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
  margin: 20px 0;
}

.success-message {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
  margin: 20px 0;
}
