/* =========================================================================
   Blind Spots, the openings section: the first 12 moves of every game read.
   Three figures, the openings ranked by what they cost (record bar, where
   you came out, mistakes), a disclosure row per opening with the worst slip
   on a small board and the course and trainer that cover it, and a
   segmented "As White / As Black" read of first moves. Rows rise in turn
   and their bars grow as the section lands. js/blind-spots.js drives it.
   ========================================================================= */

.bs-op {
  --op-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --op-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --op-win: var(--ok);
  --op-loss: #e0365c;
  margin-top: 0.5rem;
}

/* --------------------------------------------------------------- figures */

.bs-op-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0.9rem 0 0.4rem;
}
.bs-op-stats > div {
  display: grid;
  gap: 0.3rem;
  padding: 0.85rem 0.9rem;
  border-radius: 14px;
  background: color-mix(in srgb, var(--ink) 4%, transparent);
}
.bs-op-stats b {
  font: 650 1.6rem/1 var(--display);
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
}
.bs-op-stats b small { font: 600 0.72rem/1 var(--sans); letter-spacing: 0; color: var(--ink-faint); }
.bs-op-stats > div > span { font-size: 0.72rem; color: var(--ink-faint); font-weight: 600; line-height: 1.3; }

/* ------------------------------------------------------------------ list */

