/* Bit Flip. Colors follow the CV and footer (#2A7BBE accent, #1C3352 navy); type is IBM Plex like the CV.
   Dark mode follows the theme's body.dark class. */
.bitflip-page { max-width: 760px; }
.bitflip-page .bf-lead { font-size: 1.05rem; opacity: .85; margin-bottom: 1.75rem; }
.bitflip-page .bf-about { margin-top: 2.25rem; font-size: .98rem; }

/* Color tokens live on the page wrapper so the game card and the leaderboard share them. */
.bitflip-page {
  --bf-card: #fff;
  --bf-ink: #263038;
  --bf-muted: #66737f;
  --bf-line: rgba(28, 51, 82, .12);
  --bf-accent: #2a7bbe;
  --bf-accent-hover: #236aa5;
  --bf-on-accent: #fff;
  --bf-navy: #1c3352;
  --bf-tint: #e9f1f9;
  --bf-track: #c9d6e3;
  --bf-good: #1f9d55;
  --bf-warn: #c46a15;
  --bf-shadow: 0 12px 32px rgba(28, 51, 82, .10);
  --bf-line-strong: #c9d6e3;
  --bf-accent-soft: #b9d5ec;
  --bf-ring: rgba(42, 123, 190, .25);
}
.bitflip {
  position: relative;
  padding: 20px;
  border: 1px solid var(--bf-line);
  border-radius: 24px;
  background: var(--bf-card);
  box-shadow: var(--bf-shadow);
  color: var(--bf-ink);
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.dark .bitflip-page {
  --bf-card: #21222c;
  --bf-ink: #f8f8f2;
  --bf-muted: rgba(248, 248, 242, .62);
  --bf-line: rgba(255, 255, 255, .10);
  --bf-accent: #6fb1ec;
  --bf-accent-hover: #8cc2f1;
  --bf-on-accent: #0f2238;
  --bf-navy: #e9f1f9;
  --bf-tint: #2c2e3b;
  --bf-track: #454959;
  --bf-good: #4cc38a;
  --bf-warn: #f0a35e;
  --bf-shadow: none;
  --bf-line-strong: #4a4e60;
  --bf-accent-soft: #34506e;
  --bf-ring: rgba(111, 177, 236, .3);
}
.bitflip .bf-mono {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

/* Score / streak / time */
.bf-hud { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 12px; }
.bf-stat { display: flex; flex-direction: column; gap: 2px; }
.bf-stat:nth-child(2) { align-items: center; }
.bf-stat:nth-child(3) { align-items: flex-end; }
.bf-label { font-size: .7rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--bf-muted); }
.bf-value { font-size: 1.6rem; font-weight: 600; line-height: 1.1; color: var(--bf-navy); }
.bf-streak-row { display: flex; align-items: center; gap: 8px; }
.bf-pips { display: inline-flex; gap: 4px; }
.bf-pip { width: 7px; height: 7px; border-radius: 50%; background: var(--bf-track); transition: background-color .15s; }
.bf-pip.is-on { background: var(--bf-accent); }
.bitflip.is-low [data-time] { color: var(--bf-warn); }

.bf-timebar { height: 6px; margin: 14px 0 0; border-radius: 999px; background: var(--bf-tint); overflow: hidden; }
.bf-timebar span { display: block; height: 100%; background: var(--bf-accent); border-radius: inherit;
                   transform-origin: left center; }
.bitflip.is-low .bf-timebar span { background: var(--bf-warn); }

/* The number to make */
/* The play view and the screens share one grid cell, so the stage grows to fit whichever is taller. */
.bf-stage { position: relative; display: grid; min-height: 270px; text-align: center; }
.bf-stage > .bf-play, .bf-stage > .bf-overlay { grid-area: 1 / 1; }
.bf-play { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 18px 0 22px; }
.bf-target { font-size: clamp(4.25rem, 19vw, 7rem); font-weight: 600; line-height: 1; color: var(--bf-navy);
             min-height: 1em; transition: color .12s; }
.bf-target.is-new { animation: bf-in .22s ease-out; }
.bf-target.is-solved { color: var(--bf-good); }
.bf-sumline { margin-top: 14px; font-size: 1.05rem; color: var(--bf-muted); letter-spacing: .02em; }
.bf-sumline [data-binary] { letter-spacing: .12em; }
.bf-sumline.is-high { color: var(--bf-warn); }
.bf-float { position: absolute; top: 16%; left: 50%; transform: translateX(-50%); font-size: 1.3rem; font-weight: 700;
            color: var(--bf-good); opacity: 0; pointer-events: none; }
.bf-float.is-show { animation: bf-float .8s ease-out forwards; }

/* Start, countdown and results cover the stage */
.bf-overlay { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center;
              justify-content: center; gap: 10px; padding: 20px 4px; background: var(--bf-card); }
.bf-overlay[hidden] { display: none; }
.bf-overlay h2 { margin: 0; font-family: inherit; font-size: 1.35rem; font-weight: 600; color: var(--bf-navy); }
.bf-overlay p { margin: 0; max-width: 34em; font-size: .97rem; line-height: 1.5; color: var(--bf-muted); }
.bf-overlay .bf-eyebrow { font-size: .72rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
                          color: var(--bf-accent); }
.bf-count { font-size: 5rem; font-weight: 600; color: var(--bf-accent); }
.bf-count.is-tick { animation: bf-in .3s ease-out; }
.bf-final { font-size: 4rem; font-weight: 600; line-height: 1; color: var(--bf-navy); }
.bf-best.is-new { color: var(--bf-good); font-weight: 600; }

.bf-btn { margin-top: 8px; padding: 12px 34px; border: 0; border-radius: 999px; background: var(--bf-accent);
          color: var(--bf-on-accent); font: 600 1.05rem/1.2 "IBM Plex Sans", system-ui, sans-serif; cursor: pointer;
          transition: background-color .15s, transform .1s; touch-action: manipulation; }
.bf-btn:hover { background: var(--bf-accent-hover); }
.bf-btn:active { transform: scale(.97); }
.bf-btn:focus-visible, .bf-switch:focus-visible { outline: 3px solid var(--bf-accent); outline-offset: 3px; }
.bf-hint { font-size: .8rem !important; }
.bf-btn-small { margin-top: 0; padding: 10px 22px; font-size: .98rem; }
.bf-btn-ghost { background: transparent; color: var(--bf-accent); box-shadow: inset 0 0 0 1.5px var(--bf-line-strong); }
.bf-btn-ghost:hover { background: var(--bf-tint); }
.bf-btn:disabled { opacity: .6; cursor: default; }

/* Name entry after a round */
.bf-save { width: 100%; max-width: 380px; margin: 6px 0 0; }
.bf-save-label { display: block; margin-bottom: 8px; font-size: .9rem; font-weight: 600; color: var(--bf-navy); }
.bf-save-row { display: flex; gap: 8px; }
.bf-save input { flex: 1 1 auto; min-width: 0; padding: 10px 16px; border: 1.5px solid var(--bf-line-strong);
                 border-radius: 999px; background: var(--bf-card); color: var(--bf-ink);
                 font: 500 1rem/1.2 "IBM Plex Sans", system-ui, sans-serif; }
.bf-save input::placeholder { color: var(--bf-muted); }
.bf-save input:focus { outline: none; border-color: var(--bf-accent); box-shadow: 0 0 0 4px var(--bf-ring); }
.bf-overlay .bf-save-msg { min-height: 1.35em; margin-top: 6px; font-size: .85rem; color: var(--bf-warn); }
.bf-overlay .bf-save-note { font-size: .92rem; }
.bf-overlay .bf-save-note.is-good { color: var(--bf-good); font-weight: 600; }

/* Leaderboard */
.bf-board { margin-top: 24px; padding: 18px 20px 16px; border: 1px solid var(--bf-line); border-radius: 24px;
            background: var(--bf-card); box-shadow: var(--bf-shadow); color: var(--bf-ink);
            font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif; }
.bf-board[hidden] { display: none; }
.bf-board-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px;
                 margin-bottom: 8px; }
