@font-face {
  font-family: Overpass;
  src: url('/fonts/overpass.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: IBM Plex Mono;
  src: url('/fonts/ibm-plex-mono.woff2') format('woff2');
  font-display: swap;
}
:root {
  color-scheme: dark;
  --canvas: #0c1424;
  --panel: #111a2b;
  --panel-dark: #0b1423;
  --bar: #19263c;
  --line: #405576;
  --dim-line: #2a3a55;
  --ink: #e6eefb;
  --dim: #adbfd9;
  --blue: #70d7fa;
  --blue-ink: #102434;
  --blue-muted: #203851;
  --tile-light: #adbed1;
  --tile-dark: #47627b;
  --tile-ink-light: #2d455f;
  --tile-ink-dark: #f0f7ff;
  --frame: #263d58;
  --frame-bright: #83afcf;
  --side-front: #354e67;
  --side-bottom: #101e34;
  --text: Overpass, system-ui, sans-serif;
  --mono: "IBM Plex Mono", "DejaVu Sans Mono", monospace;
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--text);
}
:root[data-theme="plain"] {
  --tile-light: #ddc69f;
  --tile-dark: #95684f;
  --tile-ink-light: #583f30;
  --tile-ink-dark: #fff3da;
  --frame: #50352b;
  --frame-bright: #ae8365;
  --side-front: #79513d;
  --side-bottom: #30221d;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: linear-gradient(90deg, #090f2160, #090f211a), url('/arch-alpine.webp') center top / cover fixed no-repeat, var(--canvas);
}
::selection { color: var(--blue-ink); background: var(--blue); }
button, select, input {
  font: inherit;
  color: var(--ink);
  background: var(--panel-dark);
  border: 1px solid var(--line);
  border-radius: 2px;
  min-height: 2rem;
}
button, select { cursor: pointer; }
button:disabled { opacity: .48; cursor: default; }
button:hover:not(:disabled), select:hover { border-color: var(--blue); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
a { color: inherit; text-decoration: none; }
input { caret-color: var(--blue); }
input::placeholder { color: var(--dim); }
svg { display: block; width: 20px; height: 20px; }

.top {
  min-height: 52px;
  padding: 0 clamp(12px,3vw,42px);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: stretch;
  gap: clamp(12px,2.4vw,36px);
  background: #0b1321;
  border-bottom: 1px solid #587b9b;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.24rem;
  font-weight: 750;
  letter-spacing: -.025em;
  white-space: nowrap;
}
.brand svg { width: 27px; height: 27px; color: var(--blue); }
.workspaces { display: flex; align-items: stretch; min-width: 0; gap: 3px; }
.mode {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 6px clamp(6px,1vw,13px);
  background: #131e31;
  border: 0;
  border-inline: 1px solid #233854;
  border-radius: 0;
  white-space: nowrap;
  font-size: .83rem;
}
.mode:hover:not(:disabled) { background: var(--blue-muted); }
.mode.active, .mode.active:hover {
  background: linear-gradient(180deg,#203f58,#192c44);
  color: #e9fbff;
  border-inline-color: #467393;
  box-shadow: inset 0 -3px var(--blue);
}
.workspace-number {
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  background: #263a54;
  color: #d7efff;
  font: .78rem var(--mono);
  line-height: 1;
}
.mode.active .workspace-number { background: var(--blue); color: var(--blue-ink); }
.top-controls { display: flex; gap: clamp(9px,1.3vw,20px); align-items: center; }
.session { display: flex; align-items: center; font: .76rem var(--mono); white-space: nowrap; color: var(--dim); }
.download { color: var(--ink); font-size: .84rem; line-height: 1.2; text-underline-offset: 4px; white-space: nowrap; }
.download:hover { text-decoration: underline; }
.download small { margin-left: 4px; color: var(--dim); font: .73rem var(--mono); }
.icon { display: grid; place-items: center; width: 34px; min-height: 33px; background: transparent; }
.sound-off, #sound[aria-pressed="true"] .sound-waves { display: none; }
#sound[aria-pressed="true"] .sound-off { display: block; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, min(702px, max(510px, calc(100dvh - 325px)))) minmax(220px, 290px);
  align-items: start;
  justify-content: center;
  gap: 14px;
  width: min(1150px,100%);
  padding: clamp(18px,3vh,36px) clamp(13px,3vw,38px) 25px;
  margin: 0 auto;
  flex: 1;
}
.right { display: grid; gap: 12px; min-width: 0; }
.panel, .game { min-width: 0; border: 1px solid var(--line); background: var(--panel); }
.game { border-color: #658aa9; box-shadow: 0 15px 40px #0207137d; }
.game:focus-within { border-color: var(--blue); }
.window-bar {
  margin: 0;
  min-height: 37px;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: var(--bar);
  color: var(--ink);
  font: .83rem var(--mono);
}
.window-program { color: var(--dim); font: .74rem var(--mono); white-space: nowrap; }
.game-title {
  color: var(--ink);
  background: #1d3650;
  border-bottom-color: #4a7395;
}
h1 { margin: 0; font: inherit; }
.game-interior { padding: 10px clamp(10px,2.3vw,21px) 13px; }
.engine-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 8px; padding: 12px; }
.engine-fields label, dialog label { display: grid; gap: 5px; color: var(--dim); font-size: .83rem; min-width: 0; }
.engine-fields .action { grid-column: 1/-1; }
select { padding: .3rem .55rem; }
.action { background: var(--blue); color: var(--blue-ink); border-color: transparent; font-weight: 700; min-height: 36px; padding: 6px 12px; }
.action:hover:not(:disabled) { background: #b6ecff; }
.small { font-size: .82rem; min-height: 34px; padding: 5px 8px; }
.move-status { display: flex; justify-content: space-between; align-items: center; min-height: 29px; gap: 6px; margin-top: 5px; }
#status { margin: 0; color: var(--ink); font-size: .92rem; font-weight: 600; }
.board-tools { display: flex; justify-content: space-between; align-items: center; gap: 7px; padding-bottom: 7px; border-bottom: 1px solid var(--dim-line); }
.view-switch { display: flex; padding: 4px; gap: 1px; border: 1px solid var(--line); border-radius: 2px; }
.view-switch button { background: transparent; border-color: transparent; min-height: 30px; padding: 4px 9px; font-size: .84rem; }
.view-switch button[aria-pressed="true"] { color: var(--blue-ink); background: var(--blue); }
.piece-tools { display: flex; align-items: center; gap: 6px; }
.piece-tools label { display: flex; align-items: center; gap: 6px; color: var(--dim); font-size: .8rem; }
.piece-tools select { color: var(--ink); }
#flip { display: grid; place-items: center; width: 34px; }
#flip svg { width: 18px; height: 18px; }
.seat { display: flex; align-items: center; min-height: 36px; gap: 8px; }
.seat strong { font-size: .88rem; font-weight: 600; }
.seat-dot { width: 11px; height: 11px; border: 1px solid #f0ddba; border-radius: 50%; background: #e9c79d; }
.dark-dot { border-color: #abc2d7; background: #536780; }
.clock { margin-left: auto; color: var(--ink); background: var(--panel-dark); padding: 4px 8px; font: .88rem var(--mono); min-width: 52px; text-align: center; border: 1px solid var(--line); border-radius: 2px; }
.clock.current { color: var(--blue-ink); background: var(--blue); border-color: var(--blue); }

.board-wrap { width: 100%; padding: 3px 0 16px; }
.board-stage { position: relative; width: 100%; aspect-ratio: 1; }
.board-stage::after {
  content: '';
  position: absolute;
  z-index: 0;
  top: calc(100% - 1px);
  left: 0;
  width: 100%;
  height: 9px;
  background: linear-gradient(180deg,var(--frame-bright) 0%,var(--side-front) 21%,var(--side-bottom) 100%);
  border-radius: 0 0 4px 4px;
  box-shadow: 0 13px 22px #090a08bb;
}
.board-wrap:not(.flat) .board-stage { aspect-ratio: 1.49; }
.board-wrap:not(.flat) .board-stage::after { height: clamp(10px,2.1vw,22px); }
.board {
  display: grid;
  grid-template: repeat(8, minmax(0,1fr)) / repeat(8, minmax(0,1fr));
  position: absolute;
  z-index: 1;
  bottom: 0;
  left: 0;
  width: 100%;
  aspect-ratio: 1;
  border: clamp(4px,.65vw,9px) solid var(--frame);
  border-radius: 3px 3px 1px 1px;
  background: var(--frame);
  box-shadow: 0 0 0 1px var(--frame-bright), 0 10px 24px #090a0888;
}
.board-wrap:not(.flat) .board {
  transform: perspective(980px) rotateX(36deg);
  transform-origin: center bottom;
  box-shadow: 0 0 0 1px var(--frame-bright);
}
.square {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  isolation: isolate;
  background: linear-gradient(150deg,#fff1,transparent 58%), var(--tile-light);
  color: var(--tile-ink-light);
  touch-action: manipulation;
}
.square.dark { background: linear-gradient(150deg,#fff1,transparent 58%), var(--tile-dark); color: var(--tile-ink-dark); }
.square:hover:not(:disabled), .square:focus-visible { z-index: 1; box-shadow: inset 0 0 0 2px #e4f8ff; outline: none; }
.square.last::before, .square.selected::before, .square.check::before { content: ''; position: absolute; inset: 0; z-index: -1; }
.square.last::before { background: #bad1ff66; }
.square.selected::before { background: #90d9e477; border: 2px solid #d5faff; }
.square.check::before { background: #a3263eaa; }
.square.legal::after { content: ''; position: absolute; inset: 40%; border-radius: 50%; background: #1423209f; pointer-events: none; }
.square.legal.occupied::after { inset: 1px; border: 4px solid #17282ca5; background: none; }
.piece { position: absolute; pointer-events: none; width: 96%; height: 91%; left: 2%; bottom: 6%; object-fit: contain; object-position: center bottom; filter: drop-shadow(1px 3px 2px #142025b3); }
.piece-layer { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.piece-anchor { position: absolute; left: 50%; top: 85%; width: 0; height: 0; pointer-events: none; }
.piece-upright {
  transform: translate(-50%,-100%);
  pointer-events: auto;
  cursor: pointer;
  clip-path: polygon(18% 0,82% 0,89% 46%,96% 86%,96% 100%,4% 100%,4% 86%,11% 46%);
  filter: drop-shadow(2px 3px 2px #172021a6);
  touch-action: manipulation;
}
.coordinate { position: absolute; font: clamp(8px,1vw,12px) var(--mono); pointer-events: none; }
.file { right: 3px; bottom: 2px; }
.rank { left: 3px; top: 2px; }

.command { margin-top: 4px; border: 1px solid var(--line); background: var(--panel-dark); display: flex; align-items: center; gap: 9px; padding: 5px 8px 5px 11px; font: .83rem var(--mono); color: var(--blue); }
.command input { min-width: 0; width: 100%; border: 0; background: transparent; padding: 3px; }
.command kbd { color: var(--dim); border: 1px solid var(--line); border-radius: 2px; padding: 1px 5px; }

#move-count { color: var(--dim); font: .78rem var(--mono); }
.moves { min-height: 103px; max-height: 305px; padding: 5px 10px; overflow-y: auto; scrollbar-color: var(--line) var(--panel); }
.moves > p { font-size: .86rem; color: var(--dim); margin: 8px 1px; }
.move-row { display: grid; grid-template-columns: 2rem 1fr 1fr; gap: 3px; padding: 6px 1px; border-bottom: 1px solid var(--dim-line); font: .83rem var(--mono); }
.move-row span:first-child { color: var(--dim); }
.history-tools, .replay-controls { display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px solid var(--dim-line); padding: 8px 10px; }
.room { display: grid; gap: 7px; }
.room button { margin: 0 10px; }
.room button:last-child { margin-bottom: 10px; }
.terminal-content { display: grid; gap: 8px; padding: 11px; }
.terminal-content code {
  display: block;
  padding: 9px;
  color: var(--blue);
  background: var(--panel-dark);
  border: 1px solid var(--dim-line);
  font: .78rem var(--mono);
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.terminal-content button { justify-self: start; }
dialog { width: min(460px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--line); border-radius: 3px; background: var(--panel); color: var(--ink); }
dialog::backdrop { background: #060c17dc; }
dialog h2 { margin: 0 0 15px; font-size: 1.26rem; }
dialog input { width: 100%; padding: 9px; }
.dialog-actions, .promotions { display: flex; justify-content: end; gap: 8px; margin-top: 15px; }
.promotions button { padding: 8px; }
footer { display: flex; justify-content: space-between; gap: 10px; padding: 11px clamp(13px,3vw,42px); background: #0b1321; border-top: 1px solid var(--line); color: var(--dim); font-size: .83rem; }
footer a { text-underline-offset: 3px; text-decoration: underline; }
.online-dot { display: inline-block; flex: 0 0 6px; border-radius: 50%; width: 6px; height: 6px; background: #8de0aa; margin-right: 7px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

@media (max-width: 1060px) {
  .top { gap: 13px; }
  .session { display: none; }
}
@media (max-width: 740px) {
  .top { grid-template-columns: 1fr auto; gap: 0 10px; }
  .brand, .top-controls { min-height: 52px; }
  .workspaces { grid-row: 2; grid-column: 1/-1; }
  .top-controls { grid-row: 1; grid-column: 2; }
  .layout { grid-template-columns: minmax(0,1fr); max-width: 630px; }
  .right { grid-template-columns: repeat(auto-fit,minmax(170px,1fr)); }
  .moves { min-height: 72px; }
}
@media (max-width: 460px) {
  .top { padding-inline: 9px; }
  .workspaces { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 2px; }
  .mode { gap: 4px; min-width: 0; padding: 4px; font-size: .73rem; text-align: left; }
  .mode > span:last-child { white-space: normal; line-height: 1.15; }
  .workspace-number { display: none; }
  .top-controls { gap: 8px; }
  .download small { display: none; }
  .layout { padding: 10px 8px 20px; }
  .game-interior { padding-inline: 8px; }
  .right { grid-template-columns: minmax(0,1fr); }
  .board-wrap:not(.flat) .board-stage { aspect-ratio: 1.45; }
  .piece-tools label { font-size: 0; gap: 0; }
  .piece-tools select { font-size: .83rem; }
  .clock { font-size: .8rem; }
}

.lichess-controls {
  display: grid;
  gap: .75rem;
  padding: .85rem;
}
.lichess-controls p { margin: 0; overflow-wrap: anywhere; }
.lichess-controls form { display: grid; gap: .55rem; }
.lichess-controls label { display: grid; gap: .2rem; }
.lichess-controls .lichess-check { display: flex; align-items: center; gap: .4rem; }
.lichess-controls summary { cursor: pointer; margin-bottom: .5rem; }
.lichess-actions { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.lichess-items { display: grid; gap: .35rem; max-height: 15rem; overflow: auto; }
.lichess-items button, .lichess-items a { text-align: left; }
