@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600;700&family=Source+Serif+4:wght@400;600&display=swap');

:root {
  --bg: #151718;
  --bg2: #1d1f20;
  --panel: #262522;
  --panel-soft: #2c2b28;
  --accent: #c9a24d;
  --accent2: #6ba7a0;
  --text: #f1f1ef;
  --muted: #9f9f97;
  --danger: #d65f52;
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --line: #3b3935;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(255, 255, 255, 0.05), transparent 60%),
    linear-gradient(180deg, #1b1d1f 0%, var(--bg) 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 32px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.14);
}

.header-meta {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.subtitle {
  font-family: 'Source Serif 4', serif;
  color: var(--muted);
  max-width: 920px;
  line-height: 1.45;
}

.status {
  padding: 8px 12px;
  background: #302e2c;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: #d8d6cf;
  border: 1px solid var(--line);
  white-space: nowrap;
}

.header-stat {
  padding: 7px 12px;
  background: #252422;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.panel {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
  padding: 14px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
}

.panel.wide {
  grid-template-columns: 240px 280px minmax(320px, 1fr);
  align-items: start;
}

.top-rules,
.controls-wide,
.bottom-server {
  padding: 12px 32px 0;
}

.lobby-card {
  display: grid;
  gap: 10px;
  min-height: 100%;
  padding: 6px;
}

.lobby-card h3,
.card h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #42403a;
  background: #201f1d;
  color: var(--text);
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.lobby-actions {
  margin-top: 2px;
}

.challenge-scroll {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid #46433c;
  border-radius: 10px;
  padding: 8px;
  background: #1a1a18;
}

.hidden-clock-controls {
  display: none;
}

#challenge-list,
#my-challenges-list {
  background: #1a1a18;
}

#challenge-list > div,
#my-challenges-list > div {
  color: #10131c;
}

#challenge-list > div strong,
#my-challenges-list > div strong,
#challenge-list > div span,
#my-challenges-list > div span {
  color: #10131c;
}

#challenge-list > div button {
  background: var(--accent2);
  color: #081413;
}

button {
  padding: 10px 14px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #20170a;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

button#join {
  background: var(--accent2);
  color: #081413;
}

button#local-start {
  background: #6b7cf4;
  color: #0b0d12;
}

button#resign {
  background: #e45756;
  color: #fff;
}

button#offer-draw,
button#accept-draw,
button#decline-draw {
  background: #3cc4b7;
  color: #081413;
}

button.draw-offered {
  background: #ffd700;
  color: #000;
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.6);
  font-weight: 700;
}

.game {
  display: grid;
  grid-template-columns: minmax(560px, 1fr) 340px;
  gap: 16px;
  padding: 14px 32px 32px;
  flex: 1;
  align-items: start;
  justify-items: stretch;
  min-height: calc(100vh - 180px);
}

.left-panel {
  width: 100%;
  display: grid;
  gap: 12px;
  align-self: start;
  justify-items: center;
}

.board-wrap {
  display: grid;
  gap: 10px;
  align-items: start;
  justify-items: center;
  width: 100%;
}

.clocks {
  width: min(82vw, 640px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.clock {
  padding: 14px 16px;
  background: #2f2d2a;
  border-radius: 10px;
  border: 1px solid #46433e;
}

.clock-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.9px;
}

.clock-time {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
}

.clock.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.board {
  width: min(82vw, 640px);
  height: min(82vw, 640px);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 8px;
  overflow: hidden;
  border: 10px solid #3a3834;
  box-shadow: 0 22px 36px rgba(0, 0, 0, 0.28);
  touch-action: none;
  overscroll-behavior: contain;
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(22px, 3vw, 34px);
  cursor: pointer;
  position: relative;
  touch-action: none;
}

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

.square.light {
  background: var(--board-light);
}

.square.selected {
  outline: 3px solid #f4a340;
}

.square.flagged::after {
  content: "";
  position: absolute;
  inset: 10%;
  border: 3px solid rgba(201, 162, 77, 0.9);
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(37, 30, 18, 0.55);
  pointer-events: none;
}

.square.target {
  background: #d7c6a4;
}

.piece {
  pointer-events: auto;
  width: clamp(34px, 5vw, 54px);
  height: clamp(34px, 5vw, 54px);
  position: relative;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.45));
  user-select: none;
  -webkit-user-drag: element;
}

