:root {
  color-scheme: light dark;
  --bg: #0f172a;
  --panel-bg: rgba(15, 23, 42, 0.85);
  --accent: #38bdf8;
  --accent-muted: rgba(56, 189, 248, 0.2);
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --danger: #f87171;
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont,
    'Helvetica Neue', sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at top, #1e293b, #0f172a);
  color: var(--text);
  padding: 24px;
}

main {
  width: min(1210px, 100%);
}

.panel {
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 18px;
  padding: 32px;
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.45);
}

.hidden {
  display: none;
}

h1 {
  margin: 0 0 12px;
  font-size: clamp(2.2rem, 4vw, 3rem);
  letter-spacing: 0.04em;
}

h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.tagline {
  margin: 0 0 28px;
  color: var(--text-muted);
}

.how-to-play {
  margin-top: 32px;
  padding: 20px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 12px;
}

.how-to-play h3 {
  margin: 0 0 12px;
  font-size: 1.1rem;
  color: var(--accent);
  font-weight: 600;
}

.how-to-play p {
  margin: 0 0 12px;
  color: var(--text);
  line-height: 1.6;
  font-size: 0.95rem;
}

.how-to-play p:last-child {
  margin-bottom: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.field span {
  font-size: 0.9rem;
  color: var(--text-muted);
}

input[type='text'] {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.7);
  color: inherit;
  font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type='text']:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

button {
  cursor: pointer;
  border: none;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: #0f172a;
  transition: transform 0.1s ease, box-shadow 0.2s ease, filter 0.2s;
}

button:disabled {
  cursor: wait;
  filter: grayscale(0.4);
  opacity: 0.7;
}

button:not(:disabled):active {
  transform: translateY(1px);
  box-shadow: inset 0 0 12px rgba(8, 145, 178, 0.4);
}

.feedback {
  color: var(--danger);
  min-height: 1.4em;
}

.status-text {
  color: var(--text-muted);
  min-height: 1.4em;
}

.admin-menu {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.admin-menu.hidden {
  display: none;
}

.admin-menu-toggle {
  align-self: flex-end;
}

.admin-menu-content {
  display: flex;
  gap: 12px;
}

.admin-menu-content.hidden {
  display: none;
}

.secondary {
  background: rgba(56, 189, 248, 0.12);
  color: var(--text);
  border: 1px solid rgba(56, 189, 248, 0.4);
  padding-inline: 16px;
}

.secondary:hover:not(:disabled) {
  background: rgba(56, 189, 248, 0.2);
  border-color: rgba(56, 189, 248, 0.6);
}

.danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.4);
  width: 100%;
}

.danger:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.25);
  border-color: rgba(248, 113, 113, 0.6);
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(6px);
  z-index: 1050;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--panel-bg);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 18px;
  padding: 28px 32px;
  box-shadow: 0 30px 60px rgba(15, 23, 42, 0.6);
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: min(420px, 92vw);
  text-align: center;
}

.modal-content h2 {
  margin: 0;
  font-size: 1.6rem;
}

.game-over-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.game-over-buttons button {
  flex: 1;
  min-width: 120px;
}

.cosmetic-reward {
  border-width: 3px;
  min-width: 380px;
}

.cosmetic-image-container {
  width: 180px;
  height: 180px;
  margin: 0 auto;
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.9));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 20px rgba(15, 23, 42, 0.45);
}

.cosmetic-image {
  max-width: 140px;
  max-height: 140px;
  width: auto;
  height: auto;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.35));
}

.cosmetic-name {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text);
}

.cosmetic-rarity {
  font-size: 1rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.cosmetic-description {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.cosmetic-reason {
  color: var(--accent);
  font-weight: 500;
  font-size: 0.9rem;
  margin-top: 4px;
}

.inventory-modal {
  max-width: min(600px, 92vw);
  min-width: 480px;
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 16px;
  padding: 16px 0;
  max-height: 400px;
  overflow-y: auto;
}

.inventory-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.9));
  border: 2px solid rgba(148, 163, 184, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.inventory-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.35);
}

.inventory-item.active {
  border-width: 3px;
}

.inventory-item.inactive {
  opacity: 0.5;
  filter: saturate(0.3);
}

.inventory-item.inactive:hover {
  opacity: 0.65;
  filter: saturate(0.5);
}

