:root {
  /* Warm, low-saturation neutrals so the board is the most colourful thing on screen,
     and one green accent reserved for primary actions. */
  --bg: #302e2b;
  --panel: #262522;
  --panel-2: #3a3835;
  --line: #45423e;
  --text: #f2f1ef;
  --muted: #a8a6a2;
  --accent: #81b64c;
  --accent-hi: #a3d160;
  --accent-edge: #45753c;
  --accent-ink: #ffffff;
  --gold: #ffd166;
  --danger: #ff6b6b;
  --lt: #dfe4ec;
  --dk: #7d8ca3;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }

/* ---------- chrome ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; border-bottom: 1px solid var(--line);
  background: rgba(38, 37, 34, .96); backdrop-filter: blur(8px);
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: -.01em; text-decoration: none; }
.logo b { color: var(--accent); }
.logo-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.top nav a { color: var(--muted); text-decoration: none; }
.top nav a:hover { color: var(--text); }
main { max-width: 1260px; margin: 0 auto; padding: 24px 16px 48px; }
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 16px 40px; }

/* ---------- home ---------- */
.hero { padding: 28px 0 30px; }
.hero h1 { font-size: clamp(34px, 6vw, 60px); line-height: 1.04; margin: 0 0 14px; letter-spacing: -.025em; }
.hero h1 span { color: var(--accent); }
.hero p { color: var(--muted); max-width: 640px; font-size: 17px; margin: 0; }
.group { margin: 8px 0 36px; }
.group h2 { font-size: 26px; margin: 0 0 4px; letter-spacing: -.01em; display: flex; align-items: baseline; gap: 10px; }
.group h2 small { font-size: 14px; color: var(--muted); font-weight: 500; }
.group-sub { color: var(--muted); margin: 0 0 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.card {
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line);
  text-decoration: none; transition: transform .12s, border-color .12s, background .12s;
}
.card:hover, .card:focus-visible { transform: translateY(-2px); border-color: var(--accent); background: var(--panel-2); outline: none; }
.thumb { position: relative; aspect-ratio: 16 / 9; background: var(--panel-2); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.card:hover .thumb img { transform: scale(1.04); }
.card-body { padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 4px; }
.card h3 { margin: 0; font-size: 17px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }

/* credits */
.credits { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.credits li { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; font-size: 13px; color: var(--muted); }
.credits img { width: 96px; height: 54px; object-fit: cover; border-radius: 6px; flex: none; }
.credits b { color: var(--text); }
.credits a { color: var(--accent); word-break: break-word; }

/* ---------- game layout ---------- */
.game { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.board-col { display: flex; flex-direction: column; align-items: center; min-width: 0; }
@media (max-width: 920px) { .game { grid-template-columns: 1fr; } }

.board {
  --w: 8; --ar: 1;
  width: min(100%, calc((100vh - 210px) * var(--ar)));
  aspect-ratio: var(--ar);
  display: grid; position: relative; border-radius: 3px; overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .3);
  container-type: inline-size; user-select: none; -webkit-user-select: none; touch-action: none;
}
.board.twin { box-shadow: none; overflow: visible; }
@media (max-width: 920px) { .board { width: min(100%, calc((100vh - 170px) * var(--ar))); } }

.sq { position: relative; display: grid; place-items: center; cursor: pointer; background: var(--lt); min-width: 0; }
.sq.dk { background: var(--dk); }
.sq::before, .sq::after { pointer-events: none; }
.sq.last::before { content: ""; position: absolute; inset: 0; background: rgba(255, 209, 102, .4); }
.sq.sel::before { content: ""; position: absolute; inset: 0; background: rgba(124, 196, 255, .6); }
.sq.dest::after { content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: rgba(15, 25, 45, .4); z-index: 2; }
.sq.cap::after { content: ""; position: absolute; inset: 5%; border-radius: 50%; border: calc(100cqw / var(--w) * .075) solid rgba(15, 25, 45, .45); z-index: 2; }
.sq.check { background-image: radial-gradient(circle at center, #ff2a2a 0%, #e70000 28%, rgba(169, 0, 0, 0) 75%); }
.sq.pick { box-shadow: inset 0 0 0 3px var(--gold); animation: pulse 1.1s ease-in-out infinite; }
.sq.evt::before { content: ""; position: absolute; inset: 0; background: rgba(255, 140, 60, .55); animation: flash 1.2s ease-out forwards; }
@keyframes pulse { 50% { box-shadow: inset 0 0 0 6px var(--gold); } }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

/* green style (default): classic green/cream board, yellow highlights, soft grey hints */
.board.style-green { --lt: #ebecd0; --dk: #739552; border-radius: 4px; }
.board.style-green .sq.last::before,
.board.style-green .sq.sel::before { background: rgba(255, 255, 51, .5); }
.board.style-green .sq.dest::after { width: 33%; height: 33%; background: rgba(0, 0, 0, .14); }
.board.style-green .sq.cap::after { inset: 0; border-width: calc(100cqw / var(--w) * .09); border-color: rgba(0, 0, 0, .14); }

/* coordinates */
.coord { position: absolute; z-index: 2; pointer-events: none; font: 700 calc(100cqw / var(--w) * .19) / 1 system-ui, sans-serif; }
.coord.rank { top: 4%; left: 5%; }
.coord.file { bottom: 4%; right: 6%; }
.sq.lt .coord { color: var(--dk); }
.sq.dk .coord { color: var(--lt); }

/* dragging */
.sq.dragging .pc { opacity: .3; }
.sq.hover { box-shadow: inset 0 0 0 calc(100cqw / var(--w) * .05) rgba(255, 255, 255, .7); }
.drag-ghost { position: fixed; z-index: 30; pointer-events: none; display: grid; place-items: center; transform: translate(-50%, -50%); }
.drag-ghost .pc { position: static; }
.drag-ghost span.pc.pc { font-size: inherit; }
.drag-ghost img.pc { width: 100%; height: 100%; }
.drag-ghost .pc { transform: scale(1.08); filter: drop-shadow(0 8px 8px rgba(0, 0, 0, .35)); }

/* scrollable big boards (Infinite Chess) */
.board-wrap { width: 100%; }
.board-wrap .board { margin-inline: auto; }
.board-wrap.scroll { display: block; overflow: auto; max-height: calc(100vh - 110px); border-radius: 6px; }
.board-wrap.scroll .board { max-width: none; }

/* circular board */
.board.ring { display: block; position: relative; overflow: visible; box-shadow: none; border-radius: 50%; }
.board.ring svg { position: absolute; inset: 0; width: 100%; height: 100%; filter: drop-shadow(0 14px 30px rgba(0, 0, 0, .45)); }
.board.ring .sq { position: absolute; width: 8.6%; height: 8.6%; transform: translate(-50%, -50%); border-radius: 50%; background: transparent !important; }
.board.ring .sq::before, .board.ring .sq::after { border-radius: 50%; }

/* markers used by classic variants */
.mark {
  position: absolute; z-index: 3; bottom: 3%; right: 4%; pointer-events: none;
  font: 700 calc(100cqw / var(--w) * .24) / 1 system-ui, sans-serif; color: #fff;
  background: rgba(20, 24, 32, .82); border-radius: 5px; padding: 1px 3px;
}
.drag-ghost .mark { font-size: 30%; }
.pc.dead { filter: grayscale(1) brightness(.75); opacity: .75; }
.pc.cooling { opacity: .38; filter: grayscale(.6); }
.sq.danger { background-image: repeating-linear-gradient(45deg, rgba(230, 40, 40, .38) 0 6px, transparent 6px 12px); }
.sq.hill { box-shadow: inset 0 0 0 3px rgba(255, 196, 0, .9); }

/* terrain */
.sq.t-wall { background: linear-gradient(135deg, #4b515e, #2c313a); cursor: default; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .35); }
.theme-backrooms .sq.t-wall { background: linear-gradient(135deg, #a8954d, #7d6c2e); }
.sq.t-hole { background: radial-gradient(circle at 50% 45%, #000 0 40%, #0c0d10 60%, #23262d 100%); }
.sq.t-crack {
  background-image:
    linear-gradient(118deg, transparent 45%, rgba(40, 25, 10, .7) 46%, rgba(40, 25, 10, .7) 48%, transparent 49%),
    linear-gradient(32deg, transparent 57%, rgba(40, 25, 10, .6) 58%, rgba(40, 25, 10, .6) 59.5%, transparent 60.5%),
    linear-gradient(75deg, transparent 30%, rgba(40, 25, 10, .5) 31%, rgba(40, 25, 10, .5) 32%, transparent 33%);
}
.sq.void { background: transparent; cursor: default; }
.sq.fog { filter: brightness(.22) saturate(.3); }
.sq.portal-a { box-shadow: inset 0 0 0 3px #3fa9ff, inset 0 0 calc(100cqw / var(--w) * .35) #3fa9ff; }
.sq.portal-b { box-shadow: inset 0 0 0 3px #ff8a3d, inset 0 0 calc(100cqw / var(--w) * .35) #ff8a3d; }
.sq.offside { background-image: repeating-linear-gradient(45deg, rgba(230, 60, 60, .22) 0 5px, transparent 5px 11px); }

/* pieces */
.pc {
  position: relative; z-index: 1; pointer-events: none;
  font-size: calc(100cqw / var(--w) * .8); line-height: 1;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", "Apple Symbols", serif;
}
img.pc { width: 100%; height: 100%; display: block; -webkit-user-drag: none; }
.pc.w { color: #fbfbfb; text-shadow: 1px 0 #15171b, -1px 0 #15171b, 0 1px #15171b, 0 -1px #15171b, 0 3px 4px rgba(0, 0, 0, .35); }
.pc.b { color: #1b1d22; text-shadow: 0 0 1px rgba(255, 255, 255, .6), 0 3px 4px rgba(0, 0, 0, .3); }
.pc.t-g { color: #f7c948; text-shadow: 0 0 2px #7a5a00, 0 0 10px rgba(247, 201, 72, .8); }
.pc.t-S { font-size: calc(100cqw / var(--w) * .66); font-family: inherit; }
.pc.t-e { font-size: calc(100cqw / var(--w) * .6); font-family: inherit; filter: drop-shadow(0 0 6px #fff7a8) drop-shadow(0 0 2px #000); }
.pc.t-z::before {
  content: ""; display: block;
  width: calc(100cqw / var(--w) * .6); height: calc(100cqw / var(--w) * .6); border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #9be98a, #2d8c3a 70%); box-shadow: 0 2px 4px rgba(0, 0, 0, .35);
}
.badge {
  position: absolute; top: 3%; right: 5%; z-index: 3; pointer-events: none;
  font-size: calc(100cqw / var(--w) * .2); font-style: normal; font-weight: 700; line-height: 1.25;
  background: rgba(10, 12, 16, .75); color: #fff; border-radius: 5px; padding: 0 .3em;
}
.mine { position: absolute; z-index: 3; bottom: 4%; left: 6%; font-size: calc(100cqw / var(--w) * .3); opacity: .85; pointer-events: none; }
.ghost {
  position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; pointer-events: none;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", serif;
  font-size: calc(100cqw / var(--w) * .5); color: #7b5cff; opacity: .7;
}
.ghost b {
  position: absolute; bottom: 4%; right: 6%; font: 700 calc(100cqw / var(--w) * .2) system-ui, sans-serif;
  color: #fff; background: #7b5cff; border-radius: 5px; padding: 0 .3em;
}

/* ---------- side panel ---------- */
.side { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--text); }
.side-thumb { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 10px; display: block; background: var(--panel-2); }
.side h2 { margin: 0; font-size: 22px; display: flex; gap: 10px; align-items: center; }
.side .blurb { margin: -6px 0 0; color: var(--muted); }
.status { padding: 10px 12px; border-radius: 10px; background: var(--panel-2); font-weight: 600; }
.status.check { color: #ff8f8f; }
.status.over { background: rgba(129, 182, 76, .16); color: var(--accent-hi); }
.clocks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.clock { padding: 8px 10px; border-radius: 10px; background: var(--panel-2); font: 600 20px/1.2 ui-monospace, "Cascadia Mono", Consolas, monospace; text-align: center; }
.clock small { display: block; font: 12px system-ui, sans-serif; color: var(--muted); }
.clock.active { outline: 2px solid var(--accent); }
.clock.low { color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions:empty { display: none; }
.info { font-size: 14px; color: var(--muted); background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }
.info:empty { display: none; }
.ctrl { display: grid; gap: 10px; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
select, button { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
/* Buttons read as physical keys: a darker bottom edge that compresses when pressed. */
button { cursor: pointer; border: 0; font-weight: 600; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .28), 0 1px 2px rgba(0, 0, 0, .2); transition: background .1s, transform .05s; }
button:hover:not(:disabled) { background: #4a4743; }
button:active:not(:disabled) { transform: translateY(2px); box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .28); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); text-shadow: 0 1px 0 rgba(0, 0, 0, .25); box-shadow: inset 0 -3px 0 var(--accent-edge), inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 2px rgba(0, 0, 0, .25); }
button.primary:hover:not(:disabled) { background: var(--accent-hi); }
button.primary:active:not(:disabled) { box-shadow: inset 0 -1px 0 var(--accent-edge); }
button.on { background: var(--gold); color: #221800; border-color: var(--gold); }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns button { flex: 1; }
.online { display: grid; gap: 10px; padding: 12px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.online[hidden] { display: none; }
.online p { margin: 0; font-size: 14px; color: var(--muted); }
.online .joinrow { display: flex; gap: 8px; }
.online input { flex: 1; min-width: 0; font: 600 16px ui-monospace, Consolas, monospace; letter-spacing: .15em; text-transform: uppercase; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.online .roomcode { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.online .roomcode b { font: 700 22px ui-monospace, Consolas, monospace; letter-spacing: .12em; color: var(--accent); }
.online .roomcode button { margin-left: auto; }
.online .seats { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 14px; }
.online .seats li { display: flex; justify-content: space-between; }
.online .netmsg { color: var(--gold); word-break: break-all; }
.wildbox { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.wildbox[open] summary { margin-bottom: 10px; }
#wildcfg { display: grid; gap: 10px; }
#wildcfg .check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.twists { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.twists th { text-align: left; color: var(--muted); font-weight: 500; padding: 2px 4px; }
.twists th + th, .twists td + td { text-align: center; width: 56px; }
.twists td { padding: 3px 4px; border-top: 1px solid var(--line); }
.twists td small { color: var(--muted); }
.twists input, #wildcfg .check input { width: 16px; height: 16px; accent-color: var(--accent); }
.wildrow { display: flex; gap: 8px; }
.wildrow button { flex: 1; }
.balance { margin: 0; font-size: 13.5px; color: var(--ok, #6ee7a8); }
.balance.warn { color: var(--gold); }
.wildnote { margin: 0; font-size: 14px; color: var(--muted); }
details summary { cursor: pointer; font-weight: 600; }
details ul { padding-left: 18px; color: var(--muted); margin: 8px 0 0; }
details li { margin: 5px 0; }
.log { max-height: 260px; overflow: auto; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; font-variant-numeric: tabular-nums; }
.log:empty { display: none; }
.log .e { color: var(--gold); }

/* ---------- overlay ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(5, 7, 10, .62); }
.overlay[hidden] { display: none; }
.modal { width: 100%; max-width: 380px; padding: 24px; border-radius: 16px; text-align: center; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 24px 60px rgba(0, 0, 0, .5); }
.modal .big { font-size: 54px; line-height: 1; }
.modal h3 { font-size: 26px; margin: 10px 0 4px; }
.modal p { color: var(--muted); margin: 0 0 18px; }
.modal .btns { flex-direction: column; }
.modal.stalemate h3 { color: var(--accent); }

/* ---------- chess-site polish ---------- */

/* move hints pop in with a small overshoot when a piece is picked up */
.board.pop .sq.dest::after, .board.pop .sq.cap::after { animation: hint-pop .16s cubic-bezier(.34, 1.56, .64, 1) both; }
@keyframes hint-pop { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.board.style-green .sq.dest::after { width: 33%; height: 33%; }

/* right-click annotations */
.sq.marked::before { content: ""; position: absolute; inset: 0; background: rgba(235, 97, 80, .8); }
.board svg.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }
.arrows line { stroke: rgba(255, 170, 0, .82); stroke-width: .2; }
.arrows polygon { fill: rgba(255, 170, 0, .82); }

/* player bars above and below the board */
.pbar { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 100%; margin: 6px auto; min-height: 42px; }
.pbar[hidden] { display: none; }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 4px; display: grid; place-items: center; font-size: 24px; background: #4b4844; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .25); }
.avatar.w { background: #e9e7e3; }
.pinfo { flex: 1; min-width: 0; }
.pname { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 7px; }
.turn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(129, 182, 76, .25); }
.taken { display: flex; align-items: center; flex-wrap: wrap; min-height: 18px; font: 17px/1 "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", serif; }
.taken .tk { margin-right: -4px; }
.taken .tk.w { color: #fff; text-shadow: 1px 0 #333, -1px 0 #333, 0 1px #333, 0 -1px #333; }
.taken .tk.b { color: #1d1c1a; text-shadow: 0 0 1px rgba(255, 255, 255, .5); }
.taken b { margin-left: 10px; font: 600 12px system-ui, sans-serif; color: var(--muted); }
.pclock { flex: none; min-width: 96px; padding: 6px 12px; border-radius: 4px; text-align: right; font: 700 20px/1.2 ui-monospace, "Cascadia Mono", Consolas, monospace; background: #262421; color: #8b8986; }
.pclock.active { background: #fff; color: #262421; }
.pclock.low.active { background: #e6463e; color: #fff; }

/* move list: numbered rows, two columns, figurine pieces, latest move highlighted */
.log.moves { font-size: 14px; color: var(--text); padding: 6px 0 0; }
.mrow { display: grid; grid-template-columns: 40px 1fr 1fr; align-items: center; padding: 1px 6px; }
.mrow:nth-of-type(odd) { background: rgba(255, 255, 255, .025); }
.mno { color: var(--muted); font-size: 13px; }
.mv { padding: 2px 6px; border-radius: 3px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mv.cur { background: rgba(255, 255, 255, .14); }
.fig { font: 400 16px/1 "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", serif; margin-right: 1px; }
.log.moves .note { font-size: 12px; color: var(--gold); padding: 0 6px 3px 46px; }
