/* Chain Reaction. Every class is prefixed .cr- so nothing collides with the kit. */
.cr-stage { --t0: #ff5a5a; --t1: #ff9a3c; --t2: #ffd23f; --t3: #8fa0c8; --t4: #5ee0e6; }
.cr-stage [hidden] { display: none !important; }
.cr-screen { display: grid; grid-template-columns: 262px minmax(0, 1fr) 300px; grid-template-areas: "left mid right" "pf pf pf"; gap: 12px 14px; align-items: start; }
.cr-left { grid-area: left; display: flex; flex-direction: column; gap: 10px; }
.cr-mid { grid-area: mid; display: flex; flex-direction: column; gap: 12px; min-width: 0; position: relative; }
.cr-right { grid-area: right; display: flex; flex-direction: column; gap: 10px; align-self: stretch; height: 0; min-height: 100%; }
.cr-pf { grid-area: pf; }
.cr-ph { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.cr-ph small { font-size: 11px; }
.cr-link { appearance: none; background: none; border: 0; padding: 0; color: var(--s-dim); font: 600 12px Inter, sans-serif; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--s-faint); }
.cr-link:hover:not(:disabled) { color: var(--s-text); }
.cr-link:disabled { opacity: .4; cursor: default; }

/* ---------- left ---------- */
.cr-credits { display: flex; flex-direction: column; gap: 2px; }
.cr-credits b { font: 800 30px/1.1 Inter, sans-serif; letter-spacing: -.03em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.cr-credits small { font-size: 12px; }
.cr-seg { display: flex; width: 100%; margin-top: 8px; }
.cr-seg button { flex: 1; font-family: 'IBM Plex Mono', monospace; }
.cr-cells .cr-ph b { font-size: 13px; color: var(--you); }
.cr-chips { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.cr-chip { display: flex; align-items: center; justify-content: center; height: 30px; border-radius: 7px; border: 1.5px solid var(--you); color: var(--you); font: 600 12.5px 'IBM Plex Mono', monospace; }
.cr-chip.empty { border: 1px dashed var(--s-line); color: var(--s-faint); }
.cr-chip.hit { background: var(--you); color: var(--you-ink); }
.cr-chip.miss { opacity: .45; }
.cr-chip.bonus { border-color: var(--t4); color: var(--t4); }
.cr-links-row { display: flex; gap: 16px; margin: 10px 0 2px; }
.cr-sum { display: flex; justify-content: space-between; align-items: baseline; border-top: 1px solid var(--s-line); padding-top: 9px; margin-top: 9px; font-size: 12.5px; color: var(--s-dim); }
.cr-sum b { color: var(--s-text); font: 700 15px 'IBM Plex Mono', monospace; }
.cr-go { width: 100%; padding: 15px 18px; font-size: 15px; }
.cr-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.cr-stats div { display: flex; flex-direction: column; gap: 1px; }
.cr-stats small { font-size: 11px; color: var(--s-dim); }
.cr-stats b { font-size: 19px; font-weight: 700; }

/* ---------- middle ---------- */
.cr-head { display: grid; grid-template-columns: 1fr minmax(0, 1.3fr) 1fr; align-items: center; gap: 22px; background: var(--s-panel); border: 1px solid var(--s-line); border-radius: 14px; padding: 11px 18px; }
.cr-h-cell { display: flex; flex-direction: column; min-width: 0; }
.cr-h-cell b { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.cr-h-r { align-items: flex-end; text-align: right; }
.cr-power-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.cr-power-top b { font-size: 17px; font-weight: 700; color: var(--you); }
.cr-meter { position: relative; height: 8px; border-radius: 4px; background: var(--s-panel2); border: 1px solid var(--s-line); }
.cr-meter i { position: absolute; left: 0; top: 0; bottom: 0; width: 37.5%; border-radius: 4px; background: var(--you); transition: width .25s; }
.cr-meter span { position: absolute; top: -2px; bottom: -2px; width: 1px; background: rgba(255, 255, 255, .28); }
.cr-meter-l { position: relative; height: 13px; margin-top: 3px; }
.cr-meter-l span { position: absolute; transform: translateX(-50%); font: 600 9.5px 'IBM Plex Mono', monospace; color: var(--s-faint); }

.cr-board { position: relative; align-self: center; width: min(100%, 492px); padding: 10px; background: var(--s-panel); border: 1px solid var(--s-line); border-radius: 14px; }
.cr-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.cr-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.cr-lines line { stroke: var(--you); stroke-width: 2; stroke-linecap: round; opacity: .75; stroke-dasharray: 80; stroke-dashoffset: 80; animation: crline var(--cr-line, .3s) ease-out forwards; }
.cr-lines line.fail { stroke: var(--s-dim); stroke-dasharray: 3 4; opacity: .5; animation: none; }
@keyframes crline { to { stroke-dashoffset: 0; } }

.cr-cell { position: relative; appearance: none; aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--s-line); background: var(--s-panel2); color: var(--s-faint); cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center; transition: border-color .2s, background .25s, opacity .3s, transform .15s; }
.cr-cell:hover { border-color: #3d4352; }
.cr-cell .co { position: absolute; left: 7px; top: 5px; font: 600 10px 'IBM Plex Mono', monospace; color: var(--s-faint); }
.cr-cell .tag { position: absolute; left: 0; right: 0; bottom: 5px; font: 800 8.5px Inter, sans-serif; letter-spacing: .14em; text-transform: uppercase; color: var(--you); text-align: center; }
.cr-cell .ord { position: absolute; right: 6px; top: 5px; font: 700 10px 'IBM Plex Mono', monospace; color: var(--s-text); opacity: .8; }
.cr-cell .cr-shape { width: 40%; height: 40%; opacity: 0; transform: scale(.6); transition: opacity .3s, transform .3s; }
.cr-cell.mine { border: 2px solid var(--you); background: rgba(255, 178, 30, .07); }
.cr-cell.mine .co { color: var(--you); }
.cr-cell.shown .cr-shape { opacity: .55; transform: none; }
.cr-cell.boom { background: color-mix(in srgb, var(--c) 22%, var(--s-panel2)); border-color: color-mix(in srgb, var(--c) 55%, transparent); }
.cr-cell.boom .cr-shape { opacity: 1; transform: none; }
.cr-cell.boom.mine { border: 2px solid var(--you); box-shadow: inset 0 0 0 2px var(--you); }
.cr-cell.boom.mine .tag { color: var(--you); }
.cr-cell.now { animation: crboom var(--cr-pop, .45s) cubic-bezier(.2, .9, .3, 1.3); z-index: 2; }
.cr-cell.now::after { content: ''; position: absolute; inset: -4px; border-radius: 13px; border: 2px solid var(--c); animation: crring var(--cr-pop, .6s) ease-out forwards; pointer-events: none; }
.cr-cell.gz::before { content: 'START'; position: absolute; left: 50%; top: -8px; transform: translateX(-50%); background: var(--hot); color: #fff; font: 800 8px Inter, sans-serif; letter-spacing: .14em; padding: 2px 5px; border-radius: 4px; z-index: 3; }
.cr-cell.held { opacity: .42; }
.cr-cell.held.mine { opacity: .7; }
.cr-cell.bonus { border: 2px solid var(--t4); background: rgba(94, 224, 230, .1); opacity: 1; }
.cr-cell.bonus .cr-shape { opacity: 1; }
.cr-cell.bonus .tag { color: var(--t4); }
.cr-stage.cr-locked .cr-cell { cursor: default; }
@keyframes crboom { 0% { transform: scale(1.14); } 100% { transform: scale(1); } }
@keyframes crring { from { opacity: 1; transform: scale(.9); } to { opacity: 0; transform: scale(1.35); } }

.cr-shape { display: inline-block; width: 16px; height: 16px; flex: none; }
.cr-shape svg { width: 100%; height: 100%; display: block; }
.cr-legend { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.cr-leg { display: flex; align-items: center; gap: 9px; background: var(--s-panel); border: 1px solid var(--s-line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.cr-leg .cr-shape { width: 18px; height: 18px; }
.cr-leg b { display: block; font-size: 12.5px; font-weight: 700; }
.cr-leg small { display: block; font-size: 10.5px; color: var(--s-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cr-leg div { min-width: 0; }

/* ---------- right ---------- */
.cr-pt { display: grid; grid-template-columns: 1.2fr .8fr 1fr; gap: 8px; align-items: center; padding: 4px 9px; border-radius: 7px; font-size: 13px; }
.cr-pt span:nth-child(2), .cr-pt span:nth-child(3) { text-align: right; font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; }
.cr-pt-head { font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--s-faint); }
.cr-pt-row { color: var(--s-dim); border: 1px solid transparent; transition: background .2s, border-color .2s; }
.cr-pt-row b { color: var(--s-text); font-weight: 600; }
.cr-pt-row span:nth-child(3) { color: var(--s-text); font-weight: 600; }
.cr-pt-row.top span:nth-child(3) { color: var(--you); }
.cr-pt-row.zero span:nth-child(2), .cr-pt-row.zero span:nth-child(3) { color: var(--s-faint); font-weight: 500; }
.cr-pt-row.live { background: rgba(255, 178, 30, .1); border-color: rgba(255, 178, 30, .45); }
.cr-pt-row.won { background: var(--you); color: var(--you-ink); }
.cr-pt-row.won b, .cr-pt-row.won span { color: var(--you-ink) !important; }
.cr-pt-none { font-size: 12.5px; color: var(--s-dim); padding: 6px 9px; }
.cr-bonus { display: flex; align-items: center; gap: 9px; margin-top: 8px; padding-top: 9px; border-top: 1px solid var(--s-line); font-size: 11.5px; color: var(--s-dim); line-height: 1.4; }
.cr-bonus b { color: var(--t4); }

.cr-result { display: flex; flex-direction: column; gap: 3px; }
.cr-result b { font-size: 21px; font-weight: 800; letter-spacing: -.02em; margin-top: 3px; }
.cr-result b.up { color: var(--up); }
.cr-result small { font-size: 12px; line-height: 1.45; }
.cr-result.flash { animation: crwin .9s ease-out; }
@keyframes crwin { 0% { border-color: var(--up); } 100% { border-color: var(--s-line); } }

.cr-log { flex: 1; min-height: 140px; overflow: hidden; display: flex; flex-direction: column; }
#crLog { flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--s-line) transparent; }
.cr-le { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; padding: 5px 0; border-top: 1px solid var(--s-line); font-size: 12.5px; color: var(--s-dim); animation: dkfeed .35s cubic-bezier(.2, .9, .3, 1); }
.cr-le:first-child { border-top: 0; }
.cr-le .n { font: 600 10.5px 'IBM Plex Mono', monospace; color: var(--s-faint); }
.cr-le b { color: var(--s-text); font-weight: 600; }
.cr-le em { font-style: normal; font: 600 11px 'IBM Plex Mono', monospace; color: var(--s-faint); }
.cr-le.mine b, .cr-le.mine em { color: var(--you); }
.cr-le.bonus b { color: var(--t4); }
.cr-le.held { opacity: .7; }
.cr-log-empty { font-size: 12.5px; color: var(--s-dim); }

/* ---------- provably fair ---------- */
.cr-pf { display: grid; grid-template-columns: 168px minmax(0, 1.2fr) minmax(0, .7fr) minmax(0, 1.2fr) 176px; gap: 14px; align-items: center; background: var(--s-panel); border: 1px solid var(--s-line); border-radius: 14px; padding: 11px 16px; }
.cr-pf-t { display: flex; flex-direction: column; gap: 1px; }
.cr-pf-t b { font-size: 15px; font-weight: 700; }
.cr-pf-t small { font-size: 11.5px; color: var(--s-dim); }
.cr-pf-f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cr-pf-f small { font-size: 11px; color: var(--s-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cr-pf-f code { font: 500 11px/1.4 'IBM Plex Mono', monospace; color: var(--s-text); word-break: break-all; }
.cr-pf-f code.fresh { animation: crfresh 1.2s ease-out; }
@keyframes crfresh { from { color: var(--you); } }
.cr-pf-cs input { width: 100%; background: var(--s-bg); border: 1px solid var(--s-line); border-radius: 8px; color: var(--s-text); font: 500 12px 'IBM Plex Mono', monospace; padding: 8px 10px; outline: none; }
.cr-pf-cs input:focus { border-color: var(--you); }
.cr-pf-v { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; text-align: right; }
.cr-pf-v span { font-size: 11.5px; line-height: 1.35; }
.cr-pf-v span.ok { color: var(--up); }
.cr-pf-v span.bad { color: var(--down); }

/* ---------- TV wall ---------- */
.cr-stage:fullscreen { display: flex; flex-direction: column; }
.cr-stage:fullscreen .cr-screen { flex: 1; align-content: center; padding: 2vh 1.6vw; }
.cr-stage:fullscreen .cr-board { width: min(100%, 52vh); }
.cr-stage:fullscreen .cr-cell .co { font-size: 1.3vh; }

/* ---------- smaller screens ---------- */
@media (max-width: 1240px) {
  .cr-screen { grid-template-columns: 250px minmax(0, 1fr); grid-template-areas: "mid mid" "left right" "pf pf"; }
  .cr-right { height: auto; min-height: 0; align-self: start; }
  .cr-log { flex: none; max-height: 260px; }
  .cr-pf { grid-template-columns: 1fr 1fr; }
  .cr-pf-t { grid-column: 1 / -1; }
  .cr-pf-v { align-items: center; text-align: left; flex-direction: row; align-self: end; }
}
@media (max-width: 760px) {
  .cr-screen { grid-template-columns: minmax(0, 1fr); grid-template-areas: "mid" "left" "right" "pf"; padding: 12px; gap: 12px; }
  .cr-head { grid-template-columns: 1fr 1fr; gap: 12px; padding: 10px 12px; }
  .cr-head .cr-power { grid-column: 1 / -1; grid-row: 2; }
  .cr-h-cell b { font-size: 18px; }
  .cr-board { padding: 7px; }
  .cr-grid { gap: 5px; }
  .cr-cell { border-radius: 7px; }
  .cr-cell .co { left: 4px; top: 3px; font-size: 8.5px; }
  .cr-cell .tag { font-size: 7px; bottom: 3px; letter-spacing: .08em; }
  .cr-cell .ord { font-size: 8.5px; right: 4px; top: 3px; }
  .cr-legend { grid-template-columns: 1fr 1fr; }
  .cr-pf { grid-template-columns: minmax(0, 1fr); }
  .dk-bar-r .s-seg { display: none; }
}
