:root {
  --dark: #7a4a2b;
  --light: #f0d9b5;
  --accent: #16a34a;
  --accent-hover: #15803d;
  --red-piece: #c0392b;
  --black-piece: #222;
  --highlight: #f6d743;
  --bg: #111214;
  --panel: #1b1d21;
  --panel-2: #202329;
  --line: #30343b;
  --text: #f3f4f6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(22, 163, 74, 0.16), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: 32px 16px;
}

.wrap { width: 100%; max-width: 480px; margin: 0 auto; }
.wrap.narrow { max-width: 420px; }
.wrap.wide { max-width: 1040px; }
.wrap.game-wrap { max-width: 1080px; }

header h1 {
  font-size: 1.6rem;
  margin: 0 0 20px;
}
header h1 span {
  font-weight: 400;
  color: #999;
  font-size: 1rem;
  display: block;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}
.topbar h1 { margin-bottom: 4px; }
.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.muted {
  margin: 0;
  color: #aaa;
  font-size: 0.9rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(320px, 1.3fr);
  gap: 16px;
  align-items: start;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(360px, 1.1fr);
  gap: 16px;
  align-items: start;
}
.hero-panel {
  min-height: 220px;
  display: grid;
  align-content: space-between;
  gap: 24px;
  padding: 24px;
  border-radius: 14px;
  border: 1px solid rgba(22, 163, 74, 0.35);
  background: linear-gradient(145deg, rgba(22, 163, 74, 0.18), rgba(32, 35, 41, 0.92));
}
.hero-panel h2 {
  margin: 0 0 8px;
  font-size: 1.8rem;
  letter-spacing: 0;
}
.eyebrow {
  margin: 0 0 8px;
  color: #8dd9a7;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.control-panel {
  grid-column: 1;
}
.live-panel {
  grid-column: 2;
  grid-row: 1 / span 2;
}
.leaderboard-panel {
  grid-column: 1 / -1;
}
.layout .panel:last-child {
  grid-column: 1 / -1;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 280px;
  gap: 16px;
  align-items: start;
}
.profile-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(360px, 1.2fr);
  gap: 16px;
  align-items: start;
}
.wallet-profile {
  grid-row: span 2;
}
.wallet-profile h3 {
  margin: 18px 0 10px;
  font-size: 0.95rem;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.stat-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  display: grid;
  gap: 6px;
}
.stat-card span {
  color: #aaa;
  font-size: 0.82rem;
}
.stat-card strong {
  font-size: 1.5rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.18);
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.hidden { display: none; }

.btn {
  background: #2a2e35;
  color: var(--text);
  border: none;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  width: 100%;
}
.btn:hover { background: #3d3d3d; }
.btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.btn.primary { background: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: #8f2f27; }
.btn.danger:hover { background: #74251f; }
.btn.small {
  width: auto;
  padding: 8px 10px;
  font-size: 0.85rem;
}
.btn.secondary {
  background: #242832;
  border: 1px solid var(--line);
}
.link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 10px;
  background: #242832;
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}

.or {
  text-align: center;
  color: #777;
  margin: 14px 0;
  font-size: 0.85rem;
}

.join-row {
  display: flex;
  gap: 8px;
}
.profile-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.join-row input,
.profile-row input,
.field input,
.field select,
.join-row select {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #131519;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 1rem;
}
.field select {
  appearance: none;
}
.join-row select {
  min-width: 160px;
}
.field.compact {
  margin-bottom: 8px;
}
.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}
.field span {
  color: #ccc;
  font-size: 0.9rem;
}
.auth-switch {
  margin: 14px 0 0;
  color: #aaa;
  font-size: 0.9rem;
}
.auth-switch a {
  color: #8dd9a7;
  text-decoration: none;
  font-weight: 700;
}
.profile-row input {
  text-transform: none;
  letter-spacing: 0;
}
.profile-row .btn {
  width: auto;
  flex-shrink: 0;
}

.room-browser {
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.room-browser h2 {
  margin: 0 0 10px;
  font-size: 0.95rem;
}
.room-list {
  display: grid;
  gap: 8px;
}
.empty-list {
  margin: 0;
  color: #888;
  font-size: 0.9rem;
}
.room-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.room-details {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.room-details strong {
  letter-spacing: 1px;
}
.room-details span {
  color: #aaa;
  font-size: 0.8rem;
  line-height: 1.35;
}
.room-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.msg {
  margin-top: 12px;
  min-height: 1.2em;
  font-size: 0.9rem;
  color: #f1c40f;
}

.game-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-size: 0.9rem;
  flex-wrap: wrap;
  gap: 8px;
}
.turn-label {
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: #333;
}
.turn-label.your-turn {
  background: var(--accent);
  color: #fff;
}

.board-panel {
  min-width: 0;
}
.match-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.player-card {
  display: grid;
  gap: 2px;
  min-height: 46px;
  padding: 9px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.player-card strong,
.player-card span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-card span {
  color: #aaa;
  font-size: 0.8rem;
}
.board-shell {
  max-width: 680px;
  margin: 0 auto;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 4px solid #4a2f1c;
  border-radius: 6px;
  overflow: hidden;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.square.light { background: var(--light); }
.square.dark { background: var(--dark); }
.square.selectable::after {
  content: "";
  position: absolute;
  width: 22%;
  height: 22%;
  border-radius: 50%;
  background: var(--highlight);
  opacity: 0.85;
}
.square.playable .piece {
  outline: 3px solid #8dd9a7;
  outline-offset: 3px;
}
.square.selected { outline: 3px solid var(--highlight); outline-offset: -3px; }

.piece {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  box-shadow: 0 3px 5px rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
}
.piece.black { background: var(--black-piece); border: 2px solid #000; }
.piece.red { background: var(--red-piece); border: 2px solid #7a1f13; }
.piece.king { color: gold; font-weight: bold; }
.wallet-withdraw {
  margin-top: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(90px, 0.6fr) auto;
}

.side-panel {
  display: grid;
  gap: 14px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #3a3a40;
}
.stat-row span {
  color: #aaa;
}
.captured-grid {
  display: grid;
  gap: 14px;
}
.captured-pieces {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
  margin-top: 8px;
}
.mini-piece {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 2px 4px rgba(0,0,0,0.35);
}
.mini-piece.black { background: var(--black-piece); border: 1px solid #000; }
.mini-piece.red { background: var(--red-piece); border: 1px solid #7a1f13; }

@media (max-width: 820px) {
  body { padding: 20px 12px; }
  .topbar,
  .layout,
  .dashboard-grid,
  .profile-grid,
  .game-layout {
    grid-template-columns: 1fr;
  }
  .topbar {
    display: grid;
  }
  .layout .panel:last-child {
    grid-column: auto;
  }
  .control-panel,
  .live-panel,
  .leaderboard-panel {
    grid-column: auto;
    grid-row: auto;
  }
  .match-strip {
    grid-template-columns: 1fr;
  }
}
