:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1d1c1a;
  --muted: #5f5c55;
  --line: #dedbd2;
  --accent: #0b6e4f;
  --accent-soft: #e2f1eb;
  --warn-soft: #fbf1dc;
  --warn: #8a5a00;
  --chip: #ebe9e3;
  --chip-done: #c9e6da;
  --chip-next: #0b6e4f;
  --code-bg: #f1efe9;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --c-y: #ffd500; --c-w: #ffffff; --c-g: #00a152; --c-b: #1a5fd0; --c-r: #c8102e; --c-o: #ff6a13; --c-x: #9a9890;
  --plastic: #161616;
  --dia-stroke: #1d1c1a;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412; --surface: #1d1d1a; --surface-2: #262622; --text: #ecebe6; --muted: #a8a59c; --line: #34332e;
    --accent: #4fc79a; --accent-soft: #1b3229; --warn-soft: #33290f; --warn: #f1c46b;
    --chip: #2c2b27; --chip-done: #1f4537; --chip-next: #4fc79a; --code-bg: #262622;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --c-x: #5d5b55; --dia-stroke: #0b0b0a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141412; --surface: #1d1d1a; --surface-2: #262622; --text: #ecebe6; --muted: #a8a59c; --line: #34332e;
  --accent: #4fc79a; --accent-soft: #1b3229; --warn-soft: #33290f; --warn: #f1c46b;
  --chip: #2c2b27; --chip-done: #1f4537; --chip-next: #4fc79a; --code-bg: #262622;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --c-x: #5d5b55; --dia-stroke: #0b0b0a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html.no-scroll { overflow: hidden; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3, h4 { line-height: 1.25; margin: 1.6em 0 .5em; }
h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); margin-top: .4em; letter-spacing: -.01em; }
h2 { font-size: 1.5rem; padding-top: .6em; border-top: 1px solid var(--line); }
h3 { font-size: 1.15rem; }
p, li { max-width: 72ch; }
code, .alg {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .95em;
  background: var(--code-bg); padding: .1em .4em; border-radius: 6px; white-space: nowrap;
}
.alg { font-weight: 600; white-space: normal; }
.alg-big { display: inline-block; font-size: 1.05rem; padding: .3em .6em; margin: .2em 0; }
kbd { font-family: inherit; font-size: .85em; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 .35em; background: var(--surface); }

/* layout */
.top {
  position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line);
}
/* links scroll sideways on narrow screens; the theme switch stays put on the right */
.top-in { max-width: 1080px; margin: 0 auto; padding: 0 12px 0 16px; display: flex; gap: .4rem; align-items: center; }
.top nav { flex: 1; min-width: 0; padding: .55rem 0; display: flex; gap: .25rem; align-items: center; overflow-x: auto; scrollbar-width: none; }
.top nav::-webkit-scrollbar { display: none; }
.top a { text-decoration: none; color: var(--muted); padding: .35rem .6rem; border-radius: 8px; white-space: nowrap; font-size: .95rem; }
.top a:hover { background: var(--surface-2); color: var(--text); }
.top a.on { color: var(--text); background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
.top .brand { font-weight: 700; color: var(--text); margin-right: .4rem; display: flex; align-items: center; gap: .4rem; }
.top .hub-link { margin-left: auto; font-size: .85rem; }
.top .hub-link::before { content: "← "; }
html.hosted:not(.installed) .top .hub-link[hidden] { display: inline-block; }
.brand-mark { display: inline-grid; grid-template-columns: repeat(3, 6px); gap: 1px; }
.brand-mark i { width: 6px; height: 6px; border-radius: 1px; }
main { max-width: 1080px; margin: 0 auto; padding: 1rem 16px 5rem; }
.lead { font-size: 1.12rem; color: var(--muted); max-width: 66ch; }
.foot { color: var(--muted); font-size: .9rem; border-top: 1px solid var(--line); margin-top: 4rem; padding-top: 1rem; }
.foot p { margin: .35rem 0; }
.foot .playlist { font-size: .95rem; }
.foot .playlist a { font-weight: 600; text-decoration: none; }
.foot .playlist a:hover { text-decoration: underline; }

/* callouts */
.tip, .note, .warn {
  border-radius: var(--radius); padding: .8rem 1rem; margin: 1rem 0; max-width: 80ch;
  background: var(--accent-soft); border-left: 4px solid var(--accent);
}
.tip > :first-child, .note > :first-child, .warn > :first-child { margin-top: 0; }
.tip > :last-child, .note > :last-child, .warn > :last-child { margin-bottom: 0; }
.tip::before { content: "J Perm tip"; display: block; font-weight: 700; font-size: .8rem; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); margin-bottom: .2rem; }
.note { background: var(--surface-2); border-left-color: var(--muted); }
.warn { background: var(--warn-soft); border-left-color: var(--warn); }
.warn::before { content: "Watch out"; display: block; font-weight: 700; font-size: .8rem; letter-spacing: .04em; text-transform: uppercase; color: var(--warn); margin-bottom: .2rem; }

