* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: #0f1216;
  color: #f5f7fa;
}

.online-lobby {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  padding: 24px 32px 8px;
}

.lobby-panel {
  background: #13171d;
  border-radius: 16px;
  padding: 18px;
  border: 1px solid #1f2630;
  display: grid;
  gap: 12px;
}

.lobby-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.lobby-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.lobby-status {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: #9aa6b2;
}

.room-meta {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: #9aa6b2;
}

.roster {
  display: grid;
  gap: 8px;
  font-size: 13px;
}

.roster-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #0f141a;
  border: 1px solid #1f2630;
}

.online-connected .online-lobby {
  display: none;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 32px 12px;
  border-bottom: 1px solid #1c222b;
}

.app-header h1 {
  margin: 0 0 4px;
  font-size: 28px;
}

.subtle {
  margin: 0;
  color: #9aa6b2;
  font-size: 14px;
}

.status-panel {
  display: grid;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #171c22;
  min-width: 220px;
}

.status-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

.status-row .label {
  color: #8ea0b2;
}

.status-row .value {
  font-weight: 600;
}

.win-banner {
  position: sticky;
  top: 0;
  margin: 0 0 12px;
  padding: 12px 16px;
  text-align: center;
  border-radius: 12px;
  border: 1px solid #273141;
  background: linear-gradient(90deg, #1b2230, #242c3c);
  color: #f5f7fa;
  font-weight: 700;
  letter-spacing: 0.5px;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.win-banner--show {
  opacity: 1;
  transform: translateY(0);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(200px, 0.7fr) minmax(420px, 1.9fr) minmax(220px, 0.9fr);
  grid-template-areas: "pieces place board ai";
  gap: 20px;
  padding: 20px 20px 28px;
  align-items: start;
}

.board-panel {
  background: #101419;
  border-radius: 20px;
  border: 1px solid #1f2630;
  padding: 16px;
  display: grid;
  gap: 16px;
}

.board-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.board-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #c9d3df;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  background: #0f141a;
  border-radius: 16px;
  border: 1px dashed #263140;
  padding: 12px;
  min-height: 360px;
}

.board-cell {
  border: 1px dashed #2c3542;
  border-radius: 12px;
  min-height: 72px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.board-cell--highlight {
  border-color: #8aa6ff;
  box-shadow: 0 0 0 2px rgba(138, 166, 255, 0.25);
}

.board-cell--win {
  border-color: #f8c36a;
  box-shadow: 0 0 0 2px rgba(248, 195, 106, 0.45),
    0 0 18px rgba(248, 195, 106, 0.4);
}

.side-panel {
  display: grid;
  gap: 16px;
}

.side-panel--left {
  order: 0;
}

.panel-pieces {
  grid-area: pieces;
}

.side-panel--center {
  order: 1;
}

.panel-place {
  grid-area: place;
}

.side-panel--right {
  order: 3;
}

.panel-ai {
  grid-area: ai;
}

.panel-board {
  grid-area: board;
}

.card {
  background: #13171d;
  border-radius: 16px;
  padding: 16px;
  border: 1px solid #1f2630;
  display: grid;
  gap: 12px;
}

.card h3 {
  margin: 0;
  font-size: 16px;
}

.helper {
  margin: 0;
  color: #9aa6b2;
  font-size: 12px;
}

.piece-slot {
  min-height: 90px;
  border-radius: 12px;
  border: 1px dashed #2c3542;
  display: grid;
  place-items: center;
  background: #0f141a;
}

.piece-bank {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 10px;
}

.panel-pieces {
  --pieces-light: #f5f5f5;
  --pieces-dark: #121212;
  --pieces-bg: #576270;
}

.panel-pieces .card {
  background: var(--pieces-bg);
}

.panel-pieces .piece--light {
  --faceColor: var(--pieces-light);
  --edgeColor: #d8d8d8;
}

.panel-pieces .piece--dark {
  --faceColor: var(--pieces-dark);
  --edgeColor: #1f1f1f;
}

.color-controls {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
}

.color-controls label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: #9aa6b2;
}

.color-controls input[type="color"] {
  width: 100%;
  height: 30px;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.piece {
  --face: 54px;
  --h-short: 54px;
  --h-tall: 84px;
  --depth: 12px;
  --faceColor: #f5f5f5;
  --edgeColor: #d8d8d8;
  width: var(--face);
  height: var(--h-short);
  position: relative;
  transform-style: preserve-3d;
  transform: perspective(700px) rotateX(-18deg);
  border-radius: 14px;
}

.piece--circle {
  border-radius: 999px;
}

.piece--tall {
  height: var(--h-tall);
}

.piece--short {
  height: var(--h-short);
}

.piece--dark {
  --faceColor: #121212;
  --edgeColor: #1f1f1f;
  color: #f5f5f5;
}

.piece--light {
  --faceColor: #f5f5f5;
  --edgeColor: #d8d8d8;
  color: #121212;
}

.piece::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: var(--face);
  border-radius: inherit;
  background:
    radial-gradient(120% 120% at 30% 25%, rgba(255, 255, 255, 0.25) 0%, rgba(0, 0, 0, 0.12) 100%),
    var(--faceColor);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.35);
  transform: translateZ(var(--depth));
}

.piece::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: calc(var(--h-short) + var(--depth));
  border-radius: inherit;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, rgba(0, 0, 0, 0.28) 70%, rgba(0, 0, 0, 0.45) 100%),
    var(--edgeColor);
  transform: translateZ(0);
  clip-path: polygon(0 38%, 100% 38%, 100% 100%, 0 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.piece--tall::after {
  height: calc(var(--h-tall) + var(--depth));
}

.piece .hole {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  height: calc(var(--face) - 28px);
  border-radius: 999px;
  background: radial-gradient(80% 80% at 30% 25%, rgba(255, 255, 255, 0.1) 0%, rgba(0, 0, 0, 0.1) 35%, rgba(0, 0, 0, 0.55) 100%),
    rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transform: translateZ(calc(var(--depth) + 1px));
}

.piece .hole::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 999px;
  background: radial-gradient(80% 80% at 40% 35%, rgba(255, 255, 255, 0.06) 0%, rgba(0, 0, 0, 0.35) 55%, rgba(0, 0, 0, 0.65) 100%);
  opacity: 0.85;
}

.piece--selected {
  outline: 2px solid #8aa6ff;
  box-shadow: 0 0 0 3px rgba(138, 166, 255, 0.3);
}

select,
button,
input {
  background: #1f2732;
  color: #f5f7fa;
  border: 1px solid #2b3542;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
}

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

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