.inventory-item-image {
  max-width: 70%;
  max-height: 70%;
  width: auto;
  height: auto;
  margin-bottom: 8px;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

.inventory-item-name {
  font-size: 0.75rem;
  font-weight: 500;
  text-align: center;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.inventory-quantity-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(56, 189, 248, 0.9);
  color: #0f172a;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  line-height: 1;
}

.player-info {
  font-size: 1.1rem;
  font-weight: 500;
}


.game-status-banner {
  text-align: center;
  padding: 16px 24px;
  margin-bottom: 24px;
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 12px;
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: all 0.3s ease;
}

.game-status-banner:empty {
  display: none;
}

.game-status-banner.flash {
  background: rgba(248, 113, 113, 0.2);
  border-color: rgba(248, 113, 113, 0.4);
  color: var(--danger);
}

.game-layout {
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(220px, 260px) 1fr minmax(240px, 280px);
  align-items: start;
}

.player-overview {
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-items: center;
  justify-content: flex-start;
  padding: 8px 12px 8px 0;
}

.piece-frame {
  width: 220px;
  height: 220px;
  max-width: 100%;
  border-radius: 18px;
  border: 2px solid rgba(148, 163, 184, 0.4);
  background: linear-gradient(145deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.9));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 25px rgba(15, 23, 42, 0.45), 0 18px 32px rgba(15, 23, 42, 0.35);
  transition: opacity 0.3s ease;
}

.piece-frame.inactive {
  opacity: 0.5;
}

.piece-canvas {
  width: 100%;
  height: 100%;
  cursor: default;
  filter: drop-shadow(0 12px 16px rgba(0, 0, 0, 0.35));
}

.player-info-block {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  text-align: left;
}

.board-container {
  display: flex;
  justify-content: center;
  width: 560px;
  max-width: 100%;
  margin: 0 auto;
  justify-self: center;
  align-self: start;
}

.board {
  width: 100%;
  max-width: 560px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 10px solid #1e293b;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 1;
  flex: 0 0 auto;
}

.square {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
  transition: background 0.2s ease, transform 0.2s ease,
    box-shadow 0.2s ease;
  width: 100%;
  height: 100%;
  padding: 0;
  border: none;
}

.piece-icon {
  width: 85%;
  height: auto;
  max-width: 90%;
  max-height: 90%;
  pointer-events: none;
  display: block;
}

.square.light {
  background: var(--board-light);
  color: #1f2933;
}

.square.dark {
  background: var(--board-dark);
  color: #111827;
}

.square.controlled::after {
  content: '';
  position: absolute;
  inset: 10%;
  border: 2px solid rgba(56, 189, 248, 0.8);
  border-radius: 10%;
  pointer-events: none;
}

.square.selected {
  outline: 4px solid rgba(56, 189, 248, 0.8);
  outline-offset: -4px;
}

.square.last-move {
  box-shadow: inset 0 0 0 6px rgba(59, 130, 246, 0.35);
}

.square.capture {
  box-shadow: inset 0 0 0 6px rgba(248, 113, 113, 0.55);
}

.square.inactive {
  opacity: 0.55;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}

.sidebar-section {
  background: rgba(15, 23, 42, 0.6);
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.1);
  padding: 16px;
  max-height: 560px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
}

.leaderboard-list li {
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 8px;
  background: rgba(148, 163, 184, 0.1);
  font-size: 0.95rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.2s ease;
}

.leaderboard-list li:hover {
  background: rgba(148, 163, 184, 0.15);
}

.leaderboard-list li:last-child {
  margin-bottom: 0;
}

.leaderboard-entry-rank {
  font-weight: 700;
  color: var(--accent);
  margin-right: 12px;
  min-width: 24px;
}

.leaderboard-entry-name {
  flex: 1;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.leaderboard-entry-score {
  font-weight: 600;
  color: var(--text-muted);
}

@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: minmax(220px, 260px) minmax(0, 1fr);
  }

  .sidebar {
    grid-column: 1 / -1;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 16px;
  }

  .board-container {
    width: min(80vw, 460px);
  }

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidebar-section {
    flex: 1 1 240px;
  }
}

@media (max-width: 600px) {
  body {
    padding: 12px;
  }

  .panel {
    padding: 20px;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .player-overview {
    padding: 0;
    align-items: center;
  }

  .board {
    border-width: 6px;
  }

  .admin-menu {
    width: 100%;
    align-items: stretch;
    gap: 6px;
  }

  .admin-menu-content {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .piece-frame {
    width: 180px;
    height: 180px;
  }
}

/* Lobby Timer */
.lobby-timer {
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
  max-height: none;
}

.lobby-timer h3 {
  margin: 0 0 12px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  text-align: center;
}

.timer-display {
  font-size: 3rem;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.timer-display::after {
  content: 's';
  font-size: 1.5rem;
  margin-left: 4px;
  opacity: 0.7;
}

/* Footer */
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 24px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(148, 163, 184, 0.1);
  z-index: 10;
}

.footer-copyright {
  color: var(--text-muted);
}

.footer-separator {
  margin: 0 8px;
  color: var(--text-muted);
  opacity: 0.5;
}

.footer-link {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease, text-decoration 0.2s ease;
}

.footer-link:hover {
  color: var(--text);
  text-decoration: underline;
}

.footer-link:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
