:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel2: #eceff2;
  --line: #dce0e5;
  --text: #1f2328;
  --muted: #69727d;
  --accent: #d9a441;
  --live: #d93a3f;
  --good: #46a758;
  --light: #e9dcc1;
  --dark: #a67c52;
  --hl: rgba(224, 176, 79, .45);
  --check: rgba(229, 72, 77, .75);
  --radius: 10px;
  --board: min(560px, 92vw, calc(100vh - 220px));
  color-scheme: light;
}
* { box-sizing: border-box; }
/* "hidden" must win over the display: flex/grid set on panels below (else a hidden panel stays visible) */
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, .btn { font: inherit; color: inherit; }
h1, h2 { margin: 0; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; display: flex; gap: 8px; align-items: baseline; }
h2 small { text-transform: none; letter-spacing: 0; color: #a8781c; font-size: 12px; }

/* Header */
.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel); gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.brand > div { min-width: 0; }
.logo { font-size: 30px; color: var(--accent); line-height: 1; }
.brand h1 { font-size: 17px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { display: flex; gap: 12px; align-items: center; flex-shrink: 0; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; letter-spacing: .08em; padding: 4px 9px; border-radius: 99px; background: var(--panel2); color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on { color: var(--live); background: rgba(217, 58, 63, .1); font-weight: 600; }
.live.on i { background: var(--live); animation: pulse 1.6s infinite; }
.live.ended i { background: var(--accent); }
@keyframes pulse { 50% { opacity: .3; } }
.viewers { color: var(--muted); }
.viewers b { color: var(--text); }

/* Event tabs, in the header between the title and the live badge */
.eventTabs { display: flex; gap: 6px; flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: thin; }
.top:has(.eventTabs:not([hidden])) .brand { flex: 0 1 auto; max-width: 300px; }
.etab { flex: 0 0 auto; min-width: 190px; max-width: 290px; text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; cursor: pointer; line-height: 1.3; font-size: 13px; }
.etab:hover { border-color: var(--muted); }
.etab.on { border-color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }
.etab-players { display: flex; align-items: center; gap: 6px; font-weight: 600; white-space: nowrap; overflow: hidden; }
.etab-players .n { overflow: hidden; text-overflow: ellipsis; }
.etab-players .sep { color: var(--muted); font-weight: 400; }
.etab .pc { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.etab .pc.w { background: #fff; box-shadow: 0 0 0 1px #999; } .etab .pc.b { background: #000; }
.etab-info { display: flex; align-items: center; gap: 8px; margin-top: 1px; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.etab-info .ev { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.etab-info .ttl { overflow: hidden; text-overflow: ellipsis; }

/* Layout */
.layout { display: grid; grid-template-columns: auto minmax(280px, 1fr) minmax(260px, 340px); gap: 16px; padding: 16px; align-items: start; max-width: 1600px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.infoCol { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
/* The info column is as tall as the board column; the standings take what is left
   (scrolling if needed), so resizing the board also shrinks or grows this column */
@media (min-width: 821px) {
  .infoCol { height: calc(var(--board) + 150px); min-height: 520px; }
  .infoPanel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .infoPanel .pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .infoPanel .tableWrap { flex: 1; min-height: 60px; overflow: auto; }
  .infoPanel .graphsPane .gbox { flex: 1; min-height: 0; }
  .infoPanel .graphsPane svg { flex: 1; min-height: 40px; height: auto; }
}
@media (max-width: 1180px) {
  .layout { grid-template-columns: auto 1fr; }
  .chatCol { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  /* No room beside the title: the tabs get their own line inside the header */
  .top { flex-wrap: wrap; }
  .eventTabs { order: 3; flex-basis: 100%; }
  .layout { grid-template-columns: 1fr; padding: 10px; gap: 12px; }
  .boardCol { justify-self: center; }
  .top { padding: 8px 12px; }
  .brand h1 { font-size: 15px; }
  .logo { font-size: 24px; }
  :root { --board: min(92vw - 26px, 560px); }
}

/* Players and clocks */
.boardCol { display: flex; flex-direction: column; gap: 8px; width: calc(var(--board) + 26px); }
.player { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.player .pc { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.player .pc.w { background: #fff; box-shadow: 0 0 0 1px #999; } .player .pc.b { background: #000; box-shadow: 0 0 0 1px #000; }
.player .pname { font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .pscore { color: #a8781c; font-weight: 600; }
.clock { font: 600 20px/1 ui-monospace, "Cascadia Mono", Consolas, monospace; padding: 6px 10px; border-radius: 7px; background: var(--panel2); min-width: 92px; text-align: right; font-variant-numeric: tabular-nums; }
.player.active { border-color: var(--accent); }
.player.active .clock { background: var(--accent); color: #1a1406; }
.clock.low { color: var(--live); }
.player.active .clock.low { background: var(--live); color: #fff; }

/* Board */
.boardWrap { display: flex; gap: 8px; position: relative; }
/* Drag handle at the board's bottom-right corner to make the board smaller or bigger */
.resizer { position: absolute; right: -7px; bottom: -7px; width: 20px; height: 20px; cursor: nwse-resize; touch-action: none; z-index: 2; border-radius: 4px;
  background: linear-gradient(135deg, transparent 45%, var(--muted) 45%, var(--muted) 52%, transparent 52%, transparent 64%, var(--muted) 64%, var(--muted) 71%, transparent 71%); opacity: .7; }
.resizer:hover, .resizer.dragging { opacity: 1; background-color: var(--panel2); }
@media (max-width: 820px) { .resizer { display: none; } }
.evalbar { width: 18px; height: var(--board); border-radius: 5px; background: #3a3f47; position: relative; overflow: hidden; flex-shrink: 0; }
.evalbar .fill { position: absolute; left: 0; right: 0; bottom: 0; background: #fff; transition: height .4s ease; height: 50%; }
.evalbar.flipped .fill { top: 0; bottom: auto; }
.evalbar span { position: absolute; left: 0; right: 0; text-align: center; font-size: 9.5px; font-weight: 700; mix-blend-mode: difference; color: #fff; bottom: 4px; }
.evalbar.flipped span { bottom: auto; top: 4px; }
.board { width: var(--board); height: var(--board); display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); border-radius: 6px; overflow: hidden; position: relative; box-shadow: 0 4px 16px rgba(0,0,0,.14); user-select: none; }
.sq { position: relative; display: flex; align-items: center; justify-content: center; }
.sq.l { background: var(--light); } .sq.d { background: var(--dark); }
.sq.hl::before { content: ""; position: absolute; inset: 0; background: var(--hl); }
.sq.chk::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle, var(--check) 0, rgba(229,72,77,.35) 45%, transparent 72%); }
.sq .coord { position: absolute; font-size: calc(var(--board) / 48); font-weight: 700; opacity: .75; pointer-events: none; }
.sq .coord.f { right: 3px; bottom: 1px; } .sq .coord.r { left: 3px; top: 1px; }
.sq.l .coord { color: var(--dark); } .sq.d .coord { color: var(--light); }
/* Merida piece set (SVG), drawn over the square */
.pc-img { position: relative; width: 92%; height: 92%; display: block; pointer-events: none; -webkit-user-drag: none; }
.arrows { position: absolute; inset: 0; pointer-events: none; }

/* Controls */
.controls { display: flex; gap: 6px; flex-wrap: wrap; }
.controls button, .btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer; text-decoration: none; line-height: 1.2; }
.controls button:hover, .btn:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: #1a1406; border-color: var(--accent); font-weight: 650; }
button.primary.off { background: var(--panel2); color: var(--text); border-color: var(--line); font-weight: 400; }
button.danger { background: transparent; border: 1px solid var(--live); color: var(--live); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.result { text-align: center; padding: 10px; border-radius: var(--radius); background: rgba(217,164,65,.14); border: 1px solid var(--accent); font-weight: 650; }

/* Engines */
.engines { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .engines { grid-template-columns: 1fr; } }
.engine { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.engine.thinking { border-color: var(--accent); }
.engine .head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; white-space: nowrap; }
.engine .head .pc { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.engine .head .pc.w { background: #fff; box-shadow: 0 0 0 1px #999; } .engine .head .pc.b { background: #000; box-shadow: 0 0 0 1px #000; }
.engine .head b { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.engine .head .tag { font-size: 10.5px; color: #a8781c; letter-spacing: .06em; }
.engine .score { font: 700 26px/1.1 ui-monospace, Consolas, monospace; }
/* Fixed heights so the panels (and the graph below) don't jump when a value gets longer */
.engine .stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 10px; margin: 8px 0; font-size: 12px; }
.engine .stats span { color: var(--muted); display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; }
.engine .stats b { display: block; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.engine .pv { font-size: 12.5px; color: #48505a; line-height: 1.55; height: 4.65em; overflow: hidden; word-break: break-word; }
.engine .pv .n { color: var(--muted); }
.engine .empty { color: var(--muted); font-size: 12.5px; }

/* Graph */
/* Standings / Graphs panel */
.ptabs { display: flex; align-items: baseline; gap: 4px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.ptab { background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 2px 8px 6px; cursor: pointer; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.ptab:hover:not(:disabled) { color: var(--text); }
.ptab.on { color: var(--text); border-bottom-color: var(--accent); }
.ptab:disabled { opacity: .4; cursor: default; }
.ptabs small { margin-left: 4px; color: #a8781c; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.graphsPane { gap: 8px; }
.gbox { display: flex; flex-direction: column; }
.glabel { display: flex; align-items: baseline; gap: 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 2px; }
.glabel small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.glabel .legend { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; text-transform: none; letter-spacing: 0; font-weight: 400; }
.legend .lg { display: inline-block; width: 14px; height: 2px; border-radius: 1px; margin-left: 6px; vertical-align: middle; }
.legend .lg.w { background: #a3abb5; } .legend .lg.b { background: #1f2328; }
.graphsPane svg { width: 100%; height: 90px; display: block; cursor: pointer; background: var(--panel2); border-radius: 4px; }

/* Moves */
/* Moves: compact running text across the bottom, "12.Nf3 Nc6 13.e4 ..."; at most 4 lines, then the
   box scrolls by itself (following the live end) so the page doesn't grow */
.movesCol { grid-column: 1 / -1; min-width: 0; }
.moves { position: relative; max-height: calc(1.55em * 4); overflow-y: auto; font-size: 13px; line-height: 1.55; font-variant-numeric: tabular-nums; }
.moves .num { color: var(--muted); margin-left: 3px; }
.moves .mv { padding: 0 2px; border-radius: 3px; cursor: pointer; font-weight: 600; }
.moves .mv:hover { background: var(--panel2); }
.moves .mv.cur { background: var(--accent); color: #1a1406; }

/* Standings (middle column, compact) */
.infoPanel { min-width: 0; }
.tableWrap { overflow-x: auto; }
.standings { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 13px; }
.standings th { text-align: right; font-weight: 600; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 5px 7px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.standings td { text-align: right; padding: 5px 7px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.standings th.name, .standings td.name { text-align: left; width: 100%; }
.standings td.name { font-weight: 600; }
.standings th.rank, .standings td.rank { text-align: right; color: var(--muted); width: 1%; }
.standings td.pts { font-weight: 700; }
.standings tbody tr:hover { background: var(--panel2); }
.standings tr.playing td { background: rgba(217,164,65,.14); }
.standings tr.playing td.name::after { content: " ●"; color: var(--live); font-size: 10px; vertical-align: 2px; }
.standings th.x, .standings td.x { text-align: center; min-width: 44px; }
.standings td.x.self { background: var(--panel2); }
.standings td.win { color: #2f8a46; } .standings td.loss { color: var(--live); } .standings td.draw { color: var(--muted); }
.standingsNotes { margin-top: 8px; color: var(--muted); font-size: 12px; line-height: 1.6; }

/* Chat */
.chatCol { display: flex; flex-direction: column; height: calc(var(--board) + 150px); min-height: 520px; }
@media (max-width: 1180px) { .chatCol { height: 420px; } }
.chat { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding-right: 4px; }
.msg { padding: 4px 8px; border-radius: 6px; word-break: break-word; position: relative; }
.msg:hover { background: var(--panel2); }
.msg .who { font-weight: 650; margin-right: 6px; }
.msg .t { color: var(--muted); font-size: 11px; margin-right: 6px; }
.msg.admin .who::after { content: " ★"; color: var(--accent); }
.msg.system { background: rgba(217,164,65,.12); border-left: 3px solid var(--accent); }
.msg .mod { display: none; position: absolute; right: 4px; top: 3px; gap: 4px; }
.isAdmin .msg:hover .mod { display: flex; }
.msg .mod button { font-size: 11px; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
/* Nickname in the chat header, so the message line gets the full width */
.chatHead { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.chatHead h2 { margin-bottom: 0; flex: 1; }
.chatHead #nick { width: 150px; min-width: 0; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 12.5px; }
.chatForm { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-top: 8px; }
.chatForm input { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.chatForm input:focus, .chatHead #nick:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.chatForm button { border-radius: 8px; padding: 0 14px; cursor: pointer; }
.chatErr { color: var(--live); font-size: 12px; min-height: 16px; margin-top: 4px; }
.adminBar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; padding: 8px; border-radius: 8px; background: rgba(217,58,63,.06); border: 1px dashed var(--live); }
.adminBar input { flex: 1; min-width: 120px; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
.adminBar button:not(.danger) { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