/* cards & grids */
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem;
  box-shadow: var(--shadow); min-width: 0;
}
.card h3, .card h4 { margin-top: 0; }
.card p { margin: .4em 0; }
a.card { text-decoration: none; color: inherit; display: block; transition: transform .15s; }
a.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .kicker { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }

/* step layout: text + player side by side */
.step { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1.5rem; align-items: start; margin: 1.2rem 0 2rem; }
.step .player-col { display: flex; flex-direction: column; gap: 1rem; }
@media (max-width: 760px) { .step { grid-template-columns: minmax(0, 1fr); } .step .player-col { align-items: center; } }

/* case cards (OLL/PLL) */
.cases { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); }
.case {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem;
  display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto 1fr; gap: .4rem .8rem; align-content: start;
}
.case .dia-wrap { grid-row: span 2; align-self: center; }
.case .name { font-weight: 700; align-self: end; line-height: 1.3; }
.case .meta { align-self: start; }
.case .alg { grid-column: 1 / -1; font-size: .9rem; display: block; padding: .35em .5em; line-height: 1.5; }
.case .meta { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.case[data-status="learning"] { border-color: var(--warn); }
.case[data-status="learned"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface)); }
.status-btn {
  font: inherit; font-size: .78rem; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  border-radius: 999px; padding: .1rem .55rem; cursor: pointer;
}
.status-btn[data-v="learning"] { color: var(--warn); border-color: var(--warn); }
.status-btn[data-v="learned"] { color: var(--accent); border-color: var(--accent); }
.play-btn { font: inherit; font-size: .78rem; border: 1px solid var(--accent); background: transparent; color: var(--accent); border-radius: 999px; padding: .1rem .55rem; cursor: pointer; }
.play-btn:hover { background: var(--accent-soft); }
.group-head { display: flex; align-items: baseline; gap: .8rem; flex-wrap: wrap; }
.group-head .count { color: var(--muted); font-size: .9rem; }

