:root {
  --bg: #09090b;
  --panel: rgba(18, 18, 24, 0.92);
  --panel-2: rgba(32, 32, 42, 0.92);
  --red: #d51d2a;
  --red-2: #ff4352;
  --chrome: #d7dbe2;
  --muted: #98a0ad;
  --dark-square: #1d1d24;
  --light-square: #c9c9cf;
  --black-piece: #101015;
  --text: #f5f5f7;
  --good: #30d158;
  --bad: #ff453a;
  --warn: #ffd60a;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(213, 29, 42, 0.28), transparent 32rem),
    radial-gradient(circle at bottom right, rgba(215, 219, 226, 0.16), transparent 28rem),
    linear-gradient(135deg, #050507, #111118 48%, #050507);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  background: rgba(6, 6, 8, 0.88);
  border-bottom: 1px solid rgba(215, 219, 226, 0.16);
  backdrop-filter: blur(14px);
}

.topbar h1 { margin: 0; letter-spacing: 0.03em; }
.topbar p { margin: 0.25rem 0 0; color: var(--muted); }
.topbar nav { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.topbar a, button {
  border: 1px solid rgba(215, 219, 226, 0.24);
  color: white;
  background: linear-gradient(135deg, var(--red), #720911);
  border-radius: 999px;
  padding: 0.68rem 1rem;
  text-decoration: none;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(213, 29, 42, 0.22);
}

button.secondary, .topbar a {
  background: linear-gradient(135deg, rgba(215, 219, 226, 0.18), rgba(255,255,255,0.06));
  box-shadow: none;
}

button:disabled { opacity: 0.55; cursor: not-allowed; }

.shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 1rem;
}

.panel {
  border: 1px solid rgba(215, 219, 226, 0.14);
  border-radius: 1.25rem;
  background: linear-gradient(145deg, var(--panel), rgba(9,9,12,0.86));
  box-shadow: 0 20px 60px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.08);
  padding: 1rem;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.badge {
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-weight: 800;
  background: var(--panel-2);
}
.badge.good { color: var(--good); }
.badge.danger { color: var(--bad); }
.badge.warn { color: var(--warn); }

.join-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto auto;
  gap: 0.75rem;
  align-items: end;
}

label { color: var(--muted); font-weight: 700; }
input {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.75rem 0.9rem;
  border-radius: 0.9rem;
  border: 1px solid rgba(215, 219, 226, 0.24);
  color: var(--text);
  background: rgba(0,0,0,0.32);
}

.room-list-wrap { margin-top: 1rem; }
.room-list { display: grid; gap: 0.75rem; }
.room-list.empty { color: var(--muted); font-style: italic; }
.room-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  align-items: center;
  border: 1px solid rgba(215, 219, 226, 0.14);
  border-radius: 1rem;
  padding: 0.85rem;
  background: rgba(255,255,255,0.045);
}
.room-card strong { display: block; }
.room-card small { color: var(--muted); }

.game-layout {
  display: grid;
  grid-template-columns: minmax(220px, 0.75fr) minmax(320px, 720px) minmax(220px, 0.75fr);
  gap: 1rem;
  margin-top: 1rem;
  align-items: start;
}

.stat {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid rgba(215, 219, 226, 0.1);
}
.stat span { color: var(--muted); }
.message {
  min-height: 3rem;
  border-left: 4px solid var(--red);
  padding: 0.7rem 0.9rem;
  background: rgba(213,29,42,0.1);
  border-radius: 0.75rem;
}

