:root {
  --bg: #15171c;
  --bg-elevated: #1d2026;
  --text: #eef1f6;
  --text-muted: #9aa3b2;
  --accent: #5b8def;
  --accent-contrast: #0b1020;
  --danger: #e2574c;
  --success: #4caf78;
  --radius: 14px;
  --board-size: min(86vw, 86vh, 640px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.4rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid #ffffff12;
}

header.topbar .brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

header.topbar nav {
  display: flex;
  gap: 0.5rem;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 0.55rem 1rem;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  background: #ffffff14;
  color: var(--text);
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:hover { background: #ffffff22; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); color: white; }
.btn.ghost { background: transparent; border: 1px solid #ffffff2a; }

main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.view { display: none; width: 100%; }
.view.active { display: flex; flex-direction: column; align-items: center; gap: 1.2rem; }

.hero {
  text-align: center;
  max-width: 560px;
}
.hero h1 { font-size: 2.2rem; margin-bottom: 0.3rem; }
.hero p { color: var(--text-muted); }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  width: 100%;
  max-width: 760px;
}
.menu-card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 1.3rem;
  text-align: left;
  cursor: pointer;
  border: 1px solid #ffffff12;
  transition: transform 0.12s ease, border-color 0.15s ease;
}
.menu-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.menu-card h3 { margin: 0 0 0.3rem; }
.menu-card p { margin: 0; color: var(--text-muted); font-size: 0.9rem; }

.game-layout {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
}

/* --- Schachbrett --- */
#board-wrap {
  position: relative;
}
.board-frame {
  padding: clamp(8px, 1.6vw, 16px);
  border-radius: 18px;
  background: linear-gradient(160deg,
    color-mix(in srgb, var(--sq-dark, #83674f) 85%, #000 15%) 0%,
    color-mix(in srgb, var(--sq-dark, #83674f) 55%, #000 45%) 100%);
  box-shadow: 0 25px 60px -12px #000a, inset 0 0 0 1px #ffffff1a;
}
.board {
  width: var(--board-size);
  height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px #00000055;
  touch-action: none;
}
.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
.square.light { background: var(--sq-light, #ebe0cf); }
.square.dark { background: var(--sq-dark, #83674f); }
.square.selected::before {
  content: "";
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--accent) 55%, transparent);
}
.square.last-move { box-shadow: inset 0 0 0 999px rgba(255, 210, 60, 0.38); }
.square.check-flash { box-shadow: inset 0 0 0 999px rgba(226, 87, 76, 0.45); }
.square.drop-target { box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--accent) 80%, transparent); }
.square .move-dot {
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.16);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
  pointer-events: none;
}
.square .capture-ring {
  position: absolute;
  inset: 5%;
  border-radius: 50%;
  border: 4px solid rgba(0, 0, 0, 0.18);
  pointer-events: none;
}
.square .coord {
  position: absolute;
  font-size: 0.68rem;
  font-weight: 700;
  bottom: 2px;
  right: 4px;
  line-height: 1;
  pointer-events: none;
  font-family: ui-monospace, "Segoe UI", monospace;
}
.square .coord.file { bottom: 2px; right: 4px; }
.square .coord.rank { top: 2px; left: 4px; bottom: auto; right: auto; }
.square.light .coord { color: color-mix(in srgb, var(--sq-dark, #83674f) 75%, #000 25%); opacity: 0.75; }
.square.dark .coord { color: color-mix(in srgb, var(--sq-light, #ebe0cf) 85%, #fff 15%); opacity: 0.75; }
.piece {
  width: 86%;
  height: 86%;
  cursor: grab;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.35));
  transition: transform 0.08s ease;
}
.piece:hover { transform: scale(1.04); }
.piece.dragging { opacity: 0.25; }
.piece.drag-ghost {
  cursor: grabbing;
  transform: scale(1.12);
}
.drag-ghost {
  position: fixed;
  pointer-events: none;
  width: 72px;
  height: 72px;
  z-index: 999;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.5));
}

#side-panel {
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.panel-box {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 1rem;
  border: 1px solid #ffffff12;
}
.player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0;
}
.player-row.active { color: var(--accent); font-weight: 700; }
#move-list {
  max-height: 220px;
  overflow-y: auto;
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  line-height: 1.6;
}
#move-list .mv-num { color: var(--text-muted); margin-right: 0.3rem; }
.status-banner {
  text-align: center;
  font-weight: 700;
  padding: 0.6rem;
  border-radius: 10px;
  background: #ffffff10;
}
.status-banner.win { background: var(--success); color: #06241a; }
.status-banner.draw { background: #ffffff26; }

.theme-swatches { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.swatch {
  width: 46px; height: 46px;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}
.swatch.selected { border-color: var(--accent); }
.swatch span:nth-child(1), .swatch span:nth-child(4) { background: var(--sw-light); }
.swatch span:nth-child(2), .swatch span:nth-child(3) { background: var(--sw-dark); }

.form-box {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.form-box input, .form-box select {
  background: #ffffff10;
  border: 1px solid #ffffff22;
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  color: var(--text);
  font-size: 0.95rem;
}
.form-box label { font-size: 0.82rem; color: var(--text-muted); }
.invite-code {
  font-family: ui-monospace, monospace;
  font-size: 1.4rem;
  letter-spacing: 0.15em;
  text-align: center;
  padding: 0.6rem;
  background: #ffffff10;
  border-radius: 8px;
  cursor: pointer;
}

table.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.admin-table th, table.admin-table td {
  text-align: left;
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid #ffffff12;
}

.muted { color: var(--text-muted); }
.row { display: flex; gap: 0.6rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