.bs-op-list { list-style: none; margin: 0.4rem 0 0; padding: 0; }
.bs-op-item { border-bottom: 1px solid var(--line); }
.bs-op-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto 14px;
  gap: 0.8rem;
  align-items: center;
  width: 100%;
  padding: 0.8rem 0.2rem;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.2s var(--op-ease);
}
.bs-op-row:hover { background: color-mix(in srgb, var(--ink) 3.5%, transparent); }
.bs-op-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.bs-op-side {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border-radius: 9px;
  font-size: 1.05rem;
  line-height: 1;
}
.bs-op-side--w { background: #f4f1ea; color: #1b1b20; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08); }
.bs-op-side--b { background: #1b1b20; color: #f4f1ea; }
.bs-op-name { min-width: 0; display: grid; gap: 0.2rem; }
.bs-op-name b { font-size: 0.95rem; font-weight: 600; letter-spacing: -0.012em; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.bs-op-name small { font-size: 0.72rem; color: var(--ink-faint); }

/* The record as one bar: wins, draws, losses. */
.bs-op-wdl {
  display: flex;
  height: 5px;
  margin-top: 0.25rem;
  border-radius: 99px;
  overflow: hidden;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  gap: 2px;
}
.bs-op-wdl i { width: var(--w); transform-origin: left; }
.bs-op-wdl i:empty { display: block; }
.bs-op-wdl .w { background: var(--op-win); }
.bs-op-wdl .d { background: color-mix(in srgb, var(--ink) 25%, transparent); }
.bs-op-wdl .l { background: var(--op-loss); }

/* Where you came out of the opening. */
.bs-op-out { display: grid; justify-items: end; gap: 0.15rem; }
.bs-op-out b {
  padding: 0.28rem 0.45rem;
  border-radius: 7px;
  font: 650 0.84rem/1 var(--display);
  font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}
.bs-op-out small { font-size: 0.62rem; color: var(--ink-faint); font-weight: 600; white-space: nowrap; }
.bs-op-out.is-bad b { color: var(--op-loss); background: color-mix(in srgb, var(--op-loss) 12%, transparent); }
.bs-op-out.is-good b { color: var(--op-win); background: color-mix(in srgb, var(--op-win) 13%, transparent); }

.bs-op-chev {
  width: 14px; height: 14px;
  fill: none;
  stroke: color-mix(in srgb, var(--ink) 35%, transparent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.45s var(--op-spring), stroke 0.3s;
}
.bs-op-item.is-open .bs-op-chev { transform: rotate(90deg); stroke: var(--accent); }

/* The detail opens as a true height transition (0fr to 1fr). */
.bs-op-detail { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.5s var(--op-ease); }
.bs-op-detail > div { overflow: hidden; }
.bs-op-item.is-open .bs-op-detail { grid-template-rows: 1fr; }
.bs-op-detail > div > * { opacity: 0; transform: translateY(-4px); filter: blur(3px); transition: opacity 0.3s, transform 0.4s var(--op-ease), filter 0.3s; }
.bs-op-item.is-open .bs-op-detail > div > * { opacity: 1; transform: none; filter: none; transition-delay: 0.1s; }

.bs-op-slip {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 0.95rem;
  align-items: start;
  padding: 0.2rem 0.2rem 0.8rem 2.6rem;
}
.bs-op-board { width: 96px; }
.bs-op-slip-k { margin: 0; font-size: 0.7rem; font-weight: 600; color: var(--ink-faint); }
.bs-op-slip-t { margin: 0.25rem 0 0; font-size: 0.84rem; line-height: 1.5; color: var(--ink-soft); }
.bs-op-slip-t .is-bad { color: var(--op-loss); }
.bs-op-slip-t .is-good { color: var(--op-win); }
.bs-op-acts { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; }
.bs-op-show, .bs-op-game {
  padding: 0.42rem 0.7rem;
  border-radius: 8px;
  font: 600 0.76rem/1 var(--sans);
  text-decoration: none;
  cursor: pointer;
}
.bs-op-show { border: 0; background: var(--ink); color: var(--paper); }
.bs-op-game { color: var(--ink-soft); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.bs-op-clean { margin: 0; padding: 0.1rem 0.2rem 0.8rem 2.6rem; font-size: 0.82rem; color: var(--ink-soft); }
.bs-op-links { display: flex; flex-wrap: wrap; gap: 0.45rem; padding: 0 0.2rem 0.9rem 2.6rem; }
.bs-op-link {
  padding: 0.4rem 0.65rem;
  border-radius: 8px;
  font: 600 0.74rem/1 var(--sans);
  text-decoration: none;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  transition: background 0.2s;
}
.bs-op-link:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.bs-op-link--ghost { color: var(--ink-soft); background: color-mix(in srgb, var(--ink) 5%, transparent); }

/* Each arrow draws itself on the small board when the row opens. */
.bs-op-arrow { stroke-dasharray: 8; stroke-dashoffset: 8; }
.bs-op-item.is-open .bs-op-arrow { animation: opDraw 0.6s 0.3s var(--op-ease) forwards; }
.bs-op-item.is-open .bs-op-arrow:last-of-type { animation-delay: 0.6s; }
@keyframes opDraw { to { stroke-dashoffset: 0; } }

/* ----------------------------------------------------------- first moves */

.bs-op-first-head { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; margin: 1.3rem 0 0.6rem; }
.bs-op-seg {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 2px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--ink) 7%, transparent);
  isolation: isolate;
}
.bs-op-seg-thumb {
  position: absolute;
  top: 2px; bottom: 2px; left: 2px;
  width: calc((100% - 4px) / 2);
  border-radius: 7px;
  background: var(--paper-raised);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);
  transform: translateX(calc(var(--i, 0) * 100%));
  transition: transform 0.45s var(--op-spring);
  z-index: 0;
}
[data-theme="dark"] .bs-op-seg-thumb { background: #5b5b63; }
.bs-op-seg button {
  position: relative;
  z-index: 1;
  padding: 0.38rem 0.8rem;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font: 500 0.78rem/1 var(--sans);
  cursor: pointer;
}
.bs-op-seg button[aria-checked="true"] { color: var(--ink); font-weight: 600; }
.bs-op-first-note { font-size: 0.72rem; color: var(--ink-faint); }
.bs-op-first { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.bs-op-first li { display: grid; grid-template-columns: 3.4rem 1fr 6.2rem; gap: 0.7rem; align-items: center; font-size: 0.82rem; }
.bs-op-fm { font-weight: 600; font-variant-numeric: tabular-nums; }
.bs-op-fbar { height: 8px; border-radius: 99px; background: color-mix(in srgb, var(--ink) 6%, transparent); overflow: hidden; }
.bs-op-fbar i { display: block; height: 100%; width: var(--w); border-radius: inherit; background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 70%, var(--ink)), var(--accent)); transform-origin: left; }
.bs-op-fs { text-align: right; color: var(--ink-faint); font-size: 0.74rem; }
.bs-op-fs b { color: var(--ink); font-size: 0.84rem; }
.bs-op-none { color: var(--ink-faint); font-size: 0.8rem; grid-template-columns: 1fr !important; }

/* ---------------------------------------------------------- choreography */

@media (prefers-reduced-motion: no-preference) {
  .bs-op .bs-op-stats > div,
  .bs-op .bs-op-item { opacity: 0; }
  .bs-op.is-in .bs-op-stats > div { animation: opRise 0.7s calc(var(--n, 0) * 0.07s) var(--op-ease) both; }
  .bs-op.is-in .bs-op-stats > div:nth-child(2) { --n: 1; }
  .bs-op.is-in .bs-op-stats > div:nth-child(3) { --n: 2; }
  .bs-op.is-in .bs-op-item { animation: opRise 0.75s calc(0.25s + var(--n, 0) * 0.08s) var(--op-ease) both; }
  .bs-op.is-in .bs-op-wdl i { animation: opGrow 0.9s calc(0.55s + var(--n, 0) * 0.08s) var(--op-ease) both; }
  .bs-op.is-in .bs-op-item .bs-op-wdl i { animation-delay: calc(0.55s + var(--n, 0) * 0.08s); }
  .bs-op.is-in .bs-op-out b { animation: opPop 0.55s calc(0.7s + var(--n, 0) * 0.08s) var(--op-spring) both; }
  .bs-op.is-in .bs-op-first li { animation: opRise 0.6s calc(var(--n, 0) * 0.06s) var(--op-ease) both; }
  .bs-op.is-in .bs-op-fbar i { animation: opGrow 0.9s calc(0.15s + var(--n, 0) * 0.06s) var(--op-ease) both; }
}
@keyframes opRise { from { opacity: 0; transform: translateY(10px); filter: blur(5px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes opGrow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes opPop { from { opacity: 0; transform: scale(0.7); } to { opacity: 1; transform: scale(1); } }

@media (max-width: 520px) {
  .bs-op-row { grid-template-columns: 28px minmax(0, 1fr) auto 12px; gap: 0.6rem; }
  .bs-op-slip { grid-template-columns: 80px minmax(0, 1fr); padding-left: 0.2rem; }
  .bs-op-board { width: 80px; }
  .bs-op-links, .bs-op-clean { padding-left: 0.2rem; }
}
