/* Yard Chess, a charcoal club room: a rail on the left, the board as the room's
   centre, green for the one thing you should press next. */

:root {
  color-scheme: dark;

  --bg: #302e2b;
  --rail: #262522;
  --panel: #262522;
  --panel-2: #1f1e1c;
  --raise: #3b3936;
  --raise-hi: #45423e;
  --line: #3d3a36;

  --ink: #ffffff;
  --ink-2: #c3c2c0;
  --ink-3: #8b8987;

  --green: #81b64c;
  --green-hi: #95c95c;
  --green-edge: #537d34;
  --red: #e0584a;
  --red-edge: #a33a2f;
  --amber: #f0c15c;

  --sq-light: #ebecd0;
  --sq-dark: #739552;
  --sq-mark: rgba(255, 255, 51, 0.46);
  --sq-dot: rgba(0, 0, 0, 0.16);

  --radius: 8px;
  --radius-sm: 5px;
  --rail-w: 188px;
  --side-w: 360px;

  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: -0.01em;
}

svg {
  flex: none;
}

.muted {
  color: var(--ink-3);
}

:focus-visible {
  outline: 2px solid var(--green-hi);
  outline-offset: 2px;
}

/* ── Shell ────────────────────────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  min-height: 100%;
}

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 10px;
  background: var(--rail);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 16px;
  color: var(--ink);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.03em;
  text-decoration: none;
}

.brand-mark {
  width: 30px;
  height: 30px;
  fill: var(--green);
}

.rail-links {
  display: grid;
  gap: 2px;
}

.rail-link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink-2);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.rail-link svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rail-link:hover {
  background: var(--panel-2);
  color: var(--ink);
}

.rail-link.is-active {
  background: var(--panel-2);
  color: var(--ink);
}

.rail-link.is-active svg {
  stroke: var(--green);
}

.profile-btn {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.profile-btn:hover {
  background: var(--panel-2);
}

.avatar,
.seat-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 4px;
  background: #5d7a3c;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  flex: none;
}

.seat-avatar.is-empty {
  background: var(--raise);
  color: var(--ink-3);
}

.avatar-lg {
  width: 64px;
  height: 64px;
  font-size: 22px;
  border-radius: 6px;
}

.profile-meta {
  display: grid;
  min-width: 0;
  line-height: 1.25;
}

.profile-name {
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-record {
  font-size: 12px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.stage {
  padding: 20px 24px 32px;
  min-width: 0;
}

.view[hidden] {
  display: none;
}

/* ── Board area (shared by lobby and game) ────────────────────────────── */

.lobby,
.game {
  --size: min(calc(100vh - 150px), calc(100vw - var(--rail-w) - var(--side-w) - 88px), 760px);
  display: grid;
  grid-template-columns: auto var(--side-w);
  gap: 24px;
  justify-content: center;
  align-items: start;
}

.board-area {
  display: grid;
  gap: 8px;
  width: var(--size);
}

.player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.player-meta {
  display: grid;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.seat-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.seat-name {
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-sub {
  font-size: 12px;
  color: var(--ink-3);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--ink-3);
  flex: none;
}

.dot[data-connected="true"] {
  background: var(--green);
}

/* Clocks read like chess.com's: a light box for white, a dark one for black,
   full strength only while it is running. */
.clock {
  min-width: 118px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: #989795;
  color: rgba(38, 37, 34, 0.72);
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  letter-spacing: 0.01em;
}

.player[data-color="black"] .clock {
  background: #21201d;
  color: rgba(255, 255, 255, 0.55);
}

.player.is-turn .clock {
  background: #fff;
  color: #262522;
}

.player.is-turn[data-color="black"] .clock {
  background: #1a1917;
  color: #fff;
  box-shadow: inset 0 0 0 1px #5a5752;
}

.clock.low,
.player.is-turn .clock.low {
  background: var(--red);
  color: #fff;
  box-shadow: none;
}

.clock[hidden] {
  display: none;
}

.captured {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 21px;
}

.capture-group {
  display: flex;
}

.capture-group .piece {
  width: 21px;
  height: 21px;
  margin-right: -8px;
  cursor: default;
}

/* Off the board the black pieces sit on charcoal, so they get a light edge. */
.capture-group .piece.b svg {
  stroke: #b3b1ad;
}

.capture-group .piece.b .detail,
.capture-group .piece.b .eye {
  display: none;
}

.capture-group .piece:last-child {
  margin-right: 0;
}

.material {
  margin-left: 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-3);
}

/* ── Board ────────────────────────────────────────────────────────────── */

.board-frame {
  position: relative;
  border-radius: 4px;
  overflow: hidden;
}

.board {
  width: var(--size);
  height: var(--size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  touch-action: none;
  user-select: none;
}

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

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

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

.sq .coord {
  position: absolute;
  font-size: calc(var(--size) / 48);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.sq .coord-file {
  bottom: 4%;
  right: 5%;
}

.sq .coord-rank {
  top: 4%;
  left: 5%;
}

.sq.light .coord {
  color: var(--sq-dark);
}

.sq.dark .coord {
  color: var(--sq-light);
}

.sq.last::after,
.sq.selected::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--sq-mark);
  pointer-events: none;
}