.piece.flag-piece::before {
  content: "";
  position: absolute;
  right: 6%;
  top: 4%;
  width: 18%;
  height: 44%;
  background: linear-gradient(180deg, #f1e2a8 0%, #c9a24d 100%);
  clip-path: polygon(0 0, 100% 18%, 100% 72%, 0 56%);
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.piece.flag-piece::after {
  content: "";
  position: absolute;
  right: 24%;
  top: 4%;
  width: 5%;
  height: 48%;
  background: #f1f1ef;
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(34, 30, 24, 0.4);
}

.piece.wK { background-image: url("https://upload.wikimedia.org/wikipedia/commons/4/42/Chess_klt45.svg"); }
.piece.wQ { background-image: url("https://upload.wikimedia.org/wikipedia/commons/1/15/Chess_qlt45.svg"); }
.piece.wR { background-image: url("https://upload.wikimedia.org/wikipedia/commons/7/72/Chess_rlt45.svg"); }
.piece.wB { background-image: url("https://upload.wikimedia.org/wikipedia/commons/b/b1/Chess_blt45.svg"); }
.piece.wN { background-image: url("https://upload.wikimedia.org/wikipedia/commons/7/70/Chess_nlt45.svg"); }
.piece.wP { background-image: url("https://upload.wikimedia.org/wikipedia/commons/4/45/Chess_plt45.svg"); }

.piece.bK { background-image: url("https://upload.wikimedia.org/wikipedia/commons/f/f0/Chess_kdt45.svg"); }
.piece.bQ { background-image: url("https://upload.wikimedia.org/wikipedia/commons/4/47/Chess_qdt45.svg"); }
.piece.bR { background-image: url("https://upload.wikimedia.org/wikipedia/commons/f/ff/Chess_rdt45.svg"); }
.piece.bB { background-image: url("https://upload.wikimedia.org/wikipedia/commons/9/98/Chess_bdt45.svg"); }
.piece.bN { background-image: url("https://upload.wikimedia.org/wikipedia/commons/e/ef/Chess_ndt45.svg"); }
.piece.bP { background-image: url("https://upload.wikimedia.org/wikipedia/commons/c/c7/Chess_pdt45.svg"); }

.square:hover {
  outline: 2px solid rgba(201, 162, 77, 0.7);
}

.sidebar {
  display: grid;
  gap: 10px;
  align-self: start;
  position: sticky;
  top: 14px;
}

.card {
  padding: 14px 16px;
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid #393733;
  min-height: 0;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
}

.hero-card {
  background: linear-gradient(180deg, #2f2d29 0%, #262522 100%);
}

#instructions p,
#log,
.card p,
.card li {
  line-height: 1.45;
}

#moves-card {
  max-height: 280px;
  overflow: auto;
}

#move-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--text);
  font-size: 13px;
  columns: 2;
  column-gap: 18px;
}

#move-list li {
  margin: 2px 0;
  color: var(--muted);
}

#move-list li.latest {
  color: var(--text);
  font-weight: 600;
}

.square.last-move {
  outline: 3px solid rgba(60, 196, 183, 0.7);
  z-index: 1;
}
#log-card {
  min-height: 110px;
}

#log {
  font-size: 14px;
  color: var(--muted);
  white-space: pre-line;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 15, 0.92);
  display: grid;
  place-items: center;
  z-index: 50;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  background: #151a27;
  padding: 28px 32px;
  border-radius: 16px;
  border: 1px solid #2a3246;
  text-align: center;
  max-width: 360px;
}

.overlay-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.overlay-text {
  color: var(--muted);
  margin-bottom: 18px;
}

footer {
  padding: 16px 32px 24px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
}

@media (max-width: 900px) {
  header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-meta {
    justify-items: start;
  }

  .panel.wide {
    grid-template-columns: 1fr;
  }

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

  .sidebar {
    position: static;
  }

  .board {
    width: min(94vw, 560px);
    height: min(94vw, 560px);
  }

  .clocks {
    width: min(94vw, 560px);
  }

  .left-panel {
    justify-items: stretch;
  }
  .top-rules,
  .controls-wide,
  .bottom-server {
    padding: 8px 16px 0;
  }

  #move-list {
    columns: 1;
  }
}
