/* ============================================================================
   Hand-drawn skin over chessground.
   The board layer is drawn as SVG by main.js (wobbly grid, hatched dark
   squares); chessground keeps its own DOM for squares/pieces so drag, legal
   move dots and accessibility all still work.
   ========================================================================== */

:root {
  --paper: #f6f1e7;
  --paper-2: #efe7d8;
  --desk: #e4dac6;
  --ink: #1b1a17;
  --ink-40: rgba(27, 26, 23, .40);
  --ink-18: rgba(27, 26, 23, .18);
  --ink-08: rgba(27, 26, 23, .08);
  --line: rgba(27, 26, 23, .14);
  --c0: #d94f2b;
  --c1: #3a4c8c;
  --c2: #c98a22;
  --danger: #c0392b;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Any `display` rule outranks the UA stylesheet's [hidden] { display: none },
   so a styled panel (like .board-overlay) would stay visible forever and eat
   clicks. Force the attribute to win. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ------------------------------------------------------------- banner ---- */
.banner {
  padding: 10px 18px;
  font-size: 12.5px;
  line-height: 1.55;
  background: #fbe9e7;
  border-bottom: 1px solid rgba(192, 57, 43, .35);
  color: #7d211a;
}
.banner[hidden] { display: none; }
.banner b { font-weight: 700; }
.banner code {
  font-family: var(--mono);
  font-size: 11.5px;
  background: rgba(27, 26, 23, .08);
  padding: 1px 5px;
  border-radius: 4px;
}
.banner a { color: inherit; font-weight: 700; }

.app { flex: 1; min-height: 0; display: grid; grid-template-rows: auto 1fr; }

.login-fallback {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px dashed rgba(58, 76, 140, .45);
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.6;
  background: rgba(58, 76, 140, .05);
}
.login-fallback[hidden] { display: none; }
.login-fallback a { color: var(--c1); font-weight: 700; }
.login-fallback code {
  font-family: var(--mono);
  font-size: 10.5px;
  word-break: break-all;
  display: block;
  margin-top: 6px;
  color: var(--ink-40);
}

/* ------------------------------------------------ personal token entry --- */
details.alt {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
details.alt > summary {
  cursor: pointer;
  font-size: 11.5px;
  color: var(--ink-40);
  letter-spacing: .04em;
  list-style: none;
}
details.alt > summary::-webkit-details-marker { display: none; }
details.alt > summary::before { content: '+ '; }
details.alt[open] > summary::before { content: '– '; }
details.alt > summary:hover { color: var(--ink); }
details.alt .tiny a { color: var(--c1); font-weight: 600; }
details.alt .tiny code {
  font-family: var(--mono);
  font-size: 10.5px;
  background: rgba(27, 26, 23, .07);
  padding: 1px 4px;
  border-radius: 3px;
}
.token-row { display: flex; gap: 6px; margin-top: 8px; }
.token-row input {
  flex: 1;
  min-width: 0;
  font: 12px var(--mono);
  padding: 7px 9px;
  border: 1px solid var(--ink-18);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
}
.token-row input:focus { outline: 2px solid var(--ink); outline-offset: 1px; }

/* ------------------------------------------------------------------ bar -- */
.bar {
  display: flex; align-items: center; gap: 16px;
  padding: 9px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, .5), rgba(255, 255, 255, 0));
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand b { font-size: 15px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; }
.brand span { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-40); }
.bar-right { margin-left: auto; display: flex; align-items: center; gap: 9px; }
.who { font-size: 12px; color: var(--ink-40); }
.who b { color: var(--ink); font-weight: 600; }

/* ----------------------------------------------------------------- main -- */

/* The right column holds the machine; --panel-w is set by the splitter (default
   ~30% of the viewport) so the board keeps the rest. */
main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 9px var(--panel-w, 30%);
  min-height: 0;
}

