:root {
  color-scheme: dark;
  --bg: #10100f;
  --ink: #f3efe4;
  --muted: #aaa397;
  --line: rgba(255, 255, 255, 0.12);
  --panel: rgba(34, 33, 30, 0.9);
  --panel-strong: rgba(18, 18, 17, 0.95);
  --accent: #d6a91e;
  --accent-strong: #f4cf55;
  --accent-dark: #8e6411;
  --danger: #ff5a4f;
  --light-square: #d9bb82;
  --dark-square: #8c6040;
  --move: rgba(244, 207, 85, 0.72);
  --last-move: rgba(244, 207, 85, 0.78);
  --king-capture: #c91f1f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 48% 10%, rgba(255, 255, 255, 0.18), transparent 18%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 26px),
    linear-gradient(180deg, #2a2a28 0%, #121211 42%, #0b0b0a 100%);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: rgba(244, 207, 85, 0.48);
  background: rgba(255, 255, 255, 0.11);
}

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

button.primary {
  border-color: var(--accent);
  background: linear-gradient(180deg, #f0c541, #b98516);
  color: #191713;
  font-weight: 700;
}

button.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--accent-strong), #c89418);
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.09);
  color: var(--ink);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.mobile-only {
  display: none;
}

.shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 24px;
}

.topbar {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 18px;
  min-height: 76px;
  margin-bottom: 12px;
}

.brand {
  display: grid;
  gap: 4px;
  justify-items: center;
}

.brand-logo {
  display: block;
  width: min(300px, 24vw);
  max-height: 118px;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 14px 24px rgba(0, 0, 0, 0.52));
}

h1 {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  margin: 0;
}

.topbar p {
  display: none;
}

.main-menu,
.profile {
  display: flex;
  align-items: center;
  gap: 10px;
}

.main-menu button,
.profile button,
.side-menu-action {
  min-height: 42px;
  padding: 0 18px;
  font-weight: 700;
}

.profile strong {
  color: var(--accent-strong);
}

.layout {
  display: grid;
  grid-template-columns: 300px minmax(360px, 680px) minmax(240px, 300px);
  gap: 16px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--panel), rgba(21, 20, 18, 0.92));
  padding: 14px;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.auth-panel {
  grid-column: 1;
}

.captures-sidebar {
  grid-column: 1;
  display: grid;
  gap: 12px;
  align-self: start;
}

.game-area {
  grid-column: 2 / 4;
  display: grid;
  grid-template-columns: minmax(360px, 680px) minmax(240px, 300px);
  gap: 16px;
  align-items: start;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.tab.active {
  border-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 700;
}

.form,
.stack {
  display: grid;
  gap: 12px;
}

.choice-block {
  display: grid;
  gap: 8px;
}

.choice-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.choice-grid.two,
.time-grid {
  grid-template-columns: 1fr 1fr;
}

.choice {
  min-height: 38px;
  padding: 7px 8px;
}

.choice.active {
  border-color: var(--accent);
  color: var(--accent-strong);
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(244, 207, 85, 0.24), 0 0 18px rgba(214, 169, 30, 0.12);
}

.copy-row {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
}

.copy-row button {
  font-size: 20px;
  line-height: 1;
}

.board-shell {
  width: 100%;
}

.board {
  display: grid;
  width: min(100%, 680px);
  aspect-ratio: 1;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  border: 1px solid rgba(244, 207, 85, 0.24);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 22px 52px rgba(0, 0, 0, 0.42), 0 0 0 1px rgba(0, 0, 0, 0.55);
}

.capture-group {
  min-height: 112px;
  border: 1px solid rgba(255, 232, 130, 0.52);
  border-radius: 8px;
  background: linear-gradient(180deg, #f0c541, #b98516);
  padding: 12px;
  color: #191713;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.capture-title {
  display: block;
  margin-bottom: 8px;
  color: rgba(25, 23, 19, 0.78);
  font-size: 13px;
  font-weight: 800;
}

.captured-pieces {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 42px;
}

.captured-pieces.empty::before {
  content: "";
  width: 32px;
  height: 3px;
  border-radius: 999px;
  background: rgba(25, 23, 19, 0.28);
}

.captured-piece-img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.28));
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  padding: 0;
  overflow: hidden;
}

.square.light {
  background: linear-gradient(145deg, #e6c891, var(--light-square));
}

.square.dark {
  background: linear-gradient(145deg, #9a6c48, var(--dark-square));
}

.square.selected::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(244, 207, 85, 0.48);
}

.square.last-move {
  background: linear-gradient(145deg, rgba(244, 207, 85, 0.92), rgba(185, 133, 22, 0.82));
  box-shadow: inset 0 0 0 4px rgba(255, 238, 141, 0.42);
}

.square.king-capture {
  background: var(--king-capture);
}

.square.king-capture .coord {
  color: rgba(255, 255, 255, 0.86);
}

.square.move::before {
  content: "";
  position: absolute;
  width: 34%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: var(--move);
  box-shadow: 0 0 0 5px rgba(185, 133, 22, 0.18), 0 0 18px rgba(244, 207, 85, 0.58);
  z-index: 2;
}

.square .coord {
  position: absolute;
  left: 5px;
  bottom: 4px;
  color: rgba(20, 18, 14, 0.64);
  font-size: 11px;
  font-weight: 700;
  z-index: 3;
}

.skip-turn-img {
  position: absolute;
  width: 84%;
  height: 84%;
  object-fit: contain;
  z-index: 4;
  pointer-events: none;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.34));
}

