:root {
  color-scheme: light;
  --paper: #f4efe6;
  --ink: #1d1b18;
  --muted: #6d665d;
  --line: #d9cfc0;
  --green: #7f9d6a;
  --green-dark: #4d673f;
  --red: #b55343;
  --blue: #4a6f96;
  --light-square: #eadfcf;
  --dark-square: #8c6f52;
  --selected: #f1cc5a;
  --target: #4f7db7;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(74, 111, 150, 0.16), transparent 36%),
    radial-gradient(circle at 80% 10%, rgba(127, 157, 106, 0.18), transparent 28%),
    var(--paper);
}

button, input, a {
  font: inherit;
}

button,
.button-link {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.62);
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.button-link:hover {
  border-color: var(--blue);
}

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

.primary {
  color: white;
  border-color: var(--green-dark);
  background: var(--green-dark);
}

.danger {
  color: white;
  border-color: var(--red);
  background: var(--red);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 22px;
}

h1, h2, h3, p {
  margin: 0;
}

h1 {
  font-size: clamp(32px, 6vw, 68px);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  font-size: 24px;
  line-height: 1.15;
}

h3 {
  font-size: 15px;
  margin-bottom: 10px;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.create-panel {
  display: grid;
  grid-template-columns: minmax(260px, 0.62fr) minmax(420px, 1.38fr);
  gap: 24px;
  align-items: start;
  padding: 28px 0;
  border-top: 1px solid var(--line);
}

.create-panel p,
.status-block p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.links {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.link-row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.link-row input {
  width: 100%;
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.56);
}

.lobby-head {
  display: grid;
  gap: 22px;
  position: sticky;
  top: 18px;
}

.lobby-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.lobby-stats div {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.lobby-stats strong {
  display: block;
  font-size: 32px;
  line-height: 1;
}

.lobby-stats span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.game-list {
  display: grid;
  gap: 12px;
}

.empty-lobby {
  border-top: 1px solid var(--line);
  padding-top: 18px;
  color: var(--muted);
}

.game-card {
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.42);
}

.game-card.finished {
  opacity: 0.76;
}

.mini-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 148px;
  aspect-ratio: 1;
  overflow: hidden;
  border: 4px solid #3b3027;
  border-radius: 6px;
  background: #3b3027;
}

.mini-square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
}

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

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

.mini-square.last::after {
  content: "";
  position: absolute;
  inset: 12%;
  border: 2px solid rgba(74, 111, 150, 0.78);
  border-radius: 3px;
}

.mini-piece {
  position: relative;
  z-index: 1;
  font-size: 15px;
  line-height: 1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.mini-piece.black {
  color: #1f1c19;
}

.mini-piece.white {
  color: #fff9ed;
}

.game-card-content {
  display: grid;
  align-content: start;
  gap: 8px;
  min-width: 0;
}

.game-meta {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.game-meta h3 {
  margin: 0;
  font-size: 18px;
}

.game-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 9px;
  color: white;
  background: var(--green-dark);
  font-size: 12px;
  font-weight: 750;
}

.finished .game-badge {
  background: var(--muted);
}

.game-status {
  font-weight: 750;
}

.game-details {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.game-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.game-card-actions .button-link {
  min-height: 36px;
  padding: 0 11px;
  font-size: 13px;
  font-weight: 650;
}

.game-panel {
  display: grid;
  grid-template-columns: minmax(320px, 760px) minmax(280px, 1fr);
  gap: 26px;
  align-items: start;
}

.board-wrap {
  width: min(760px, 100%);
  aspect-ratio: 1;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border: 10px solid #3b3027;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 22px 60px rgba(55, 39, 22, 0.22);
  background: #3b3027;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  padding: 0;
  min-height: 0;
  font-size: clamp(30px, 8vw, 70px);
  line-height: 1;
  user-select: none;
}

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

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

.square.selected {
  background: var(--selected);
}

.square.last::after {
  content: "";
  position: absolute;
  inset: 8%;
  border: 3px solid rgba(74, 111, 150, 0.78);
  border-radius: 6px;
  pointer-events: none;
}

.square.target::before {
  content: "";
  position: absolute;
  width: 28%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(74, 111, 150, 0.58);
  pointer-events: none;
}

.coord {
  position: absolute;
  left: 5px;
  bottom: 4px;
  color: rgba(29, 27, 24, 0.55);
  font-size: 10px;
  font-weight: 800;
}

.piece {
  position: relative;
  z-index: 1;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.18);
}

.piece.black {
  color: #1f1c19;
}

.piece.white {
  color: #fff9ed;
}

.side {
  display: grid;
  gap: 18px;
  padding-top: 2px;
}

.status-block {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

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

.history {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.history li {
  min-width: 0;
  padding: 4px 0;
}

.promotion-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(29, 27, 24, 0.42);
}

.promotion-modal {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--paper);
  box-shadow: 0 24px 70px rgba(29, 27, 24, 0.26);
}

.promotion-choices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.promotion-choice {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-height: 0;
  font-size: 44px;
}

@media (max-width: 820px) {
  .shell {
    width: min(100vw - 20px, 640px);
    padding-top: 14px;
  }

  .topbar,
  .create-panel,
  .game-panel {
    grid-template-columns: 1fr;
  }

  .lobby-head {
    position: static;
  }

  .topbar {
    display: grid;
  }

  .link-row {
    grid-template-columns: 1fr;
  }

  .game-card {
    grid-template-columns: 108px minmax(0, 1fr);
  }

  .mini-board {
    width: 108px;
  }

  .mini-piece {
    font-size: 12px;
  }

  .board {
    border-width: 6px;
  }

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