.splitter {
  position: relative;
  cursor: col-resize;
  touch-action: none;
  border: 0;
  padding: 0;
  background: transparent;
}
.splitter::before {
  content: '';
  position: absolute;
  inset: 0 4px;
  border-radius: 2px;
  background: linear-gradient(to right, transparent, var(--ink-18), transparent);
  transition: background 120ms ease;
}
.splitter::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: 34px;
  transform: translate(-50%, -50%);
  border-radius: 2px;
  background: var(--ink-18);
  transition: background 120ms ease, height 120ms ease;
}
.splitter:hover::before,
.splitter:focus-visible::before { background: var(--ink-40); }
.splitter:hover::after,
.splitter:focus-visible::after,
.splitter.dragging::after { background: var(--ink); height: 54px; }
.splitter.dragging::before { background: var(--ink-40); }
.splitter:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }

.board-col {
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 8px; padding: 14px 18px; min-width: 0; min-height: 0;
}

.player {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--ink-40); min-height: 26px;
}
.player .pname { color: var(--ink); font-weight: 600; }
.player .prating { font-family: var(--mono); font-size: 11.5px; }
.player .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-18); }
.player.white .dot { background: var(--paper); border: 1.5px solid var(--ink); }
.player.black .dot { background: var(--ink); }
.player.active .pname { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.player .clock {
  margin-left: auto; font-family: var(--mono); font-size: 17px; font-weight: 600;
  color: var(--ink); font-variant-numeric: tabular-nums;
}
.player.active .clock { color: var(--c1); }
.player .clock.low { color: var(--danger); }

.board-wrap { position: relative; display: grid; place-items: center; min-height: 0; }

/* ------------------------------------------------------------ the board -- */
.cg-wrap {
  position: relative;
  width: min(100%, 74dvh);
  aspect-ratio: 1;
  border-radius: 2px;
  box-shadow: 0 18px 40px -22px rgba(27, 26, 23, .5), 0 2px 0 rgba(27, 26, 23, .06);
}

/* the hand-drawn layer sits *under* chessground's pieces and highlight squares */
.cg-wrap .sketch {
  position: absolute; inset: 0; z-index: 0;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  /* no SVG displacement filter here on purpose: it clipped the grid lines at
     some noise seeds, making them intermittently invisible. The boil is now a
     background-image swap of three pre-baked variants (see main.js). */
  pointer-events: none;
}
.cg-wrap.boil-off .sketch { filter: none; }

cg-board { background: none !important; z-index: 1; }

/* chessground highlights, styled as pencil marks */
cg-board square.last-move { background-color: rgba(201, 138, 34, .26); }
cg-board square.check {
  background: radial-gradient(circle at center, rgba(192, 57, 43, .78) 0%, rgba(192, 57, 43, .34) 42%, transparent 72%);
}
cg-board square.move-dest {
  background: radial-gradient(circle at center, rgba(27, 26, 23, .30) 19%, transparent 21%);
}
cg-board square.oc.move-dest {
  background: radial-gradient(circle at center, transparent 0%, transparent 78%, rgba(27, 26, 23, .28) 80%);
}
cg-board square.selected { background-color: rgba(58, 76, 140, .18); }
cg-board square.current-premove { background-color: rgba(58, 76, 140, .25); }

/* pieces: lichess's own cburnett set, inked and shadowed like a drawing */
.cg-wrap piece {
  filter: drop-shadow(1.5px 2px 0 rgba(27, 26, 23, .18));
}
.cg-wrap piece.anim { transition: none; }
.cg-wrap piece.fading { opacity: .42; }

.cg-wrap coords coord { color: var(--ink-40); font-family: var(--mono); font-size: 10px; }

/* ------------------------------------------------------- promo overlay --- */
.board-overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(246, 241, 231, .72); z-index: 20; backdrop-filter: blur(1px);
}
.promo {
  background: var(--paper); border: 1.5px solid var(--ink); border-radius: 10px;
  padding: 14px 16px; box-shadow: 0 12px 30px -16px rgba(27, 26, 23, .6);
}
.promo-title { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-40); margin-bottom: 9px; }
.promo-row { display: flex; gap: 8px; }
.promo-row button {
  width: 54px; height: 54px; border: 1px solid var(--ink-18); border-radius: 8px;
  background: var(--paper-2); cursor: pointer; font-size: 30px; line-height: 1;
}
.promo-row button:hover { background: #fff; border-color: var(--ink); }

/* ---------------------------------------------------------------- panel -- */
.panel {
  border-left: 1px solid var(--line); overflow-y: auto; overscroll-behavior: contain;
  padding: 14px; display: flex; flex-direction: column; gap: 11px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .34), rgba(255, 255, 255, 0));
}
.card {
  background: rgba(255, 255, 255, .5); border: 1px solid var(--line);
  border-radius: 9px; padding: 13px;
}
.card h2 {
  margin: 0 0 8px; font-size: 10px; letter-spacing: .17em; text-transform: uppercase;
  font-weight: 700; color: var(--ink-40);
}
.card h3 { margin: 14px 0 7px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-40); }
.muted { font-size: 12.5px; color: var(--ink-40); margin: 0 0 10px; line-height: 1.55; }
.tiny { font-size: 11px; color: var(--ink-40); line-height: 1.5; margin: 9px 0 0; }