.bf-board h2 { margin: 0; font-family: inherit; font-size: 1.2rem; font-weight: 600; color: var(--bf-navy); }
.bf-tabs { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--bf-tint); }
.bf-tab { padding: 6px 14px; border: 0; border-radius: 999px; background: transparent; color: var(--bf-muted);
          font: 600 .85rem/1.2 "IBM Plex Sans", system-ui, sans-serif; cursor: pointer; touch-action: manipulation; }
.bf-tab[aria-selected="true"] { background: var(--bf-card); color: var(--bf-navy); box-shadow: 0 1px 3px rgba(0, 0, 0, .14); }
.bf-tab:focus-visible { outline: 2px solid var(--bf-accent); outline-offset: 1px; }
.bf-board-list { margin: 0; padding: 0; list-style: none; }
.bf-row { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 12px; padding: 9px 8px;
          border-top: 1px solid var(--bf-line); }
.bf-row:first-child { border-top: 0; }
.bf-rank { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--bf-tint);
           color: var(--bf-muted); font: 600 .82rem/1 "IBM Plex Mono", monospace; }
.bf-row:nth-child(1) .bf-rank { background: var(--bf-accent); color: var(--bf-on-accent); }
.bf-row:nth-child(2) .bf-rank, .bf-row:nth-child(3) .bf-rank { background: var(--bf-accent-soft); color: var(--bf-navy); }
.bf-row-name { min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.bf-row-score { font: 600 1.05rem/1 "IBM Plex Mono", monospace; font-variant-numeric: tabular-nums; color: var(--bf-navy); }
.bf-row.is-me { border-radius: 12px; background: var(--bf-tint); }
.bf-row.is-me + .bf-row { border-top-color: transparent; }
.bf-row.is-new { animation: bf-glow 1.6s ease-out; }
.bf-you { margin-left: 8px; font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
          color: var(--bf-accent); }
.bf-board-empty { margin: 6px 0 4px; color: var(--bf-muted); }
.bf-board-empty[hidden] { display: none; }
.bf-board-note { margin: 12px 0 0; font-size: .8rem; line-height: 1.45; color: var(--bf-muted); }
@keyframes bf-glow { 0% { box-shadow: 0 0 0 3px var(--bf-accent); } 100% { box-shadow: 0 0 0 3px transparent; } }

/* The eight switches */
.bf-switches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; }
.bf-switch { position: relative; display: flex; flex-direction: column; align-items: center; gap: 9px;
             padding: 12px 2px 10px; border: 0; border-radius: 16px; background: var(--bf-tint); color: var(--bf-ink);
             cursor: pointer; touch-action: manipulation; user-select: none;
             transition: background-color .12s, color .12s, transform .08s; }
