/* Code Breaker. Colours come from ../shared/base.css; the fallbacks keep the page usable without it. */
:root {
  --cb-ink: #2f3a2c;
  --cb-paper: var(--card, #fff);
  --cb-line: var(--line, #e6e0d2);
  --cb-accent: var(--accent, #a65032);
  --cb-forest: var(--forest, #3d5a3a);
  --cb-muted: var(--muted, #6b6b60);
  --cb-exact: #2f7d4f;
  --cb-near: #e0a21f;
  --peg: 44px;
}

* { box-sizing: border-box; }
body { margin: 0; background: #faf7f1; color: var(--cb-ink); font-family: system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
.cb-top .header-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--cb-line); background: var(--cb-paper); font-weight: 700; font-size: 17px; }

.cb { max-width: 640px; margin: 0 auto 56px; padding: 0 24px; }
.cb-levels { display: flex; flex-wrap: nowrap; gap: 8px; overflow-x: auto; margin: 0; padding: 8px 2px 14px; scrollbar-width: none; }
.cb-levels::-webkit-scrollbar { display: none; }
.level-tab { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 92px; padding: 9px 12px; border-radius: 14px; border: 1px solid var(--cb-line); background: var(--cb-paper); }
.level-tab b { font-size: 14px; white-space: nowrap; }
.level-tab span { font-size: 11px; color: var(--cb-muted); font-variant-numeric: tabular-nums; }
.level-tab[aria-current="true"] { background: var(--cb-forest); border-color: var(--cb-forest); color: #fff; }
.level-tab[aria-current="true"] span { color: #ffffffcc; }

.cb-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin: 4px 0 14px; }
.cb-head h1 { font: 400 clamp(26px, 5vw, 34px) Georgia, serif; margin: 4px 0 0; letter-spacing: -.5px; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 1.4px; color: var(--cb-accent); }
.soft-btn { padding: 10px 14px; border-radius: 12px; border: 1px solid var(--cb-line); background: var(--cb-paper); font-weight: 600; font-size: 14px; white-space: nowrap; }
.primary { padding: 12px 18px; border-radius: 14px; border: 0; background: var(--cb-forest); color: #fff; font-weight: 700; }
.primary:disabled { opacity: .4; cursor: default; }

/* ---------- board ---------- */
.cb-card { padding: 16px 16px 12px; background: var(--cb-paper); border: 1px solid var(--cb-line); border-radius: 22px; box-shadow: 0 10px 35px #3d44350a; }
.secret-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 6px 14px; margin-bottom: 8px; border-bottom: 1px dashed var(--cb-line); }
.secret { display: flex; gap: 8px; padding: 8px 10px; border-radius: 16px; background: #34402f; }
.secret .slot { border-color: #ffffff30; background: #ffffff14; color: #ffffffaa; font: 700 18px Georgia, serif; }
.fits { font-size: 13px; color: var(--cb-muted); text-align: right; line-height: 1.35; }
.fits b { display: block; font-size: 20px; color: var(--cb-ink); font-variant-numeric: tabular-nums; }

.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.row { display: grid; grid-template-columns: 22px auto 1fr; align-items: center; gap: 10px; padding: 5px 6px; border-radius: 14px; }
.row .num { font-size: 12px; color: #b0a890; text-align: right; font-variant-numeric: tabular-nums; }
.row.current { background: #f6f1e4; }
.row.future { opacity: .35; }
.row.future .slot { border-style: dashed; }
.pegs { display: flex; gap: 8px; }
.slot { width: var(--peg); height: var(--peg); border-radius: 50%; border: 2px solid #ddd6c4; background: #fff; display: grid; place-items: center; padding: 0; position: relative; }
.row.current .slot { border-color: #c9bfa6; }
.row.current .slot.sel { border-color: var(--cb-accent); box-shadow: 0 0 0 3px #a6503233; }
.slot.locked::after { content: "🔒"; position: absolute; right: -4px; bottom: -4px; font-size: 12px; }
.peg { width: 100%; height: 100%; border-radius: 50%; display: grid; place-items: center; box-shadow: inset 0 -4px 0 #0000001f, inset 0 3px 0 #ffffff40; }
.peg svg { width: 46%; height: 46%; }
.slot.has { border-color: transparent !important; }
.slot.pop .peg { animation: pop .35s ease; }
@keyframes pop { 40% { transform: scale(.75); } }

.fb { display: grid; grid-template-columns: repeat(3, 14px); gap: 4px; justify-content: start; }
.fb.five { grid-template-columns: repeat(3, 14px); }
.dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; vertical-align: -2px; }
.dot.exact { background: var(--cb-exact); }
.dot.near { border: 3px solid var(--cb-near); background: #fff; }
.dot.miss { background: #ece6d6; transform: scale(.55); }
.fb-text { font-size: 12px; color: var(--cb-muted); }
.row.contra .pegs { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.rows .left { display: flex; align-items: center; gap: 5px; padding: 8px 10px 2px 38px; color: #b0a890; font-size: 12px; }
.rows .left i { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid #d6cdb6; }
.rows .left span { margin-left: 6px; }
.controls { background: #faf7f1; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: center; margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--cb-line); font-size: 12px; color: var(--cb-muted); }

/* ---------- palette and tools ---------- */
.palette { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 16px 0 4px; }
.colour { width: 54px; height: 54px; border-radius: 50%; border: 3px solid #fff; padding: 0; box-shadow: 0 3px 10px #3d443522; }
.colour:disabled { opacity: .25; cursor: default; }
.colour .peg { pointer-events: none; }
.cb-tools { display: flex; gap: 8px; margin-top: 14px; }
.tool { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--cb-line); background: var(--cb-paper); font-weight: 600; font-size: 14px; }
.tool.hint { background: #fff8e1; border-color: #f0dc9a; }
.tool:disabled { opacity: .45; cursor: default; }
.cb-tools .check { flex: 1; font-size: 16px; }
button:focus-visible { outline: 3px solid var(--cb-accent); outline-offset: 2px; }

.hint-box { margin: 14px 0 0; padding: 14px 16px; border-radius: 16px; background: #fff8e1; border: 1px solid #f0dc9a; font-size: 15px; line-height: 1.5; }
.hint-box.ok { background: #eef6ea; border-color: #c4dcb8; }
.hint-box .mini { display: inline-flex; gap: 3px; vertical-align: -5px; margin: 0 2px; }
.hint-box .mini .peg, .mini-peg { width: 20px; height: 20px; display: inline-grid; border-radius: 50%; }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 24px; padding: 28px 26px 24px; max-width: min(440px, calc(100vw - 32px)); width: 100%; box-shadow: 0 30px 80px #2a302633; color: var(--cb-ink); background: #fffdf8; }
dialog.wide { max-width: min(620px, calc(100vw - 32px)); }
dialog::backdrop { background: #2a302655; }
dialog h2 { font: 400 28px Georgia, serif; margin: 6px 0 14px; }
dialog .close { position: absolute; top: 12px; right: 14px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: #f2efe6; font-size: 20px; }
.guide-list { padding-left: 20px; margin: 14px 0 20px; line-height: 1.55; font-size: 15px; }
.guide-list li { margin-bottom: 6px; }
.guide-demo { display: flex; justify-content: center; }
.guide-demo .row { background: #f6f1e4; --peg: 34px; }

#listBody section { margin-bottom: 18px; }
#listBody h3 { font-size: 14px; margin: 0 0 8px; display: flex; justify-content: space-between; gap: 8px; }
#listBody h3 span { font-weight: 400; color: var(--cb-muted); text-align: right; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; }
.chip { height: 46px; border-radius: 12px; border: 1px solid var(--cb-line); background: #fff; font-size: 13px; font-weight: 700; color: var(--cb-muted); display: grid; place-items: center; line-height: 1.1; }
.chip small { display: block; font-size: 10px; font-weight: 600; }
.chip.solved { background: #e6f2e2; border-color: #c4dcb8; color: var(--cb-forest); }
.chip.missed { background: #f2efe6; color: #b0a890; }
.chip.going { border-color: var(--cb-near); }
.chip.current { box-shadow: 0 0 0 2px var(--cb-accent) inset; border-color: var(--cb-accent); }

#end { text-align: center; }
.end-code { display: inline-flex; gap: 8px; padding: 10px 12px; border-radius: 18px; background: #34402f; margin: 4px 0 14px; animation: win-in .6s cubic-bezier(.2, 1.4, .4, 1); }
.end-code .peg { width: 40px; height: 40px; }
@keyframes win-in { from { transform: scale(.5); opacity: 0; } }
.win-points { font-weight: 700; color: var(--cb-forest); min-height: 1.4em; margin: -6px 0 6px; }
.win-note { color: var(--cb-muted); margin: 0 0 18px; font-size: 14px; }
.win-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

@media (max-width: 560px) {
  :root { --peg: 40px; }
  .cb { padding: 0 16px; }
  .cb-card { padding: 12px 10px 10px; border-radius: 18px; }
  .row { gap: 8px; grid-template-columns: 18px auto 1fr; padding: 4px; }
  .pegs { gap: 6px; }
  .palette { gap: 7px; flex-wrap: nowrap; margin: 0; padding-top: 12px; }
  .colour { width: 42px; height: 42px; border-width: 2px; flex: 0 0 auto; }
  .controls { position: sticky; bottom: 0; z-index: 2; padding: 0 0 calc(12px + env(safe-area-inset-bottom)); box-shadow: 0 -12px 16px -12px #3d443522; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
  .cb-tools { margin-top: 10px; }
  .secret .slot { --peg: 36px; }
}
@media (max-width: 380px) { :root { --peg: 34px; } .colour { width: 38px; height: 38px; } .palette { gap: 5px; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