.sq.target::before {
  content: "";
  position: absolute;
  width: 32%;
  height: 32%;
  border-radius: 999px;
  background: var(--sq-dot);
  pointer-events: none;
  z-index: 4;
}

.sq.target.occupied::before {
  width: 100%;
  height: 100%;
  background: none;
  box-shadow: inset 0 0 0 calc(var(--size) / 100) var(--sq-dot);
}

.sq.target:hover::before {
  width: 100%;
  height: 100%;
  border-radius: 0;
  background: none;
  box-shadow: inset 0 0 0 calc(var(--size) / 160) rgba(255, 255, 255, 0.7);
}

.sq.check::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, #ff2a1a 0%, rgba(231, 32, 20, 0.75) 32%, transparent 72%);
  pointer-events: none;
}

.piece {
  position: relative;
  z-index: 3;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

.board-static .piece {
  cursor: default;
}

.piece svg {
  display: block;
  width: 100%;
  height: 100%;
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.piece.w svg {
  fill: #f9f9f7;
  stroke: #2c2a27;
}

.piece.b svg {
  fill: #3a3835;
  stroke: #121110;
}

.piece .detail {
  fill: none;
}

.piece.b .detail {
  stroke: #cfcdc8;
  stroke-width: 1.1;
}

.piece.w .eye {
  fill: #2c2a27;
  stroke: none;
}

.piece.b .eye {
  fill: #cfcdc8;
  stroke: none;
}

.board .piece svg {
  filter: drop-shadow(0 1.5px 0 rgba(0, 0, 0, 0.18));
}

.piece.dragging {
  opacity: 0.3;
}

.drag-ghost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  cursor: grabbing;
  transform: translate(-50%, -50%);
}

.board-veil {
  position: absolute;
  inset: 0;
  background: rgba(20, 19, 17, 0.4);
  z-index: 5;
}

/* ── Cards ────────────────────────────────────────────────────────────── */

.card {
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.card-head {
  padding: 26px 22px 6px;
  text-align: center;
}

.card-head h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.025em;
}

.lede {
  margin: 8px auto 0;
  max-width: 30ch;
  color: var(--ink-2);
  font-size: 14px;
}

.card-body {
  padding: 18px 22px 22px;
}

.card-section {
  padding: 16px 22px 18px;
  border-top: 1px solid var(--line);
}

.section-title,
.field-label {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}

/* ── Time controls ────────────────────────────────────────────────────── */

.tc-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.chip {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  padding: 12px;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--raise);
  color: var(--ink-3);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.chip svg {
  grid-row: span 2;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chip strong {
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.chip span {
  font-size: 12px;
}

.chip:hover {
  background: var(--raise-hi);
}

.chip.is-selected {
  border-color: var(--green);
  background: #3a4430;
  color: var(--green-hi);
}

/* ── Buttons ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--raise);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.28);
  color: var(--ink-2);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}

.btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn:hover:not(:disabled) {
  background: var(--raise-hi);
  color: var(--ink);
}

.btn:active:not(:disabled) {
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.28);
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--green);
  box-shadow: inset 0 -4px 0 var(--green-edge);
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

.btn-primary:hover:not(:disabled) {
  background: var(--green-hi);
  color: #fff;
}

.btn-primary:active:not(:disabled) {
  box-shadow: inset 0 -1px 0 var(--green-edge);
}

.btn-danger.is-armed,
.btn-danger.is-armed:hover:not(:disabled) {
  background: var(--red);
  box-shadow: inset 0 -3px 0 var(--red-edge);
  color: #fff;
}

.btn-xl {
  width: 100%;
  padding: 18px 16px 22px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  border-radius: 8px;
}

.half {
  font-size: 17px;
  line-height: 1;
}

.linkish {
  background: none;
  border: 0;
  padding: 0;
  color: var(--ink-3);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.linkish:hover {
  color: var(--ink);
}

.hint {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--ink-3);
  text-align: center;
}

.hint-link {
  color: var(--ink-2);
  font-weight: 700;
}

.hint-link:hover {
  color: var(--ink);
}

.icon-btn {
  background: none;
  border: 0;
  color: var(--ink-3);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

.icon-btn:hover {
  color: var(--ink);
  background: var(--raise);
}

/* ── Game side panel ──────────────────────────────────────────────────── */

.side {
  display: flex;
  flex-direction: column;
  height: calc(var(--size) + 116px);
  max-height: calc(100vh - 52px);
}

.status {
  padding: 18px 18px 16px;
  background: var(--panel-2);
  text-align: center;
}

.status-line {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.015em;
}

.status-sub {
  margin: 2px 0 0;
  min-height: 1.4em;
  font-size: 13px;
  color: var(--ink-3);
}

.status.is-over .status-line {
  color: var(--green-hi);
}

.share,
.offer {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.share-row {
  display: flex;
  gap: 8px;
}

.share-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

.share-row input:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: -1px;
}

.share .linkish {
  margin-top: 12px;
}

.offer {
  background: #3a4430;
}

.offer p {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 700;
}

.offer-actions {
  display: flex;
  gap: 8px;
}

.offer-actions .btn {
  flex: 1;
}

.moves-head {
  padding: 12px 18px 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}

.moves-wrap {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
}

.moves {
  margin: 0;
  padding: 0 0 8px;
  list-style: none;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.moves li {
  display: grid;
  grid-template-columns: 44px 1fr 1fr;
  align-items: center;
  padding: 2px 10px 2px 18px;
}

.moves li:nth-child(even) {
  background: rgba(255, 255, 255, 0.025);
}

.moves .no {
  color: var(--ink-3);
}

.moves .san {
  justify-self: start;
  padding: 3px 7px;
  border-radius: 3px;
  font-weight: 600;
  color: var(--ink-2);
}

.moves .san.latest {
  background: var(--raise-hi);
  color: var(--ink);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25);
}

.moves .empty {
  display: block;
  padding: 20px 18px;
  color: var(--ink-3);
  text-align: center;
}

.actions {
  display: flex;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}

.actions .btn {
  flex: 1;
}

.actions .btn[hidden] {
  display: none;
}

.back {
  align-self: center;
  padding: 0 0 16px;
}

/* ── Game list ────────────────────────────────────────────────────────── */

.game-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.game-list li {
  display: grid;
  grid-template-columns: 50px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-2);
}

.game-list li:first-child {
  border-top: 0;
}

.game-list li.empty {
  display: block;
  text-align: center;
  padding: 14px;
  color: var(--ink-3);
}

.tag {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 0;
  border-radius: 3px;
  text-align: center;
  color: #fff;
}

.tag.win {
  background: var(--green);
}

.tag.loss {
  background: var(--red);
}

.tag.draw {
  background: #7a7874;
}

.game-list .when {
  color: var(--ink-3);
  font-size: 12px;
}

/* ── Dialogs ──────────────────────────────────────────────────────────── */

.dialog {
  width: min(440px, calc(100vw - 32px));
  border: 0;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  padding: 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.dialog-sm {
  width: min(340px, calc(100vw - 32px));
  text-align: center;
}

.dialog::backdrop {
  background: rgba(10, 10, 9, 0.7);
}

.dialog-close-form {
  position: absolute;
  top: 12px;
  right: 12px;
  margin: 0;
}

.dialog-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.dialog-head h2 {
  font-size: 22px;
  font-weight: 800;
}

.dialog-head p {
  margin: 2px 0 0;
  font-size: 13px;
}

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

.record-cell {
  display: grid;
  gap: 2px;
  padding: 14px 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  text-align: center;
  border-bottom: 3px solid transparent;
}

.record-cell.win {
  border-bottom-color: var(--green);
}

.record-cell.loss {
  border-bottom-color: var(--red);
}

.record-cell.draw {
  border-bottom-color: #7a7874;
}

.record-cell strong {
  font-size: 28px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.record-cell span {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
}

.record-total {
  margin: 10px 0 0;
  font-size: 13px;
  text-align: center;
}

.account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 22px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
}

.account p {
  margin: 0;
  font-size: 13px;
}

.name-form {
  margin-top: 22px;
}

.dialog-section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.promo-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.promo-btn {
  aspect-ratio: 1;
  padding: 6px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--sq-light);
  cursor: pointer;
}

.promo-btn:nth-child(even) {
  background: var(--sq-dark);
}

.promo-btn:hover {
  box-shadow: inset 0 0 0 3px var(--green-hi);
}

.promo-btn .piece {
  cursor: pointer;
}

/* ── Toast ────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  margin: 0;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  background: #fff;
  color: #262522;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  z-index: 60;
}

/* ── Narrower screens ─────────────────────────────────────────────────── */

@media (max-width: 1180px) {
  :root {
    --rail-w: 64px;
    --side-w: 320px;
  }

  .brand span,
  .rail-link span,
  .profile-meta {
    display: none;
  }

  .brand,
  .rail-link,
  .profile-btn {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    position: sticky;
    z-index: 20;
    height: 56px;
    flex-direction: row;
    align-items: center;
    padding: 0 12px;
  }

  .brand {
    padding: 0;
  }

  .brand span {
    display: inline;
  }

  .rail-links {
    display: flex;
    margin-left: auto;
  }

  .rail-link {
    width: auto;
    padding: 8px 10px;
  }

  .profile-btn {
    width: auto;
    margin: 0;
    padding: 4px;
  }

  .stage {
    padding: 12px 16px 28px;
  }

  .lobby,
  .game {
    --size: min(calc(100vw - 32px), 600px);
    grid-template-columns: minmax(0, var(--size));
  }

  .lobby .play-card {
    order: -1;
  }

  .side {
    height: auto;
    max-height: none;
  }

  .moves-wrap {
    max-height: 200px;
  }

  .clock {
    min-width: 96px;
    font-size: 19px;
  }
}
