/* The board pages (analysis, play the engine, and later live games): the board with its
   two hands, the evaluation gauge, the side panel with engine lines and the move list. */

/* ================================================================ layout */

.board-page {
  --board-height: clamp(440px, calc(100dvh - var(--topbar) - 34px), 1000px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 16px minmax(340px, 420px);
  grid-template-areas: "table gauge side" "under . side2";
  grid-template-rows: var(--board-height) auto;
  gap: 14px 10px;
  padding-top: 14px;
}
.board-page.no-gauge { grid-template-columns: minmax(0, 1fr) minmax(340px, 400px); grid-template-areas: "table side" "under side2"; column-gap: 16px; }

/* ================================================================ board and hands */

.board-area { grid-area: table; display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.board-wrap {
  position: relative; flex: 1; min-height: 0; background: var(--board);
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: inset 0 0 0 1px #00000026;
}
.board { display: block; width: 100%; height: 100%; touch-action: manipulation; user-select: none; -webkit-user-select: none; }

.hand {
  display: flex; align-items: center; gap: 10px; min-height: 54px; padding: 2px 6px 2px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.hand.active { border-color: var(--line-2); }
.hand .who {
  flex: none; width: 64px; color: var(--dim); font-weight: 650; font-size: 13px;
  display: flex; align-items: center; gap: 7px;
}
.hand .who::before { content: ""; width: 12px; height: 12px; border-radius: 3px; flex: none; }
.hand[data-colour="0"] .who::before { background: var(--tile-white); box-shadow: 0 0 0 1px #0004; }
.hand[data-colour="1"] .who::before { background: var(--tile-black); box-shadow: 0 0 0 1px #fff3; }
.hand .who.to-move { color: var(--text-strong); }
.hand .who.to-move::after { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px #5fb85a33; }
.reserves { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; min-width: 0; }
.hand-empty { color: var(--faint); font-size: 12.5px; }
.reserve { position: relative; width: 46px; height: 50px; padding: 0; border: 0; background: none; border-radius: 8px; flex: none; }
.reserve svg { width: 100%; height: 100%; display: block; }
.reserve:hover:not(:disabled) { background: var(--hover); }
.reserve:disabled { opacity: .55; cursor: default; }
.reserve.picked { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.reserve b {
  position: absolute; right: -2px; bottom: 1px; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--panel); border: 1px solid var(--line-2);
  font-size: 11px; line-height: 15px; text-align: center; color: var(--text); font-weight: 650;
}

/* On the board */
.piece { cursor: pointer; }
.piece.raised > .tile > .face { filter: drop-shadow(0 5px 3px #0009); }
.piece.picked > .tile > .face { stroke: var(--accent); stroke-width: 9; }
.piece .under .face { stroke: #8f9aa6; stroke-width: 14; }
.last { fill: #f0b42926; stroke: #f0b42990; stroke-width: 3; stroke-linejoin: round; }
.last.from { fill: none; stroke-dasharray: 9 8; }
.target { cursor: pointer; }
.target .area { fill: transparent; }
.target circle { fill: #63b95cb8; }
.target.climb circle { fill: none; stroke: #63b95cd9; stroke-width: 7; }
.target:hover circle { fill: #7bd373; }
.target.climb:hover circle { fill: #63b95c40; }
.arrow, .ghost { pointer-events: none; }
.arrow path { stroke: #4aa3ffd9; fill: none; stroke-linecap: round; }
.arrow polygon { fill: #4aa3ff; }
.ghost { opacity: .55; }
.ghost .face { stroke: #4aa3ff; stroke-width: 9; filter: none !important; }

.board-banner {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: color-mix(in srgb, var(--bg) 92%, transparent); border: 1px solid var(--line-2); border-radius: var(--radius-lg);
  padding: 8px 20px; font-size: 16px; font-weight: 650; color: var(--text-strong); box-shadow: var(--shadow);
  white-space: nowrap;
}
.pass-button { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); box-shadow: var(--shadow); }

/* Dragging pieces (analysis board) */
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 1000; pointer-events: none; will-change: transform;
  filter: drop-shadow(0 12px 10px #0009); transition: opacity .12s;
}
.drag-ghost svg { display: block; width: 100%; height: 100%; }
html.dragging, html.dragging * { cursor: grabbing !important; }
html.drag-off .drag-ghost { opacity: .4; }
.drag-enabled .reserve:not(:disabled), .drag-enabled .board .piece.top { touch-action: none; }
.piece.lifted { opacity: .28; }
.reserve.lifted { opacity: .35; }
.cells .cell { fill: #ffffff06; stroke: #ffffff30; stroke-width: 2; stroke-dasharray: 7 6; pointer-events: none; }
[data-theme="light"] .cells .cell { fill: #ffffff26; stroke: #0000002e; }
.hover { pointer-events: none; }
.drop polygon { fill: #63b95c2e; stroke: #63b95c; stroke-width: 5; stroke-linejoin: round; }
.drop.bad polygon { fill: #e5534b2e; stroke: var(--bad); }
.drop.shake { animation: shake .42s ease-in-out; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.remover { cursor: pointer; }
.remover circle { fill: var(--bad); stroke: var(--board); stroke-width: 4; }
.remover path { stroke: #fff; stroke-width: 3.2; stroke-linecap: round; }
.remover:hover circle { fill: #f0675f; }

/* The board editor (analysis board): its panel takes the place of the engine and moves */
.editor-panel { display: none; flex-direction: column; flex: 1; min-height: 0; }
.editing .editor-panel { display: flex; }
.editing .side > :not(.editor-panel) { display: none; }
.editing .gauge { visibility: hidden; }
.editing .board { touch-action: none; }
.editing .reserve { touch-action: none; cursor: grab; }
.editing .reserve:disabled { opacity: 1; }
.editing .board-wrap { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent); }
.editing .piece { cursor: grab; }
.editor-head {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px; min-height: 58px;
  background: var(--panel-2); border-bottom: 1px solid var(--line);
}
.editor-head h2 { margin: 0; font-size: 16px; font-weight: 650; color: var(--text-strong); }
.editor-head svg, .setup-row .btn svg, .editor-tools svg {
  width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.editor-head svg { color: var(--accent); width: 20px; height: 20px; }
.editor-state { padding: 14px 14px 0; }
.editor-body { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.editor-hint { margin: 0; color: var(--dim); font-size: 13px; line-height: 1.55; }
.editor-row { display: flex; align-items: center; gap: 12px; }
.editor-label { flex: none; width: 64px; color: var(--dim); font-weight: 650; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; }
.editor-side { flex: 1; max-width: 260px; }
.editor-side > button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.editor-panel .swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; flex: none; box-shadow: 0 0 0 1px #0005; }
.editor-panel .swatch.white { background: var(--tile-white); }
.editor-panel .swatch.black { background: var(--tile-black); box-shadow: 0 0 0 1px #fff3; }
.editor-advanced summary {
  cursor: pointer; color: var(--dim); font-size: 13px; font-weight: 600; list-style: none; display: inline-flex; align-items: center; gap: 8px;
}
.editor-advanced summary::-webkit-details-marker { display: none; }
.editor-advanced summary::before {
  content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform .15s;
}
.editor-advanced[open] summary::before { transform: rotate(45deg); }
.editor-advanced summary:hover { color: var(--text); }
.editor-advanced > .editor-row { margin-top: 10px; }
.editor-turn { width: 110px; }
.editor-note { margin: 8px 0 0; color: var(--faint); font-size: 12px; line-height: 1.5; }
.editor-status {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--good) 12%, transparent); border: 1px solid color-mix(in srgb, var(--good) 40%, transparent);
  color: var(--text-strong); font-weight: 600; font-size: 13.5px; line-height: 1.45;
}
.editor-status .dot { flex: none; width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: var(--good); }
.editor-status.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.editor-status.bad .dot { background: var(--bad); }
.editor-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.editor-tools .btn { gap: 6px; }
.editor-tools svg { width: 15px; height: 15px; }
.editor-actions { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); background: var(--panel-2); flex: none; }
.editor-actions .btn { flex: 1; min-height: 40px; }

/* ================================================================ evaluation gauge */

.gauge {
  grid-area: gauge; position: relative; background: var(--gauge-black); border-radius: 4px; overflow: hidden;
  margin: 60px 0; box-shadow: inset 0 0 0 1px #0005;
}
.gauge.off { visibility: hidden; }
.gauge-white { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: var(--gauge-white); transition: height .35s ease; }
.gauge .tick { position: absolute; left: 0; right: 0; border-top: 1px solid #8884; }
.gauge .zero { position: absolute; left: -1px; right: -1px; top: 50%; border-top: 2px solid var(--bad); }

/* ================================================================ side panel */

.side {
  grid-area: side; display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden;
}
.side-section { border-bottom: 1px solid var(--line); }

/* The engine's header: switch, evaluation, name and speed, settings */
.engine-head { display: flex; align-items: center; gap: 12px; padding: 9px 8px 9px 12px; background: var(--panel-2); min-height: 58px; }
.eval { font-size: 26px; font-weight: 700; min-width: 80px; font-variant-numeric: tabular-nums; color: var(--text-strong); letter-spacing: -.01em; }
.engine-meta { flex: 1; min-width: 0; color: var(--dim); font-size: 12px; line-height: 1.4; }
.engine-name { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.engine-stats { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.engine-off .eval { color: var(--faint); }

.pv-lines { list-style: none; margin: 0; padding: 0; font-family: var(--mono); font-size: 12.5px; }
.pv-lines:empty { display: none; }
.pv-lines li { display: flex; gap: 8px; align-items: baseline; padding: 5px 12px; border-top: 1px solid var(--line); min-height: 30px; }
.pv-lines li:hover { background: var(--hover); }
.line-score { width: 48px; flex: none; font-weight: 700; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.line-moves { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--dim); }
.pv { cursor: pointer; padding: 1px 3px; border-radius: 3px; margin-right: 3px; color: var(--text); }
.pv:hover { background: var(--accent); color: var(--accent-ink); }
.num { color: var(--faint); margin-right: 2px; }
.share { color: var(--dim); font-size: 11.5px; flex: none; font-variant-numeric: tabular-nums; }

/* The move list */
.moves { flex: 1; min-height: 80px; overflow-y: auto; font-family: var(--mono); font-size: 13px; overscroll-behavior: contain; }
.moves .row { display: grid; grid-template-columns: 40px 1fr 1fr; }
.moves .index {
  background: var(--panel-2); color: var(--faint); text-align: center; padding: 5px 0;
  border-right: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.move { display: flex; justify-content: space-between; gap: 6px; padding: 5px 10px; cursor: pointer; white-space: nowrap; color: var(--text); }
.move.empty { cursor: default; color: var(--faint); }
.move:not(.empty):hover { background: var(--hover); }
.move.active { background: var(--select); color: #fff; }
.move .score { color: var(--faint); font-size: 11px; align-self: center; font-variant-numeric: tabular-nums; }
.move.active .score { color: #d6e6fa; }
.variations { background: var(--bg-2); border-block: 1px solid var(--line); padding: 4px 10px 4px 14px; }
.variation { padding: 2px 0 2px 10px; border-left: 2px solid var(--line-2); line-height: 1.8; }
.move.inline { display: inline-flex; padding: 0 4px; border-radius: 3px; margin-right: 3px; }
.move.inline .score { display: none; }
.sub { color: var(--faint); margin-right: 3px; }
.empty-note { color: var(--dim); font-family: var(--font); font-size: 13px; padding: 14px; margin: 0; line-height: 1.55; }
.result-row { text-align: center; padding: 10px; font-family: var(--font); font-weight: 650; color: var(--text-strong); border-top: 1px solid var(--line); }

/* Buttons under the move list */
.move-controls { display: flex; border-top: 1px solid var(--line); background: var(--panel-2); flex: none; }
.move-controls button {
  flex: 1; border: 0; border-radius: 0; background: none; padding: 9px 0; display: grid; place-items: center; color: var(--dim);
}
.move-controls button.aux { flex: 0 0 46px; }
.move-controls button:hover:not(:disabled) { background: var(--hover); color: var(--text-strong); }
.move-controls button:disabled { opacity: .35; }
.move-controls svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.move-controls .nav-step svg { fill: currentColor; stroke-width: 1.2; }

/* ================================================================ under the board */

.underboard { grid-area: under; display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 8px 12px; align-items: start; padding: 14px 16px; }
.underboard > label { color: var(--dim); font-weight: 650; padding-top: 8px; text-transform: uppercase; font-size: 11.5px; letter-spacing: .06em; }
.copy-row { display: flex; gap: 8px; align-items: flex-start; }
.copy-row .input, .copy-row .textarea { flex: 1; min-width: 0; }
.copy-row .textarea { min-height: 60px; }
.copy-row .btn-col { display: flex; flex-direction: column; gap: 6px; }
.underboard .form-error { grid-column: 2; }
.underboard .form-error:empty { display: none; }
.underboard > .setup-label { color: var(--dim); font-weight: 650; padding-top: 8px; text-transform: uppercase; font-size: 11.5px; letter-spacing: .06em; }
.setup-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.setup-row .btn { gap: 7px; }
.setup-row .hint { color: var(--faint); font-size: 12.5px; margin-top: 0; }
.move.start-row { font-family: var(--font); font-size: 12.5px; font-weight: 600; color: var(--dim); background: var(--bg-2); border-bottom: 1px solid var(--line); justify-content: flex-start; }
.move.start-row.active { background: var(--select); color: #fff; }
.underboard .hint { grid-column: 2; color: var(--faint); font-size: 12px; margin-top: -4px; }

/* The thinking bar (play pages) */
.think-bar { height: 3px; background: var(--line); overflow: hidden; position: relative; }
.think-bar > div { height: 100%; width: 0; background: var(--accent); }
.think-bar.indeterminate > div { width: 35%; position: absolute; animation: sweep 1.1s ease-in-out infinite; }
@keyframes sweep { from { left: -35%; } to { left: 100%; } }

/* ================================================================ narrow windows */

@media (max-width: 1100px) {
  .board-page { grid-template-columns: minmax(0, 1fr) 14px 340px; }
  .board-page.no-gauge { grid-template-columns: minmax(0, 1fr) 340px; }
}

@media (max-width: 860px) {
  .board-page, .board-page.no-gauge {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas: "table" "side" "side2" "under";
    padding-top: 8px; gap: 10px;
  }
  .board-area { height: min(calc(100vw + 80px), 76dvh, 680px); gap: 4px; }
  .gauge { display: none; }
  .side { max-height: 70dvh; }
  .moves { min-height: 150px; }
  .hand { min-height: 46px; padding: 2px 4px 2px 8px; gap: 6px; }
  .hand .who { width: 8px; font-size: 0; gap: 0; }
  .hand .who::before { display: none; }
  .reserves { flex-wrap: nowrap; gap: 0; }
  .reserve { width: 36px; height: 40px; }
  .reserve b { min-width: 15px; height: 15px; font-size: 10px; line-height: 13px; }
  .underboard { grid-template-columns: minmax(0, 1fr); padding: 12px; }
  .underboard > label { padding-top: 4px; }
  .underboard .form-error, .underboard > .hint { grid-column: 1; }
  .underboard > .setup-label { padding-top: 4px; }
  .editing .side { max-height: none; }
  .editor-body { overflow: visible; order: 3; }
  /* On a phone the state of the position and Analyse come first, right under the board. */
  .editor-head { min-height: 46px; }
  .editor-state { order: 1; padding: 12px 12px 0; }
  .editor-actions { order: 2; border-top: 0; background: none; padding: 10px 12px 0; }
  .editor-body { padding: 14px 12px; }
  .eval { font-size: 22px; min-width: 66px; }
}