/* diagrams */
.dia { display: block; }
.dia-arrow { stroke: #111; stroke-width: 2.6; stroke-linecap: round; }
.dia-head { fill: #111; }
.dia-play { cursor: pointer; border-radius: 8px; transition: transform .12s; }
.dia-play:hover { transform: scale(1.04); }
.dia-play:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* tables */
table { border-collapse: collapse; width: 100%; margin: 1rem 0; font-size: .95rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.table-wrap { overflow-x: auto; }

/* ---------- 3D player ---------- */
.cp { display: inline-flex; flex-direction: column; align-items: center; gap: .5rem; outline: none; max-width: 100%; }
.cp:focus-visible .cp-stage { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 12px; }
.cp-stage { display: grid; place-items: center; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.cp-stage.dragging { cursor: grabbing; }
.cp-cube { position: relative; width: 0; height: 0; transform-style: preserve-3d; }
.cp-face { position: absolute; background: var(--plastic); border-radius: 9%; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.cp-cube:not(.turning) .cp-inner { display: none; }
.cp-face i { position: absolute; inset: 5%; border-radius: 13%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }
.cp-bar { display: flex; gap: .25rem; align-items: center; flex-wrap: wrap; justify-content: center; }
.cp-btn, .cp-speed {
  font: inherit; font-size: .9rem; min-width: 2.2rem; height: 2.1rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); cursor: pointer; padding: 0 .5rem;
}
.cp-btn:hover { border-color: var(--accent); }
.cp-play { background: var(--accent); color: var(--surface); border-color: var(--accent); min-width: 2.8rem; }
.cp-speed { min-width: 3.4rem; }
.cp-moves { display: flex; flex-wrap: wrap; gap: .35rem .6rem; justify-content: center; max-width: 340px; }
.cp-group { display: inline-flex; flex-wrap: wrap; gap: .2rem; align-items: center; }
.cp-label { font-size: .72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-right: .15rem; }
.cp-chip {
  font: 600 .85rem ui-monospace, Menlo, Consolas, monospace; border: 0; border-radius: 6px; padding: .15rem .4rem;
  background: var(--chip); color: var(--text); cursor: pointer; min-width: 1.7rem;
}
.cp-chip.done { background: var(--chip-done); }
.cp-chip.next { background: var(--chip-next); color: var(--surface); }
.cp-mini { position: relative; cursor: pointer; border-radius: 12px; }
.cp-mini .cp-stage { cursor: pointer; }
.cp-mini-hint { position: absolute; right: 2px; bottom: 2px; font-size: .7rem; color: var(--muted); }

/* modal */
.cp-modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; place-items: center; z-index: 100; padding: 16px; }
.cp-modal.open { display: grid; }
.cp-modal-box { background: var(--surface); border-radius: 16px; padding: 1.2rem; max-width: 420px; width: 100%; position: relative; text-align: center; max-height: 100%; overflow: auto; }
.cp-modal-box h3 { margin: 0 2rem .3rem; }
.cp-modal-alg { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 600; margin: 0 0 .6rem; }
.cp-modal-note { color: var(--muted); font-size: .82rem; margin: .6rem 0 0; }
.cp-modal-close { position: absolute; top: .6rem; right: .6rem; border: 0; background: var(--surface-2); color: var(--text); border-radius: 50%; width: 2rem; height: 2rem; cursor: pointer; font-size: 1rem; }

/* misc */
.pill { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.roadmap { counter-reset: rm; list-style: none; padding: 0; display: grid; gap: .8rem; }
.roadmap > li { counter-increment: rm; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem .9rem 3.4rem; position: relative; max-width: none; }
.roadmap > li::before { content: counter(rm); position: absolute; left: 1rem; top: .85rem; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--accent); color: var(--surface); display: grid; place-items: center; font-weight: 700; font-size: .9rem; }
.roadmap h3 { margin: 0 0 .2rem; }
.roadmap p { margin: .2rem 0; }
.toc { display: flex; flex-wrap: wrap; gap: .4rem; margin: 1rem 0; }
.toc a { text-decoration: none; font-size: .88rem; padding: .25rem .65rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--text); }
.toc a:hover { border-color: var(--accent); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 1rem 2rem; }
.move-card { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .8rem; align-items: center; }
.move-card .big { font: 700 1.5rem ui-monospace, Menlo, Consolas, monospace; }
.input-row { display: flex; gap: .5rem; flex-wrap: wrap; margin: .5rem 0; }
.input-row input { flex: 1 1 220px; font: 600 1rem ui-monospace, Menlo, Consolas, monospace; padding: .5rem .7rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); min-width: 0; }
.btn { font: inherit; font-weight: 600; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--surface); cursor: pointer; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn kbd { background: transparent; color: inherit; border-color: currentColor; opacity: .75; margin-left: .3rem; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.sandbox { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1.5rem; align-items: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
@media (max-width: 760px) { .sandbox { grid-template-columns: minmax(0,1fr); justify-items: center; } }
.movepad { display: grid; grid-template-columns: repeat(auto-fill, minmax(3.1rem, 1fr)); gap: .3rem; }
.movepad button { font: 600 .95rem ui-monospace, Menlo, Consolas, monospace; padding: .45rem 0; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); cursor: pointer; }
.movepad button:hover { border-color: var(--accent); }
.history { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9rem; color: var(--muted); min-height: 1.5em; word-break: break-word; }
.face-key { display: inline-block; width: .9em; height: .9em; border-radius: 3px; vertical-align: -.1em; border: 1px solid rgba(0,0,0,.25); }

/* App update notice (assets/pwa.js) */
.pwa-toast { position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); z-index: 60; display: flex; gap: .8rem; align-items: center; max-width: calc(100% - 2rem); padding: .6rem .7rem .6rem 1rem; border-radius: 12px; background: var(--surface); color: var(--text); border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0,0,0,.18); }