.piece-img {
  width: 86%;
  height: 86%;
  object-fit: contain;
  z-index: 1;
  pointer-events: none;
}

.hidden-piece-img {
  width: 93%;
  height: 93%;
  object-fit: contain;
  z-index: 1;
  pointer-events: none;
  filter: drop-shadow(0 5px 7px rgba(0, 0, 0, 0.32));
}

.game-panel {
  display: grid;
  gap: 14px;
}

.players {
  display: grid;
  gap: 8px;
}

.player-row {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 28px;
}

.player-clock {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.dot {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1px solid #8a8377;
}

.white .dot {
  background: #ffffff;
}

.black .dot {
  background: #111111;
}

.turn-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 46px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

#timer {
  font-size: 24px;
  letter-spacing: 0;
}

.game-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.game-actions.hidden {
  display: none;
}

.action-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 48px;
  min-height: 38px;
  border-color: rgba(255, 255, 255, 0.08);
  background: #1f211d;
  color: #e8e7df;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.action-icon {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  color: #d9dedb;
  font-size: 23px;
  line-height: 1;
}

.text-action .action-icon {
  color: #d8eff7;
  font-size: 18px;
}

.game-actions.computer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.game-actions.computer .action-button {
  min-height: 60px;
  border-radius: 8px;
  background: rgba(42, 52, 49, 0.86);
}

.game-actions.computer .action-button span:not(.action-icon) {
  display: none;
}

.game-actions.computer .action-icon {
  font-size: 31px;
}

.status {
  min-height: 42px;
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.status.error {
  color: var(--danger);
}

.rematch-box {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.rematch-box.hidden {
  display: none;
}

.rematch-box span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(12, 12, 11, 0.66);
  backdrop-filter: blur(7px);
}

.modal-panel {
  width: min(100%, 390px);
  max-height: min(86vh, 720px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #292824, #171615);
  padding: 18px;
  box-shadow: 0 22px 52px rgba(0, 0, 0, 0.38);
}

.play-panel,
.rules-panel {
  width: min(100%, 440px);
}

.modal-panel h2 {
  margin: 0 0 12px;
  font-size: 22px;
  line-height: 1.15;
}

.modal-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions.single {
  grid-template-columns: 1fr;
}

.rules-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
  line-height: 1.45;
}

.moves {
  display: grid;
  gap: 6px;
  max-height: 220px;
  margin: 0;
  padding-left: 22px;
  overflow: auto;
  color: var(--muted);
}

.menu-button {
  width: 46px;
  min-width: 46px;
  height: 46px;
  padding: 8px;
}

.menu-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.side-menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.48);
}

.side-menu {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 31;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 12px;
  width: min(82vw, 320px);
  padding: 16px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #292824, #141312);
  box-shadow: 18px 0 42px rgba(0, 0, 0, 0.4);
}

.side-menu-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.side-logo {
  width: 188px;
  max-width: calc(100% - 52px);
}

.side-menu-top button {
  width: 42px;
  min-width: 42px;
  font-size: 26px;
  line-height: 1;
}

.mobile-profile {
  align-self: end;
  display: grid;
  gap: 10px;
  justify-items: center;
  text-align: center;
}

.mobile-profile strong {
  color: var(--accent-strong);
  justify-self: center;
}

.mobile-top-user {
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

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

  .layout {
    display: flex;
    flex-direction: column;
  }

  .game-area {
    display: contents;
  }

  .board-shell {
    order: 1;
  }

  .captures-sidebar {
    order: 2;
    width: min(100%, 680px);
    grid-template-columns: 1fr 1fr;
  }

  .game-panel {
    order: 3;
    width: min(100%, 680px);
  }

  .auth-panel {
    order: 4;
    width: min(100%, 420px);
  }
}

@media (max-width: 640px) {
  .desktop-only {
    display: none;
  }

  .mobile-only {
    display: inline-grid;
  }

  .shell {
    width: min(100vw - 20px, 1280px);
    padding: 10px 0 16px;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    min-height: 58px;
    margin-bottom: 10px;
  }

  .brand {
    min-width: 0;
    justify-items: start;
  }

  .brand-logo {
    width: min(160px, 34vw);
    max-height: 56px;
  }

  .topbar p {
    display: none;
  }

  .profile {
    justify-content: flex-end;
    gap: 6px;
    min-width: 0;
  }

  .mobile-top-user,
  .profile:not(.authed) button:first-child {
    display: none;
  }

  .profile strong {
    display: block;
    max-width: 78px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
  }

  .profile button {
    min-height: 38px;
    padding: 0 10px;
    font-size: 13px;
  }

  .panel {
    padding: 12px;
  }

  .captures-sidebar {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .capture-group {
    min-height: 80px;
  }

  .square .coord {
    display: none;
  }

  .modal-actions {
    grid-template-columns: 1fr;
  }
}
