:root {
  --bg: #10161c;
  --bg2: #0c1116;
  --panel: #1a242e;
  --panel2: #121a22;
  --line: #314253;
  --tx: #e7eef4;
  --mut: #8ea0b0;
  --acc: #e2b15a;
  --acc2: #a9782e;
  --danger: #e06a5c;
  --ok: #7dcea0;
  --lt: #efe6d5;
  --dk: #6d8f73;
  --shadow: 0 18px 50px rgba(0, 0, 0, .38);
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
}
html[data-theme="walnut"] { --lt: #f0d9b5; --dk: #b58863; }
html[data-theme="marine"] { --lt: #e4eef5; --dk: #4c7399; }
html[data-theme="night"] { --lt: #c5d0dc; --dk: #3e5168; }
html[data-theme="contrast"] { --lt: #f5f5f5; --dk: #1c1c1c; }
html[data-theme="turneu"] { --lt: #eeeed2; --dk: #769656; }
html[data-theme="albastru"] { --lt: #dee3e6; --dk: #8ca2ad; }
html[data-theme="indigo"] { --lt: #d4deee; --dk: #4a6794; }
html[data-theme="violet"] { --lt: #f0e4f6; --dk: #8a6798; }
html[data-theme="coral"] { --lt: #fde6d0; --dk: #d4894e; }
html[data-theme="roz"] { --lt: #fde4ee; --dk: #d46b96; }
html[data-theme="menta"] { --lt: #e4f6ee; --dk: #4e9e7c; }
html[data-theme="oliv"] { --lt: #ebe7c6; --dk: #6b7438; }
html[data-theme="sticla"] { --lt: #e4f2fb; --dk: #3e8fbf; }
html[data-theme="marmura"] { --lt: #eeeae4; --dk: #847f78; }
html[data-theme="neon"] { --lt: #c6f6dc; --dk: #148255; }
html[data-theme="cireasa"] { --lt: #f8e2da; --dk: #b25a56; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--tx);
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
body { font: 16px/1.45 var(--font, "Segoe UI"), system-ui, sans-serif; }
input, textarea, select { -webkit-user-select: text; user-select: text; font-size: 16px; }
button, input, select { font: inherit; }
h1, h2, h3 { font-family: Georgia, "Palatino Linotype", Palatino, serif; font-weight: 600; margin: 0 0 .4rem; }
p { margin: .3rem 0; }
button, .sq, .piece, svg { -webkit-user-drag: none; }
[hidden] { display: none !important; }
main { max-width: 1080px; margin: 0 auto; padding: 1rem; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1.05rem;
  box-shadow: var(--shadow);
}
label { color: var(--mut); }
input, select {
  padding: .6rem .75rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--tx);
  width: 100%;
}
button {
  cursor: pointer;
  background: var(--acc);
  color: #1c1406;
  border: 0;
  border-radius: 8px;
  padding: .6rem .9rem;
  font-weight: 700;
  font-size: 0.875rem;
}
button.ghost { background: transparent; color: var(--tx); border: 1px solid var(--line); }
button.danger, button.danger.ghost { color: #fff; background: #8d3a32; border-color: transparent; }
button:disabled { opacity: .55; cursor: default; }
button.icon { width: 36px; height: 36px; padding: 0; background: transparent; color: var(--tx); border: 1px solid var(--line); font-size: 1.3rem; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.inline-box { display: flex; flex-direction: column; gap: .55rem; margin: .55rem 0; padding: .75rem .8rem; border: 1px solid var(--acc); border-radius: 12px; background: var(--bg2); }
.inline-box[hidden] { display: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.lobby-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; }
.lobby-head h1 { margin-bottom: .15rem; }
#pool { margin: 0; text-align: right; }
.lobby-tabs { display: flex; gap: .4rem; overflow-x: auto; margin: .15rem 0 .85rem; scrollbar-width: none; }
.lobby-tabs button { background: transparent; color: var(--tx); border: 1px solid var(--line); white-space: nowrap; padding: .5rem .8rem; }
.lobby-tabs button[aria-selected="true"] { background: var(--acc); color: #1c1406; border-color: transparent; }
.lobby-tabs .pill { background: rgba(0, 0, 0, .16); color: inherit; }
.tc-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.tc-chips button { background: var(--bg2); color: var(--tx); border: 1px solid var(--line); padding: .45rem .7rem; }
.tc-chips button.on { background: var(--acc); color: #1c1406; border-color: transparent; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
button.wide { width: 100%; }
.stat-who { display: flex; flex-direction: column; gap: .15rem; }
.stat-who > b { font-size: 1.15rem; }
.stat-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; }
.stat-tiles div { background: var(--bg2); border-radius: 12px; padding: .7rem .4rem; text-align: center; }
.stat-tiles b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stat-tiles span { color: var(--mut); font-size: .78rem; }
.seeker .who small { white-space: normal; }
.seeker button { flex: none; }
.stack { display: flex; flex-direction: column; gap: .55rem; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.muted { color: var(--mut); }
.err { color: #ffb0a6; min-height: 1.2em; }
.lead { font-size: 1.15rem; }
.code { font: 700 1.4rem/1 ui-monospace, monospace; letter-spacing: .08em; }
.check { display: flex; gap: .5rem; align-items: center; color: var(--tx); }
.check input { width: auto; }
#auth { max-width: 420px; margin: 8vh auto; }
.who { display: flex; gap: .55rem; align-items: center; min-width: 0; }
.who b, .who small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { color: var(--mut); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #667; flex: none; }
.onl { display: inline-block; width: 7px; height: 7px; margin-right: .35rem; border-radius: 50%; background: var(--ok); vertical-align: 1px; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(125, 206, 160, .18); }
.caps { display: flex; flex-wrap: wrap; gap: 0; align-items: center; min-height: 18px; }
.caps .piece { width: 16px; height: 16px; filter: none; }
.caps .diff { color: var(--acc); font-weight: 700; margin-left: .3rem; font-variant-numeric: tabular-nums; }
.stage {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 210px 16px 16px;
}
.board-stack { width: min(720px, calc(100vw - 240px), calc(100dvh - 130px)); display: flex; flex-direction: column; gap: 8px; }
.pl { display: flex; align-items: center; justify-content: space-between; gap: .6rem; min-height: 46px; }
.clock {
  font: 700 1.35rem/1 ui-monospace, monospace;
  padding: .28rem .55rem;
  border-radius: 8px;
  background: #0d141b;
  min-width: 4.6rem;
  text-align: center;
  flex: none;
}
.clock.on { background: var(--acc); color: #1c1406; }
.clock.low { color: #ffb4a8; }
.clock.crit { background: #8c2f2f; color: #fff; animation: pulse .7s ease-in-out infinite; }
@keyframes pulse { 50% { filter: brightness(1.25); } }
.board-frame {
  position: relative;
  padding: 12px;
  border-radius: 14px;
  background:
    linear-gradient(145deg, rgba(255,255,255,.18), transparent 32%),
    linear-gradient(160deg, #7a5a38, #2c1d12 55%, #4e3624);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.25);
}
#board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1;
  width: 100%;
  border-radius: 4px;
  overflow: hidden;
  touch-action: none;
  position: relative;
}
.sq {
  position: relative;
  display: block;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
}
.sq.l { background: var(--lt); }
.sq.d { background: var(--dk); }
.sq.last::before, .sq .hintmark { pointer-events: none; }
.sq.last::before { content: ""; position: absolute; inset: 0; background: rgba(226, 168, 52, .46); z-index: 1; }
.sq.chk { background: #d45348 !important; }
.sq.sel { outline: 3px solid var(--acc); outline-offset: -3px; z-index: 3; }
.sq.pre { outline: 3px dashed var(--acc); outline-offset: -4px; z-index: 3; }
.sq.hover { outline: 3px solid rgba(255,255,255,.85); outline-offset: -3px; z-index: 3; }
.sq.hint::after {
  content: "";
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(20, 16, 10, .28);
  position: absolute;
  z-index: 2;
  pointer-events: none;
}
.sq.hint.cap::after { width: 84%; height: 84%; background: transparent; border: 4px solid rgba(20, 16, 10, .32); }
.sq i {
  position: absolute;
  z-index: 4;
  font-style: normal;
  font-size: clamp(8px, 1.5vw, 12px);
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
}
.sq.l i { color: rgba(0, 0, 0, .55); }
.sq.d i { color: rgba(255, 255, 255, .78); }
.sq i.rank { top: 2px; left: 3px; }
.sq i.file { right: 3px; bottom: 2px; }
.piece { width: 88%; height: 88%; z-index: 2; color: #fbfaf7; filter: drop-shadow(0 1px 1px rgba(0,0,0,.4)); }
.sq > .piece { position: absolute; left: 6%; top: 6%; width: 88%; height: 88%; }
.piece.b { color: #16181b; }
.piece svg { width: 100%; height: 100%; display: block; }
.piece path, .piece circle, .piece rect { fill: currentColor; stroke: rgba(0,0,0,.4); stroke-width: 1.15; stroke-linejoin: round; }
.piece.b path, .piece.b circle, .piece.b rect { stroke: rgba(255,255,255,.28); }
.piece .cut, .piece .eye { stroke: none; }
.piece .cut { fill: rgba(0,0,0,.38); }
.piece.b .cut { fill: rgba(255,255,255,.45); }
.piece.w .eye { fill: #16181b; }
.piece.b .eye { fill: #f4f1ea; }
.piece.flip { transform: scaleX(-1); }
html[data-pieces="outline"] .piece.w { color: transparent; }
html[data-pieces="outline"] .piece.w path,
html[data-pieces="outline"] .piece.w circle,
html[data-pieces="outline"] .piece.w rect { fill: rgba(255,255,255,.08); stroke: #f7f4ee; stroke-width: 1.6; }
html[data-pieces="outline"] .piece.b { color: transparent; }
html[data-pieces="outline"] .piece.b path,
html[data-pieces="outline"] .piece.b circle,
html[data-pieces="outline"] .piece.b rect { fill: rgba(0,0,0,.2); stroke: #1a1a1a; stroke-width: 1.6; }
.evalbar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 7px;
  background: #141414;
  z-index: 5;
  pointer-events: none;
}
#evalfill { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: #f4f1ea; }
.promo {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .45);
}
.promo-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
  text-align: center;
}
.promo-row { display: flex; gap: 8px; }
.promo-row button {
  width: 68px; height: 68px; padding: 6px;
  background: var(--lt); border-radius: 10px;
}
.promo-row .piece { width: 100%; height: 100%; }
.widget {
  position: fixed;
  z-index: 50;
  top: 50%;
  right: max(12px, env(safe-area-inset-right));
  transform: translateY(-50%);
  width: max-content;
  max-width: min(420px, calc(100vw - 24px));
}
.dock {
  display: flex;
  align-items: center;
  gap: .7rem;
  text-align: left;
  color: var(--tx);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: .7rem .85rem .7rem .7rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  min-width: 168px;
}
.dock.alert { border-color: var(--acc); box-shadow: 0 0 0 3px rgba(226, 177, 90, .25), var(--shadow); }
.mark {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: grid; place-items: center; background: var(--acc); color: #1c1406;
}
.mark .piece { width: 28px; height: 28px; color: #1c1406; filter: none; }
.dock-copy { display: flex; flex-direction: column; min-width: 0; }
.dock-copy strong { font-size: .95rem; }
.dock-copy small { color: var(--mut); font-variant-numeric: tabular-nums; }
.widget.open { width: min(420px, calc(100vw - 24px)); }
.widget.open .dock { display: none; }
.console {
  display: flex;
  flex-direction: column;
  max-height: min(78dvh, 760px);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  overflow: hidden;
}
.console-top, .tabs, .tab-body { padding-left: 12px; padding-right: 12px; }
.console-top { display: flex; justify-content: space-between; align-items: center; padding-top: 10px; }
.tabs { display: flex; gap: 4px; overflow: auto; padding-bottom: 0; border-bottom: 1px solid var(--line); }
.tabs button {
  background: transparent; color: var(--mut); border-radius: 0;
  border-bottom: 2px solid transparent; padding: .55rem .45rem; font-weight: 650;
  white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--tx); border-bottom-color: var(--acc); }
.tab-body { overflow: auto; padding-top: 12px; padding-bottom: 14px; min-height: 220px; }
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: .4rem 0 .8rem; }
.duo div { background: var(--bg2); border-radius: 10px; padding: .45rem .6rem; }
.duo small { color: var(--mut); display: block; }
.duo b { font: 700 1.15rem/1.2 ui-monospace, monospace; }
#moves { display: grid; grid-template-columns: 2.2rem 1fr 1fr; gap: 2px 6px; margin-top: .7rem; align-items: center; }
#moves button, #moves span.num {
  background: transparent; color: inherit; font-weight: 600; text-align: left;
  padding: .18rem .35rem; border-radius: 5px;
}
#moves span.num { color: var(--mut); }
#moves button.on { background: rgba(226, 177, 90, .22); }
#chat { display: flex; flex-direction: column; gap: .35rem; max-height: 320px; overflow: auto; margin-bottom: .6rem; }
.bubble { background: var(--bg2); border-radius: 10px; padding: .35rem .55rem; }
.bubble b { display: block; font-size: .78rem; color: var(--acc); }
.bubble.mine { background: #2a3542; }
.themes { display: flex; gap: .4rem; flex-wrap: wrap; }
.themes button { width: 42px; height: 42px; padding: 0; border: 2px solid transparent; border-radius: 10px; }
.themes button.on { border-color: var(--acc); }
.sw { display: grid; grid-template-columns: 1fr 1fr; height: 100%; border-radius: 8px; overflow: hidden; }
.sw i { display: block; height: 100%; }
#g-notes { margin: .4rem 0; padding-left: 1.1rem; color: var(--mut); }
.salons { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .7rem; margin: .4rem 0 1.1rem; }
button.salon-card {
  width: 100%;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  background: var(--panel);
  color: var(--tx);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: .9rem 1rem;
  font-weight: 500;
  box-shadow: var(--shadow);
}
button.salon-card b { font-size: 1.05rem; }
button.salon-card.locked, button.salon-card:disabled { opacity: .62; }
.pills { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .2rem; }
.pill { font-size: .75rem; padding: .08rem .45rem; border-radius: 99px; background: var(--bg2); color: var(--mut); }
.pill.ok { color: var(--ok); }
.salon-head { display: flex; justify-content: space-between; align-items: flex-end; gap: .8rem; margin-bottom: .6rem; }
.room { display: grid; grid-template-columns: 1.15fr .85fr; gap: 1rem; align-items: start; }
.row.spread { justify-content: space-between; }
.person { display: flex; align-items: center; gap: .6rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.person .who { flex: 1; min-width: 0; }
.av { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: #243140; font-weight: 750; flex: none; }
.badge { font-size: .75rem; border-radius: 99px; padding: .12rem .5rem; white-space: nowrap; }
.badge.free { background: rgba(125, 206, 160, .16); color: var(--ok); }
.badge.busy { background: rgba(224, 106, 92, .16); color: #ffb0a6; }
.badge.idle { color: var(--mut); }
.person button { margin-left: .4rem; padding: .35rem .65rem; }
.challenge { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; border-color: var(--acc); margin-bottom: .7rem; }
#invite {
  position: fixed;
  z-index: 55;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 24px));
  margin: 0;
  box-shadow: var(--shadow);
}
#schat { display: flex; flex-direction: column; gap: .35rem; max-height: min(420px, 48dvh); overflow: auto; min-height: 140px; }
.hrow, .lbrow {
  display: grid;
  grid-template-columns: 1.4fr .7fr .9fr;
  gap: .4rem;
  padding: .35rem 0;
  border-bottom: 1px solid var(--line);
  font-size: .92rem;
}
#lb2 .lbrow { grid-template-columns: 1.5rem minmax(0, 1.4fr) minmax(0, .8fr) auto; align-items: center; }
#lb2 .lbrow span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.28); z-index: 45; }
table { width: 100%; border-collapse: collapse; }
td, th { padding: .35rem .3rem; border-bottom: 1px solid var(--line); text-align: left; }
body.mode-auth #invite { display: none; }
body.mode-play { overflow: hidden; }
body.mode-play main { padding: 0; max-width: none; height: 100dvh; }
@media (max-width: 860px) {
  .cols, .room, .salons, .pair { grid-template-columns: 1fr; }
  body.mode-lobby main, body.mode-salon main { padding-left: 10px; padding-right: 10px; }
  .lobby-head { flex-direction: column; align-items: flex-start; }
  #pool { text-align: left; }
  body.mode-lobby .card,
  body.mode-lobby [data-lpanel],
  body.mode-salon .card,
  body.mode-salon .room,
  body.mode-salon .salons { width: 100%; max-width: none; margin-right: 0; }
  .dock { min-width: 0; width: 54px; height: 54px; padding: 0; border-radius: 16px; justify-content: center; }
  body.mode-play .widget:not(.open) {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    transform: none;
  }
  .dock-copy { display: none; }
  .stage { padding: 12px 72px 12px 12px; }
  .board-stack { width: min(100%, calc(100dvh - 140px)); }
  body.mode-play { position: fixed; inset: 0; width: 100%; height: 100dvh; }
  body.mode-play #game { position: fixed; inset: 0; display: flex; background: #070b10; }
  body.mode-play .stage { padding: 0; width: 100%; height: 100%; min-height: 0; }
  body.mode-play .board-stack {
    width: 100%;
    height: 100%;
    max-width: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0;
  }
  body.mode-play .board-frame {
    padding: 0; border-radius: 0; box-shadow: none; background: transparent;
    width: min(100vw, calc(100dvh - 108px));
  }
  body.mode-play #board { width: 100%; height: auto; border-radius: 0; aspect-ratio: 1; }
  body.mode-play .pl {
    position: relative;
    width: min(100vw, calc(100dvh - 108px));
    padding: 6px 8px;
    min-height: 48px;
    color: #fff;
    z-index: 2;
  }
  body.mode-play .who small, body.mode-play .caps .diff { color: #ecd9a4; }
  body.mode-play .clock { background: rgba(0,0,0,.45); color: #fff; }
  body.mode-play .clock.on { background: var(--acc); color: #1c1406; }
  .widget.open {
    inset: 0; top: 0; right: 0; transform: none;
    width: 100%; max-width: none; height: 100dvh;
  }
  .widget.open .console { height: 100%; max-height: none; border-radius: 0; border: 0; }
}
@media (min-width: 861px) {
  body.mode-lobby main, body.mode-salon main { padding-right: 210px; }
  body.console-open .stage { padding-right: min(460px, 48vw); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
