:root {
  --editorial-bg: #1d1d1b;
  --editorial-surface: #242421;
  --editorial-text: #f1f0ea;
  --editorial-muted: #9b9990;
  --editorial-soft: #c7c2b7;
  --editorial-rule: #3c3b36;
  --editorial-accent: #e8e0d0;
  --board-light: #e8e0d0;
  --board-dark: #6f6b60;
  --selected: #f1f0ea;
  --legal: rgba(232, 224, 208, 0.74);
  --sidebar-width: 286px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  color: var(--editorial-text);
  background:
    radial-gradient(circle at 78% 12%, rgba(232, 224, 208, 0.06), transparent 28rem),
    var(--editorial-bg);
  font-family: 'Newsreader', Georgia, serif;
  font-size: 19px;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  gap: 28px;
  padding: 28px;
}

.sidebar {
  min-height: calc(100svh - 56px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 28px;
  padding: 4px 0;
  border-right: 1px solid var(--editorial-rule);
}

.kicker {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 26px;
  color: #85837c;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
  line-height: 1.2;
  text-transform: uppercase;
}

.kicker span {
  width: 34px;
  height: 1px;
  background: #77756f;
  display: inline-block;
}

.brand {
  margin: 0;
  max-width: 220px;
  color: var(--editorial-text);
  font-family: 'Newsreader', Georgia, serif;
  font-size: clamp(2.4rem, 5vw, 4rem);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 0.95;
}

.subtitle {
  margin: 18px 0 28px;
  max-width: 220px;
  color: var(--editorial-soft);
  font-size: 1.08rem;
  font-style: italic;
  line-height: 1.42;
}

.status {
  margin: 0;
  padding-top: 20px;
  border-top: 1px solid var(--editorial-rule);
  color: var(--editorial-accent);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  line-height: 1.45;
  text-transform: uppercase;
}

.sidebar-bottom,
.controls,
.moves,
.captured-panel,
.history-panel,
.color-panel {
  display: grid;
  gap: 12px;
}

.sidebar-bottom {
  padding-right: 28px;
}

.controls {
  align-self: stretch;
}

.captured-panel,
.moves,
.history-panel,
.color-panel {
  padding-top: 22px;
  border-top: 1px solid var(--editorial-rule);
  color: var(--editorial-muted);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.8;
  text-transform: uppercase;
}

.captured-row {
  display: grid;
  gap: 4px;
}

.captured-pieces {
  min-height: 28px;
  color: var(--editorial-text);
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", serif;
  font-size: 1.35rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  line-height: 1.2;
  text-transform: none;
  word-break: break-word;
}

.moves strong {
  color: var(--editorial-text);
  letter-spacing: 0.02em;
  text-transform: none;
}

.move-history {
  max-height: 168px;
  overflow-y: auto;
  padding-right: 6px;
  color: var(--editorial-text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.65;
  text-transform: none;
}

.history-row {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  gap: 10px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(60, 59, 54, 0.5);
}

.history-number {
  color: var(--editorial-muted);
}

button {
  width: 100%;
  height: 58px;
  border: 1px solid var(--editorial-accent);
  border-radius: 0;
  padding: 0 16px;
  color: var(--editorial-bg);
  background: var(--editorial-accent);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.13em;
  line-height: 58px;
  text-align: center;
  text-transform: uppercase;
  cursor: pointer;
  transition: filter 180ms ease, transform 180ms ease;
}
button:hover,
button:focus {
  filter: brightness(1.06);
}
button:active {
  transform: translateY(1px);
}

.color-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.color-button {
  height: 40px;
  padding: 0 8px;
  border-color: var(--editorial-rule);
  color: var(--editorial-text);
  background: transparent;
  font-size: 10px;
  letter-spacing: 0.08em;
  line-height: 40px;
}

.color-button.active,
.color-button:hover,
.color-button:focus {
  border-color: var(--editorial-accent);
  color: var(--editorial-bg);
  background: var(--editorial-accent);
  filter: none;
}

.board-wrap {
  min-width: 0;
  min-height: calc(100svh - 56px);
  display: grid;
  place-items: center;
}

.board {
  width: min(calc(100vw - var(--sidebar-width) - 84px), calc(100svh - 56px));
  height: min(calc(100vw - var(--sidebar-width) - 84px), calc(100svh - 56px));
  min-width: 280px;
  min-height: 280px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  overflow: hidden;
  border: 1px solid var(--editorial-rule);
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.28);
}

.square {
  position: relative;
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  border: 0;
  display: block;
  font-family: 'Newsreader', Georgia, serif;
  font-size: clamp(1.8rem, 8.3vmin, 5rem);
  line-height: 1;
  cursor: pointer;
  transition: filter 140ms ease, box-shadow 140ms ease;
  padding: 0;
  overflow: hidden;
  border-radius: 0;
}

.piece {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  color: #1d1d1b;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", serif;
  font-size: 0.86em;
  line-height: 1;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transform-origin: center;
}

.square:hover { filter: brightness(1.08); }
.square.light { background: var(--board-light); }
.square.dark { background: var(--board-dark); }
.square.light,
.square.dark { color: #1d1d1b; }
.square.last-move {
  box-shadow: inset 0 0 0 999px rgba(241, 240, 234, 0.22);
}
.square.selected {
  outline: 1px solid var(--selected);
  outline-offset: -7px;
  box-shadow: inset 0 0 0 3px rgba(29, 29, 27, 0.34);
}
.square.last-move.selected {
  box-shadow:
    inset 0 0 0 999px rgba(241, 240, 234, 0.22),
    inset 0 0 0 3px rgba(29, 29, 27, 0.34);
}
.square.in-check {
  box-shadow: inset 0 0 0 999px rgba(150, 45, 45, 0.48);
}
.square.in-check.last-move {
  box-shadow:
    inset 0 0 0 999px rgba(150, 45, 45, 0.48),
    inset 0 0 0 7px rgba(241, 240, 234, 0.34);
}
.square.legal::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22%;
  height: 22%;
  border-radius: 999px;
  background: var(--legal);
  box-shadow: 0 0 0 1px rgba(29, 29, 27, 0.24);
  transform: translate(-50%, -50%);
}
.square.legal.occupied::after {
  top: 50%;
  left: 50%;
  width: 78%;
  height: 78%;
  background: transparent;
  border: 2px solid var(--legal);
  transform: translate(-50%, -50%);
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    gap: 14px;
    padding: 14px;
  }

  .sidebar {
    min-height: auto;
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 14px;
    padding: 0 0 14px;
    border-right: 0;
    border-bottom: 1px solid var(--editorial-rule);
  }

  .kicker,
  .subtitle,
  .captured-panel,
  .history-panel,
  .moves { display: none; }

  .sidebar-bottom {
    padding-right: 0;
  }

  .brand {
    max-width: none;
    font-size: 2rem;
  }

  .status {
    margin-top: 8px;
    padding-top: 8px;
    font-size: 11px;
  }

  .controls {
    display: flex;
    width: max-content;
  }

  .board-wrap { min-height: auto; }
  .board {
    width: min(calc(100vw - 28px), calc(100svh - 116px));
    height: min(calc(100vw - 28px), calc(100svh - 116px));
  }
}

@media (max-width: 560px) {
  body { font-size: 17px; }
  .sidebar {
    grid-template-columns: 1fr;
  }
  .controls { width: 100%; }
  button { flex: 1; }
}