button {
  font: inherit; color: inherit; background: none; border: 1px solid var(--ink-18);
  border-radius: 8px; padding: 8px 12px; cursor: pointer;
  transition: background .16s ease, transform .1s ease, border-color .16s ease, opacity .16s;
}
button:hover:not(:disabled) { background: rgba(27, 26, 23, .055); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
button.primary {
  width: 100%; padding: 12px; font-weight: 600; letter-spacing: .04em;
  background: var(--ink); color: var(--paper); border-color: var(--ink);
}
button.primary:hover:not(:disabled) { background: #000; }
button.ghost { font-size: 12px; padding: 7px 11px; }
button.small { font-size: 11px; padding: 6px 10px; }
button.danger { color: var(--danger); border-color: rgba(192, 57, 43, .3); }
.row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin: 10px 0; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-40); }
.field input { width: 74px; font: 600 13px var(--mono); padding: 7px 8px; border: 1px solid var(--ink-18); border-radius: 7px; background: var(--paper); color: var(--ink); }
.field select {
  font: 600 13px var(--sans);
  padding: 7px 8px;
  border: 1px solid var(--ink-18);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.field select:focus { outline: 2px solid var(--ink); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-40); padding-bottom: 8px; }

/* ---------------------------------------------------------- candidates -- */
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 4px; }
.slot {
  border: 1.5px dashed var(--ink-18); border-radius: 9px; padding: 9px;
  min-height: 82px; display: flex; flex-direction: column; gap: 3px; position: relative;
  transition: border-color .2s, background .2s, transform .18s cubic-bezier(.22, 1, .36, 1);
}
.slot.filled { border-style: solid; background: rgba(255, 255, 255, .6); }
.slot .sig { font-size: 13px; line-height: 1; }
.slot .san { font: 600 17px var(--mono); letter-spacing: .01em; }
.slot .hint { font-size: 10px; color: var(--ink-40); letter-spacing: .06em; text-transform: uppercase; }
.slot .x {
  position: absolute; top: 4px; right: 5px; width: 18px; height: 18px; padding: 0;
  border: 0; font-size: 13px; line-height: 1; color: var(--ink-40); border-radius: 50%;
}
.slot .x:hover { background: rgba(27, 26, 23, .1); color: var(--ink); }
.slot.pop { animation: pop .26s cubic-bezier(.22, 1, .36, 1); }
@keyframes pop { from { transform: scale(.9); opacity: .4 } to { transform: scale(1); opacity: 1 } }

