:root {
  --bg: #161512; --panel: #262421; --panel2: #302e2b; --line: #3d3a36; --text: #e8e6e3; --muted: #9a958e;
  --accent: #7fa650; --accent2: #95bb4a; --warn: #e2a33a; --bad: #d9534f;
  --brill: #1baca6; --great: #5c8bb0;
  --r: 10px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent2); }
button {
  font: inherit; font-weight: 600; border: 0; border-radius: 8px; padding: .55em 1em; cursor: pointer;
  background: var(--accent); color: #fff; transition: filter .12s, transform .06s;
}
button:hover { filter: brightness(1.1); }
button:active { transform: translateY(1px); }
button.ghost { background: var(--panel2); color: var(--text); }
button.danger:hover { background: #4a2523; }
button:disabled { opacity: .45; cursor: default; filter: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.err { color: var(--bad); min-height: 1.2em; margin: .3em 0; font-size: .9rem; }

/* header */
.top { display: flex; align-items: center; gap: 1.2rem; padding: .7rem 1.2rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.logo { display: flex; align-items: center; gap: .45rem; font-weight: 800; font-size: 1.25rem; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.logo .mark { display: grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 7px; background: var(--accent); color: #fff; font-size: 1.2rem; }
.tabs { display: flex; gap: .25rem; flex: 1; }
.tabs button { background: transparent; color: var(--muted); padding: .5em .9em; }
.tabs button[aria-selected="true"] { color: var(--text); background: var(--panel2); }
.me { margin-left: auto; background: var(--panel2); color: var(--text); display: flex; gap: .5em; align-items: baseline; }
.me b { color: var(--accent2); }

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 1.2rem; }
.foot { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: .9rem 1.2rem; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--line); }
.foot a { color: var(--muted); }

/* lobby */
.hero h1 { margin: .2rem 0 .3rem; font-size: 1.7rem; letter-spacing: -.02em; }
.hero p { margin: 0 0 1.2rem; color: var(--muted); max-width: 60ch; line-height: 1.5; }
.practice-btn { margin: -.4rem 0 1.2rem; }
.tc-grid.lv-grid { grid-template-columns: repeat(5, 1fr); }
.lv-grid button b { font-size: 1rem; }
.cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 1rem 1.1rem; }
.card-h { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .6rem; }
.card-h h2 { margin: 0; font-size: 1.05rem; }
.empty { color: var(--muted); font-size: .92rem; line-height: 1.5; }
.players, .recent { list-style: none; margin: 0; padding: 0; }
.players li { display: flex; align-items: center; gap: .7rem; padding: .55rem .2rem; border-top: 1px solid var(--line); }
.players li:first-child { border-top: 0; }
.dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--accent2); flex: none; }
.dot.busy { background: var(--warn); }
.players .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .rt { color: var(--muted); font-variant-numeric: tabular-nums; }
.players .you { color: var(--muted); font-size: .85rem; }
.players .state { color: var(--warn); font-size: .85rem; }
.recent li { display: grid; grid-template-columns: auto 1fr auto; gap: .6rem; align-items: center; padding: .5rem .2rem; border-top: 1px solid var(--line); font-size: .93rem; }
.recent li:first-child { border-top: 0; }
.res { font-weight: 800; width: 1.6rem; text-align: center; border-radius: 5px; padding: .1em 0; font-size: .8rem; }
.res.w { background: #3b5323; color: #b9e07b; } .res.l { background: #4a2523; color: #f0a19e; } .res.d { background: var(--panel2); color: var(--muted); }
.delta { font-variant-numeric: tabular-nums; font-size: .85rem; }
.delta.up { color: var(--accent2); } .delta.down { color: #e9827e; }
.recent a { color: var(--text); text-decoration: none; }
.recent a:hover { text-decoration: underline; }

.incoming { display: grid; gap: .6rem; margin-bottom: 1rem; }
.ch-card { display: flex; align-items: center; gap: .8rem; padding: .8rem 1rem; border-radius: var(--r); background: #2c3a22; border: 1px solid #4d6b30; animation: pop .25s ease-out; }
.ch-card .txt { flex: 1; }
.ch-card .bar { height: 3px; background: var(--accent2); border-radius: 2px; margin-top: .4rem; transform-origin: left; }
.outgoing { margin-top: .8rem; display: grid; gap: .4rem; }
.out-card { display: flex; align-items: center; gap: .6rem; font-size: .9rem; color: var(--muted); background: var(--panel2); padding: .45rem .7rem; border-radius: 8px; }
.out-card span { flex: 1; }
.out-card button { padding: .3em .7em; font-size: .85rem; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }

/* game */
.game { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1.2rem; align-items: start; }
.board-col { width: min(100%, calc(100vh - 220px)); min-width: 280px; justify-self: center; }
.board-wrap { position: relative; width: 100%; aspect-ratio: 1; }
.cg-board-host { width: 100%; height: 100%; }
.player-bar { display: flex; align-items: center; gap: .6rem; padding: .45rem 0; }
.player-bar .pname { font-weight: 700; }
.player-bar .prating { color: var(--muted); flex: 1; font-variant-numeric: tabular-nums; }
.clock { font: 700 1.6rem/1 ui-monospace, "SF Mono", Menlo, monospace; background: var(--panel2); color: var(--muted); padding: .3rem .6rem; border-radius: 7px; min-width: 6.2rem; text-align: right; font-variant-numeric: tabular-nums; }
.clock.run { background: #e8e6e3; color: #161512; }
.clock.low.run { background: var(--bad); color: #fff; }
.side { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: .9rem; display: flex; flex-direction: column; gap: .8rem; }
.status { font-weight: 600; min-height: 1.3em; }
.moves { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow: auto; display: grid; grid-template-columns: 2.2rem 1fr 1fr; font-variant-numeric: tabular-nums; background: var(--bg); border-radius: 7px; }
.moves li { display: contents; }
.moves .n { color: var(--muted); padding: .25rem .4rem; background: var(--panel2); }
.moves .mv { padding: .25rem .5rem; }
.moves .mv.last { background: #3c4b2a; }
.tag { font-weight: 800; margin-left: .15em; }
.tag.brilliant { color: var(--brill); } .tag.great { color: var(--great); }
.game-buttons { display: flex; gap: .4rem; flex-wrap: wrap; }
.game-buttons button { flex: 1; padding: .5em .6em; font-size: .9rem; }
.draw-banner { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; background: var(--panel2); border-radius: 8px; padding: .6rem; font-size: .92rem; }
.draw-banner span { flex: 1 1 100%; }
.end { text-align: center; display: grid; gap: .45rem; padding: .3rem 0; }
.end-result { font-size: 1.5rem; font-weight: 800; }
.end-rating { font-variant-numeric: tabular-nums; }
.end-brill { color: var(--brill); font-weight: 700; }
.end-buttons { display: flex; gap: .5rem; justify-content: center; }
.end-analyse { font-size: .9rem; }

.promo { position: absolute; inset: 0; z-index: 5; background: rgba(0,0,0,.55); display: grid; place-items: center; }
.promo .row { display: flex; gap: .5rem; background: var(--panel); padding: .6rem; border-radius: var(--r); }
.promo button { width: 4.2rem; height: 4.2rem; padding: 0; background: var(--panel2) center/80% no-repeat; }

/* brilliant cheer: only the player who played the move ever sees this */
.cheer { position: absolute; left: 50%; top: 42%; z-index: 6; pointer-events: none; transform: translate(-50%, -50%) scale(.6); opacity: 0;
  padding: .6rem 1.1rem; border-radius: 999px; font-weight: 800; font-size: 1.25rem; color: #fff; white-space: nowrap;
  box-shadow: 0 8px 30px rgba(0,0,0,.45); }
.cheer.brilliant { background: var(--brill); }
.cheer.great { background: var(--great); }
.cheer.show { animation: cheer 2.2s cubic-bezier(.2,.9,.3,1.2) forwards; }
@keyframes cheer {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.6); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  20% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(.96); }
}
cg-board square.brill-sq { background: rgba(27, 172, 166, .55); }
cg-board square.great-sq { background: rgba(92, 139, 176, .5); }

/* ratings */
.ratings-card { max-width: 720px; margin: 0 auto; }
.ratings { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.ratings th { text-align: left; color: var(--muted); font-weight: 600; font-size: .85rem; padding: .4rem; border-bottom: 1px solid var(--line); }
.ratings td { padding: .5rem .4rem; border-bottom: 1px solid var(--line); }
.ratings tr.mine td { background: #2c3a22; }
.ratings td:nth-child(3) { font-weight: 700; }

/* dialogs */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 1.3rem 1.4rem; width: min(92vw, 420px); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 .6rem; }
dialog p { line-height: 1.5; }
dialog input[type=text], #nameInput { width: 100%; font: inherit; padding: .6rem .7rem; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.dlg-buttons { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.tc-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin: .4rem 0 .9rem; }
.tc-grid button { display: grid; gap: .15rem; padding: .8rem .3rem; background: var(--panel2); color: var(--text); }
.tc-grid button b { font-size: 1.35rem; }
.tc-grid button span { font-size: .75rem; color: var(--muted); font-weight: 500; }
.tc-grid button:hover { background: var(--accent); }
.tc-grid button:hover span { color: #fff; }
.color-pick { display: flex; gap: .9rem; align-items: center; flex-wrap: wrap; }
.toggle { display: flex; gap: .5rem; align-items: center; font-weight: 600; margin-top: .8rem; }
.me-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; text-align: center; }
.me-stats div { background: var(--panel2); border-radius: 8px; padding: .6rem .3rem; }
.me-stats b { display: block; font-size: 1.3rem; }
.me-stats span { font-size: .78rem; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%) translateY(150%); background: var(--panel2); border: 1px solid var(--line);
  padding: .65rem 1rem; border-radius: 10px; transition: transform .25s; z-index: 50; max-width: 90vw; }
.toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 860px) {
  .cols, .game { grid-template-columns: 1fr; }
  .board-col { width: 100%; }
  .top { flex-wrap: wrap; gap: .6rem; }
  .tabs { order: 3; flex-basis: 100%; }
  main { padding: .8rem; }
  .clock { font-size: 1.35rem; min-width: 5.4rem; }
}

/* ---- board feel: grey move dots, lifted pieces, landing flash -------------------------------------- */
cg-board square.move-dest { background: radial-gradient(rgba(0, 0, 0, .2) 16%, transparent 17%); }
cg-board square.oc.move-dest { background: radial-gradient(transparent 0 74%, rgba(0, 0, 0, .2) 75% 88%, transparent 89%); }
cg-board square.move-dest:hover, cg-board square.move-dest.hover { background: rgba(0, 0, 0, .1); }
cg-board square.premove-dest { background: radial-gradient(rgba(40, 70, 140, .28) 16%, transparent 17%); }
cg-board square.oc.premove-dest { background: radial-gradient(transparent 0 74%, rgba(40, 70, 140, .3) 75% 88%, transparent 89%); }
cg-board square.premove-dest:hover, cg-board square.premove-dest.hover { background: rgba(40, 70, 140, .15); }
cg-board square.selected { background: rgba(255, 210, 70, .5); }
cg-board square.last-move { background: rgba(255, 210, 70, .32); animation: land .28s ease-out; }
@keyframes land { from { background: rgba(255, 225, 120, .75); } }
.cg-wrap piece { transition: scale .12s ease-out, filter .12s ease-out; }
.cg-wrap piece.lifted { scale: 1.1; filter: drop-shadow(0 5px 4px rgba(0, 0, 0, .35)); }
cg-board piece.dragging { scale: 1.18; filter: drop-shadow(0 10px 8px rgba(0, 0, 0, .4)); cursor: grabbing; }
