/*
 * bb-session.css: the "session" view of a board page. One position, the board as the
 * page, the move verdict directly under the board, nothing that needs scrolling.
 *
 * Shared on purpose: built for the endgame trainer first, meant for the report drills
 * and a signed-out teaser next. Nothing in here knows about the trainer. Pair with
 * app/static/js/bb-verdict.js (badges + pips).
 *
 * Structure (phone order top to bottom; desktop puts .bb-col-side beside the board):
 *   .bb-session
 *     .bb-session-bar            way back + where you are
 *     .bb-col-board
 *       .bb-board-area           the board (and anything laid over it)
 *       .bb-controls             icon buttons
 *     .bb-col-side
 *       .bb-goal                 goal title, count, pips
 *       .bb-verdict              what the last move did (fixed height: the board never jumps)
 *       .bb-slip                 shown instead of the controls after a mistake
 *       .bb-extras               everything else, quiet
 *
 * Motion is transform/opacity only and switches off under prefers-reduced-motion.
 * No backdrop-filter anywhere, so there is nothing to fall back from on in-app browsers.
 */

.bb-session {
  --bb-good: #22c55e;
  --bb-good-deep: #1a8f47;
  --bb-found: #4a90e2;
  --bb-warn: #f5b740;
  --bb-mistake: #f08a4b;
  --bb-bad: #ef6b6b;
  --bb-quiet: #5b6460;
  --bb-line: rgba(255,255,255,0.09);
  /* Board edge: as wide as the screen allows, but never so tall that the verdict and the
     controls fall off the bottom. vh first for browsers without dvh. */
  --bb-board: max(240px, min(calc(100vw - 16px), calc(100vh - 292px), 560px));
  --bb-board: max(240px, min(calc(100vw - 16px), calc(100dvh - 292px), 560px));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bb-col-board, .bb-col-side { display: contents; }
.bb-session-bar { order: 0; }
.bb-goal        { order: 1; }
.bb-board-area  { order: 2; }
.bb-verdict     { order: 3; }
.bb-controls    { order: 4; }
.bb-slip        { order: 4; }
.bb-extras      { order: 5; }

/* ── Bar ─────────────────────────────────────────────────────────────── */
.bb-session-bar {
  display: flex; align-items: center; gap: 12px;
  min-height: 36px;
  font-size: 12.5px; color: var(--muted, rgba(255,255,255,0.65));
}
.bb-session-back {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 36px; padding: 0 8px 0 0;
  background: none; border: none; cursor: pointer;
  font: inherit; font-weight: 600; color: rgba(255,255,255,0.85);
  -webkit-tap-highlight-color: transparent;
}
.bb-session-back svg { width: 16px; height: 16px; }
.bb-session-back:hover { color: #fff; }
.bb-session-where {
  margin-left: auto; min-width: 0; text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bb-session-next {
  display: inline-flex; align-items: center; gap: 2px; flex: none;
  min-height: 36px; padding: 0 0 0 8px;
  background: none; border: none; cursor: pointer;
  font: inherit; font-weight: 600; color: rgba(255,255,255,0.85);
  -webkit-tap-highlight-color: transparent;
}
.bb-session-next svg { width: 16px; height: 16px; }
.bb-session-next:hover { color: #fff; }

/* ── Goal ────────────────────────────────────────────────────────────── */
.bb-goal-side { font-size: 12px; color: var(--muted, rgba(255,255,255,0.65)); }
.bb-goal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.bb-goal-title {
  font-family: var(--font-display, Georgia, serif);
  font-size: 19px; font-weight: 600; letter-spacing: -0.2px; line-height: 1.25;
}
.bb-goal-count { font-size: 12.5px; color: var(--muted, rgba(255,255,255,0.65)); white-space: nowrap; }
/* Key idea: a collapsed plain-words definition under the goal (drill pages). */
.bb-idea { margin-top: 6px; }
.bb-idea > summary {
  display: inline-block; cursor: pointer; list-style: none; padding: 6px 0;
  font-size: 12.5px; color: var(--muted, rgba(255,255,255,0.65));
  text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px;
}
.bb-idea > summary::-webkit-details-marker { display: none; }
.bb-idea[open] > summary { color: rgba(255,255,255,0.88); text-decoration: none; }
.bb-idea > p { margin: 2px 0 4px; font-size: 13px; line-height: 1.55; color: var(--muted, rgba(255,255,255,0.65)); max-width: 60ch; }
.bb-goal-sub { display: none; font-size: 13px; line-height: 1.5; color: var(--muted, rgba(255,255,255,0.65)); margin-top: 4px; }

/* Pips: one per move of yours. With a target they are slots to fill; without one they
   are a trail. */
.bb-pips { display: flex; gap: 3px; margin-top: 8px; min-height: 6px; }
.bb-pips i {
  display: block; flex: 1 1 0; height: 6px; border-radius: 3px;
  background: rgba(255,255,255,0.10);
  transition: background-color .25s ease, transform .25s ease;
}
.bb-pips.bb-trail i { flex: 0 0 14px; }
.bb-pips i.best, .bb-pips i.found { background: var(--bb-good); }
.bb-pips i.good, .bb-pips i.hold  { background: var(--bb-good-deep); }
.bb-pips i.found { background: var(--bb-found); }
.bb-pips i.inaccuracy { background: transparent; box-shadow: inset 0 0 0 1.5px var(--bb-warn); }
.bb-pips i.mistake { background: var(--bb-mistake); transform: scaleY(1.6); }
.bb-pips i.blunder { background: var(--bb-bad); transform: scaleY(1.6); }
.bb-pips i.try, .bb-pips i.none { background: var(--bb-quiet); }
.bb-pips i.checking { background: rgba(255,255,255,0.28); }
.bb-pips i.bb-new { animation: bb-pip-in .3s ease-out; }
@keyframes bb-pip-in { from { transform: scaleX(.2); opacity: .2; } to { transform: none; opacity: 1; } }

/* ── Board ───────────────────────────────────────────────────────────── */
.bb-board-area { display: flex; justify-content: center; }
.bb-board-frame { position: relative; }
.bb-session .board-wrap {
  width: var(--bb-board);
  margin: 0;
  --sq-size: calc(var(--bb-board) / 8);
  box-shadow: none;
}

/* Verdict badge on the square the piece landed on. */
.bb-vbadge {
  position: absolute; top: 3%; right: 3%; z-index: 4;
  width: 36%; height: 36%; min-width: 15px; min-height: 15px; max-width: 24px; max-height: 24px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font: 700 11px/1 var(--font-body, system-ui, sans-serif);
  letter-spacing: -0.5px;
  pointer-events: none;
  box-shadow: 0 0 0 1.5px rgba(0,0,0,0.55);
}
.bb-vbadge svg { width: 62%; height: 62%; display: block; }
.bb-vbadge.bb-pop { animation: bb-badge-pop .26s cubic-bezier(.3,1.6,.5,1); }
@keyframes bb-badge-pop { from { transform: scale(0); } to { transform: scale(1); } }
.bb-vbadge.found      { background: var(--bb-found);     color: #04182e; }
.bb-vbadge.best       { background: var(--bb-good);      color: #06210f; }
.bb-vbadge.good,
.bb-vbadge.hold       { background: var(--bb-good-deep); color: #eafff1; }
.bb-vbadge.inaccuracy { background: var(--bb-warn);      color: #3a2600; }
.bb-vbadge.mistake    { background: var(--bb-mistake);   color: #3a1500; }
.bb-vbadge.blunder    { background: var(--bb-bad);       color: #3d0a0a; }
.bb-vbadge.try        { background: var(--bb-quiet);     color: #eef1ef; }
.bb-vbadge.checking   { background: #0b0d0e; color: #cfd5d1; box-shadow: inset 0 0 0 1.5px var(--bb-quiet), 0 0 0 1.5px rgba(0,0,0,0.55); }

/* ── Verdict ─────────────────────────────────────────────────────────── */
.bb-verdict {
  display: flex; align-items: center; gap: 12px;
  min-height: 58px;
}
.bb-verdict .bb-vbadge {
  position: static; flex: none;
  width: 26px; height: 26px; max-width: none; max-height: none; font-size: 13px;
  box-shadow: none;
}
.bb-verdict .bb-vbadge.checking { box-shadow: inset 0 0 0 1.5px var(--bb-quiet); }
.bb-verdict .bb-vbadge[hidden] { display: none; }
.bb-verdict-text { min-width: 0; }
.bb-verdict-text.bb-swap { animation: bb-verdict-in .22s ease-out; }
@keyframes bb-verdict-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.bb-verdict-title {
  font-family: var(--font-display, Georgia, serif);
  font-size: 17px; font-weight: 600; line-height: 1.25;
}
.bb-verdict-san { color: var(--muted, rgba(255,255,255,0.65)); margin-right: 7px; }
.bb-verdict-san:empty { display: none; }
.bb-verdict-sub, .bb-verdict-msg {
  font-size: 12.5px; line-height: 1.45; color: var(--muted, rgba(255,255,255,0.65)); margin-top: 2px;
}
.bb-verdict-sub:empty, .bb-verdict-msg:empty { display: none; }
.bb-verdict.yellow .bb-verdict-title { color: var(--bb-warn); }
.bb-verdict.red .bb-verdict-title    { color: var(--bb-bad); }

/* ── Controls ────────────────────────────────────────────────────────── */
.bb-controls {
  display: flex; justify-content: space-around; gap: 4px;
  padding-top: 8px; border-top: 1px solid var(--bb-line);
}
.bb-ctl {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 56px; min-height: 48px; padding: 4px 6px;
  background: none; border: none; border-radius: 10px; cursor: pointer;
  font: inherit; font-size: 11.5px; font-weight: 500; color: var(--muted, rgba(255,255,255,0.65));
  -webkit-tap-highlight-color: transparent;
}
.bb-ctl svg { width: 21px; height: 21px; color: rgba(255,255,255,0.85); }
.bb-ctl:hover { background: rgba(255,255,255,0.06); }
.bb-ctl:disabled { opacity: 0.35; cursor: not-allowed; background: none; }
.bb-ctl[aria-expanded="true"] { background: rgba(255,255,255,0.08); }
.bb-ctl .et-spinner { position: absolute; top: 4px; right: 6px; }

/* ── Slip card: takes the controls' place after a mistake ────────────── */
.bb-slip {
  display: none;
  padding: 12px 0 2px;
  border-top: 2px solid var(--bb-warn);
}
.bb-slip.show { display: block; animation: bb-verdict-in .22s ease-out; }
.bb-session.is-slip .bb-controls { display: none; }
.bb-slip-why { font-size: 13px; line-height: 1.55; color: rgba(255,255,255,0.86); }
.bb-slip-why:empty { display: none; }
.bb-slip-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.bb-slip-btn {
  min-height: 44px; padding: 8px 10px; border-radius: 10px; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 600;
  border: 1px solid rgba(255,255,255,0.16); background: rgba(255,255,255,0.05); color: rgba(255,255,255,0.9);
  -webkit-tap-highlight-color: transparent;
}
.bb-slip-btn:hover { background: rgba(255,255,255,0.10); }
.bb-slip-btn.primary {
  grid-column: 1 / -1;
  background: var(--bb-good); border-color: var(--bb-good); color: #06210f; font-weight: 700;
}
.bb-slip-btn.primary:hover { background: #2bd168; }
.bb-slip-btn.link {
  grid-column: 1 / -1; min-height: 36px;
  background: none; border: none; font-weight: 500; font-size: 12.5px;
  color: var(--muted, rgba(255,255,255,0.65)); text-decoration: underline; text-underline-offset: 2px;
}

/* ── Extras ──────────────────────────────────────────────────────────── */
.bb-extras { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.bb-more {
  display: flex; flex-direction: column; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--bb-line); border-radius: 12px;
  background: rgba(255,255,255,0.03);
}
.bb-more[hidden] { display: none; }
.bb-more-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
/* The shared mute button carries an emoji as its text (bb-sounds.js). Here it reads as
   words, taken from the label that script already keeps up to date. */
.bb-more .bb-mute-btn { font-size: 0; }
.bb-more .bb-mute-btn::after { content: attr(aria-label); font-size: 12px; }
.bb-more .bb-arrows-controls { justify-content: flex-start; margin: 0; }
.bb-history-title { font-size: 12px; color: var(--muted, rgba(255,255,255,0.65)); margin-bottom: 6px; }

/* Result card rises over the board. */
.bb-board-frame .et-terminal.show { animation: bb-rise .28s ease-out; }
@keyframes bb-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ── Desktop: board left, everything else beside it ──────────────────── */
@media (min-width: 900px) {
  .bb-session {
    --bb-board: max(320px, min(46vw, calc(100vh - 250px), 600px));
    --bb-board: max(320px, min(46vw, calc(100dvh - 250px), 600px));
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 32px; row-gap: 6px;
    align-items: start;
  }
  .bb-session-bar { grid-column: 1 / -1; }
  .bb-col-board, .bb-col-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
  .bb-col-side { gap: 14px; padding-top: 4px; }
  .bb-goal-title { font-size: 26px; }
  .bb-goal-sub { display: block; }
  .bb-pips { margin-top: 12px; max-width: 420px; }
  .bb-verdict {
    min-height: 74px; padding: 12px 0;
    border-top: 1px solid var(--bb-line); border-bottom: 1px solid var(--bb-line);
  }
  .bb-verdict-title { font-size: 19px; }
  .bb-controls { justify-content: flex-start; gap: 10px; border-top: none; padding-top: 2px; }
  /* The card sits beside the board here, so hiding the controls would only make the
     column under the board jump. Keep their space. */
  .bb-session.is-slip .bb-controls { display: flex; visibility: hidden; }
  .bb-slip { border-top: none; padding-top: 0; max-width: 420px; }
}

@media (prefers-reduced-motion: reduce) {
  .bb-session *, .bb-session *::before, .bb-session *::after { animation: none !important; transition: none !important; }
}