/* ------------------------------------------------------------- machine -- */
#machine {
  display: block; width: 100%; aspect-ratio: 1200 / 876;
  border-radius: 3px; margin-top: 11px;
  box-shadow: 0 10px 24px -16px rgba(27, 26, 23, .5);
}
.drop-result { font-size: 12.5px; min-height: 18px; margin-top: 9px; color: var(--ink-40); }
.drop-result b { color: var(--ink); }
.drop-result .win { font-weight: 600; }

/* ------------------------------------------------------------------ log -- */
.log { font-family: var(--mono); font-size: 11px; line-height: 1.6; color: var(--ink-40); max-height: 150px; overflow-y: auto; }
.log div { padding: 1px 0; }
.log .err { color: var(--danger); }
.log .ok { color: #4f7a4a; }

.seat { margin: 12px 0; }
.seat-label { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-40); margin-bottom: 5px; }
.seat-link { display: inline-block; font-weight: 600; color: var(--c1); text-decoration: none; border-bottom: 2px solid rgba(58, 76, 140, .3); }
.seat-link:hover { border-bottom-color: var(--c1); }
.copy-row { display: flex; gap: 6px; }
.copy-row input { flex: 1; font: 12px var(--mono); padding: 7px 8px; border: 1px solid var(--ink-18); border-radius: 7px; background: var(--paper); color: var(--ink); min-width: 0; }

.alt-path {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.alt-path-title {
  font-size: 11px;
  letter-spacing: .06em;
  color: var(--ink-40);
  margin-bottom: 2px;
}
#challenge-status {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  background: rgba(58, 76, 140, .07);
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink);
}
#challenge-status[hidden] { display: none; }
#challenge-status b { font-weight: 700; }

.challenge-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 0;
  border-top: 1px solid var(--line); font-size: 12.5px;
}
.challenge-item .who { flex: 1; }

/* the one-time intro note */
.intro {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(227, 215, 189, .34);
}
.intro-text { flex: 1; min-width: 0; }
.intro-line {
  margin: 0;
  font: 600 14px var(--sans);
  color: var(--ink);
  letter-spacing: -.005em;
}
.intro-sub {
  margin: 4px 0 0;
  font: 400 12.5px var(--sans);
  line-height: 1.45;
  color: var(--ink-40);
}
.intro-close {
  flex: none;
  width: 26px; height: 26px;
  padding: 0;                 /* UA button padding of 1px 6px was shifting the glyph */
  box-sizing: border-box;
  display: grid; place-items: center;
  color: var(--ink-40);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
/* the glyph is an SVG so it is optically centred, not at the mercy of font metrics */
.intro-close svg { display: block; }
.intro-close:hover {
  color: var(--ink);
  border-color: var(--ink-18);
  background: rgba(246, 241, 231, .8);
}

@media (max-width: 1040px) {
  main { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .splitter { display: none; }
  .panel { border-left: 0; border-top: 1px solid var(--line); max-height: 52dvh; }
  .cg-wrap { width: min(100%, 58dvh); }
}

/* ---------------------------------------------------- probability bars -- */

.prob { margin-top: 12px; }

.prob-title {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
  font: 600 11.5px var(--sans);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink);
  margin-bottom: 10px;
}
.prob-title .muted {
  font: 400 10.5px var(--sans);
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-40);
}

.prob-bars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.prob-bar { display: grid; grid-template-rows: 78px auto auto; min-width: 0; }
.prob-track { position: relative; }
.prob-fill {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 46px;
  min-height: 3px;
  border: 1.5px solid var(--ink);
  border-bottom: 0;
  border-radius: 3px 3px 0 0;
  transition: height 480ms cubic-bezier(.22,.61,.36,1), background 200ms linear;
}
.prob-label {
  margin-top: 6px;
  text-align: center;
  font: 600 10.5px var(--mono);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.prob-ord {
  margin-top: 1px;
  text-align: center;
  font: 500 9.5px var(--sans);
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--ink-40);
}