.bf-switch:active:not(:disabled) { transform: scale(.95); }
.bf-switch:disabled { cursor: default; opacity: .6; }
.bf-switch.is-on { background: var(--bf-accent); color: var(--bf-on-accent); }
.bf-switch-value { font-size: 1rem; font-weight: 600; }
.bf-toggle { position: relative; width: 38px; height: 22px; border-radius: 999px; background: var(--bf-track);
             transition: background-color .12s; }
.bf-knob { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff;
           box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .14s ease; }
.bf-switch.is-on .bf-toggle { background: rgba(255, 255, 255, .92); }
.bf-switch.is-on .bf-knob { transform: translateX(16px); background: var(--bf-accent); box-shadow: none; }
.bf-bit { font-size: 1.3rem; font-weight: 600; line-height: 1; }
.bf-key { display: none; position: absolute; top: 5px; right: 7px; padding: 0; background: none; box-shadow: none;
          color: inherit; font: 500 .62rem/1 "IBM Plex Mono", monospace; opacity: .5; }
.bf-overlay .bf-keyboard-only { display: none; }
@media (hover: hover) and (pointer: fine) {
  .bf-key { display: block; }
  .bf-overlay .bf-keyboard-only { display: block; }
}

@media (max-width: 560px) {
  .bitflip { padding: 16px; border-radius: 20px; }
  .bf-switches { grid-template-columns: repeat(4, 1fr); }
  .bf-stage { min-height: 250px; }
  .bf-value { font-size: 1.35rem; }
  .bf-board { padding: 16px 14px 14px; border-radius: 20px; }
}

@keyframes bf-in { from { transform: scale(.82); opacity: .2; } to { transform: scale(1); opacity: 1; } }
@keyframes bf-float { 0% { opacity: 0; transform: translate(-50%, 6px); }
                      20% { opacity: 1; }
                      100% { opacity: 0; transform: translate(-50%, -30px); } }
@media (prefers-reduced-motion: reduce) {
  .bf-target.is-new, .bf-count.is-tick { animation: none; }
  .bf-float.is-show { animation: bf-fade .8s ease-out forwards; }
  .bf-knob, .bf-switch { transition: none; }
  .bf-row.is-new { animation: none; }
}
@keyframes bf-fade { 0%, 60% { opacity: 1; } 100% { opacity: 0; } }

.bf-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Link back to the Games page */
.games-back { display: inline-block; margin-top: 1.25rem; font-size: .92rem; font-weight: 600; }
.games-back + h1 { margin-top: .25rem; }