.board-wrap { display: grid; place-items: center; }
.board {
  width: min(86vw, 680px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 10px solid #08080b;
  border-radius: 1.2rem;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,0.48), 0 0 0 1px rgba(215,219,226,0.18);
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  user-select: none;
}
.square.light { background: linear-gradient(145deg, #e3e3e8, #9697a0); }
.square.dark { background: linear-gradient(145deg, #1a1a22, #0c0c10); }
.square.selected { outline: 4px solid var(--warn); outline-offset: -4px; }
.square.legal::after {
  content: "";
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(48, 209, 88, 0.7);
  box-shadow: 0 0 18px rgba(48,209,88,0.35);
}

.piece {
  width: 76%;
  height: 76%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: clamp(1rem, 4vw, 2.25rem);
  font-weight: 900;
  border: 4px solid rgba(255,255,255,0.24);
  box-shadow: inset 0 5px 10px rgba(255,255,255,0.2), inset 0 -9px 18px rgba(0,0,0,0.35), 0 10px 22px rgba(0,0,0,0.42);
}
.piece.red { background: radial-gradient(circle at 35% 25%, #ff7a84, var(--red) 42%, #700710); }
.piece.black { background: radial-gradient(circle at 35% 25%, #62626c, var(--black-piece) 45%, #000); }
.piece.king::before { content: "♛"; color: rgba(255,255,255,0.9); text-shadow: 0 2px 3px rgba(0,0,0,0.5); }

.log {
  max-height: 440px;
  overflow: auto;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
  font-size: 0.92rem;
}
.log-entry {
  border-bottom: 1px solid rgba(215, 219, 226, 0.08);
  padding: 0.5rem 0;
  color: var(--chrome);
}

.admin-shell { display: grid; gap: 1rem; }
.code-box {
  white-space: pre-wrap;
  overflow: auto;
  border-radius: 1rem;
  padding: 1rem;
  color: #d7ffd9;
  background: #050507;
  border: 1px solid rgba(215,219,226,0.14);
}
.notes { line-height: 1.8; color: var(--chrome); }

@media (max-width: 1050px) {
  .game-layout { grid-template-columns: 1fr; }
  .status-panel { order: 1; }
  .board-wrap { order: 2; }
  .log-panel { order: 3; }
}

@media (max-width: 720px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .join-row { grid-template-columns: 1fr; }
  .shell { padding: 0.7rem; }
  .board { width: min(96vw, 680px); border-width: 6px; border-radius: 0.8rem; }
  .panel { border-radius: 1rem; }
  .room-card { grid-template-columns: 1fr; }
}

/* Phase 1.1 admin dashboard polish */
.muted { color: var(--muted); }
.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--red-2);
  font-size: 0.85rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.admin-dashboard { gap: 1rem; }
.admin-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.admin-hero h2 { margin: 0; font-size: clamp(1.6rem, 3vw, 2.55rem); }
.admin-actions,
.control-list,
.command-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}
.admin-grid { display: grid; gap: 1rem; }
.metrics-grid { grid-template-columns: repeat(4, minmax(160px, 1fr)); }
.two-col { grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr); }
.metric-card {
  min-height: 126px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.metric-card span,
.metric-card small { color: var(--muted); }
.metric-card strong {
  display: block;
  margin: 0.35rem 0;
  font-size: clamp(1.65rem, 3vw, 2.45rem);
}
.control-button {
  border: 1px solid rgba(215, 219, 226, 0.18);
  color: var(--text);
  background: rgba(255,255,255,0.055);
  border-radius: 1rem;
  padding: 0.85rem 1rem;
  text-decoration: none;
  font-weight: 850;
}
.control-button:hover,
.room-card:hover { border-color: rgba(255,255,255,0.32); }
.admin-room-card { align-items: start; }
.room-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 1rem;
  margin-top: 0.65rem;
  color: var(--muted);
  font-size: 0.92rem;
}
.room-meta b { color: var(--chrome); }
.admin-log { max-height: 420px; }
.log-entry.error { color: var(--bad); }
.log-entry.info { color: var(--chrome); }

@media (max-width: 1050px) {
  .metrics-grid,
  .two-col { grid-template-columns: 1fr 1fr; }
  .admin-hero { flex-direction: column; align-items: stretch; }
}

@media (max-width: 720px) {
  .metrics-grid,
  .two-col { grid-template-columns: 1fr; }
  .admin-actions,
  .control-list,
  .command-stack { flex-direction: column; }
  .admin-actions button,
  .control-list a,
  .command-stack button { width: 100%; text-align: center; }
}


/* Phase 1.2 movement polish */
.board::before { content: ""; }
.square { touch-action: manipulation; }
.square.dark:hover { filter: brightness(1.18); }
.square.selected {
  outline: 5px solid var(--warn);
  outline-offset: -5px;
  box-shadow: inset 0 0 0 999px rgba(255, 214, 10, 0.10);
}
.square.legal {
  cursor: pointer;
  box-shadow: inset 0 0 0 5px rgba(48, 209, 88, 0.78), inset 0 0 26px rgba(48, 209, 88, 0.38);
}
.square.legal::after {
  content: "MOVE";
  width: auto;
  height: auto;
  min-width: 54%;
  min-height: 32%;
  padding: 0.18rem 0.34rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #031b08;
  background: rgba(48, 209, 88, 0.92);
  box-shadow: 0 0 24px rgba(48,209,88,0.55);
  font-size: clamp(0.48rem, 1.35vw, 0.82rem);
  font-weight: 1000;
  letter-spacing: 0.06em;
  pointer-events: none;
}
.piece { cursor: pointer; }
.piece[draggable="true"] { cursor: grab; }
.piece[draggable="true"]:active { cursor: grabbing; }
.board.flipped .piece::after {
  content: "";
}
.message {
  font-weight: 800;
  line-height: 1.35;
}
@media (max-width: 720px) {
  .square.legal::after { content: ""; min-width: 32%; min-height: 32%; padding: 0; }
}
