/* rubiks.css — the shared look of every page under /experiments/rubiks/.
 *
 * Colours come from /shared/tokens.css (loaded first, with /shared/theme.js before
 * it). The only colours defined here are the six sticker colours, which are the
 * same in every theme because they are the colours of a real cube.
 *
 * Page-specific styles go in their own file (css/solve.css, css/learn.css, …) and
 * build on the classes here. Prefer these components to new ones:
 *
 *   .rk-bar            the app bar (brand + nav), sticky
 *   .rk-page           the content column;  .rk-page.is-wide for full-width tools
 *   .rk-hero           a page heading block: .eyebrow, h1, .lede
 *   .panel             a raised card;  .panel-title inside
 *   .btn               a button;  .btn.primary  .btn.ghost  .btn.small  .btn.danger
 *   .seg               a segmented control: <div class="seg"><button aria-pressed>…
 *   .chip              a small pill;  .chip.ok  .chip.warn  .chip.bad
 *   .field             label + control stacked
 *   .alg               an algorithm in monospace (wrap with <code class="alg">)
 *   .kbd               a key cap
 *   .grid-2 .grid-3    responsive grids
 *   .stage             a canvas holder for a 3-D cube (keeps a square-ish aspect)
 *   .toast-host        where shell.js toast() puts messages
 *   dialog.rk-dialog   a modal (use showModal())
 */

:root {
  --st-w: #F5F5F0;
  --st-r: #C8102E;
  --st-g: #009B48;
  --st-y: #FFD500;
  --st-o: #FF6A13;
  --st-b: #0046AD;
  --st-unknown: #6B6275;
  --cube-plastic: #121014;

  --bar-h: 58px;
  --page-max: 1180px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
}
img, svg, canvas { max-width: 100%; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 0.5em; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.4rem); letter-spacing: -0.01em; }
h2 { font-size: clamp(1.25rem, 1.05rem + 0.8vw, 1.6rem); }
h3 { font-size: 1.1rem; }
p { margin: 0 0 0.9em; }
a { color: var(--accent-text); }
a:hover { text-decoration-thickness: 2px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.5rem 0; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
[hidden] { display: none !important; }

/* ── app bar ─────────────────────────────────────────────────────────────── */
.rk-bar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.rk-bar-inner {
  max-width: var(--page-max); margin: 0 auto;
  min-height: var(--bar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
}
.rk-brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none; font-weight: 700;
  min-height: 44px; flex: none;
}
.rk-brand svg { width: 30px; height: 30px; }
.rk-brand span { font-size: 1.05rem; letter-spacing: 0.01em; }
.rk-nav {
  display: flex; gap: 2px; margin-left: auto;
  overflow-x: auto; scrollbar-width: none;
}
.rk-nav::-webkit-scrollbar { display: none; }
.rk-nav a {
  display: flex; align-items: center;
  min-height: 40px; padding: 0 12px;
  border-radius: var(--radius-pill);
  color: var(--ink-dim); text-decoration: none; font-weight: 600; font-size: 0.92rem;
  white-space: nowrap;
}
.rk-nav a:hover { color: var(--ink); background: var(--surface-hi); }
.rk-nav a[aria-current="page"] { color: var(--accent-ink); background: var(--accent); }
.rk-theme {
  flex: none;
  border: 1px solid var(--line); background: transparent; color: var(--ink-dim);
  border-radius: var(--radius-pill); cursor: pointer; font: inherit;
  min-block-size: 40px; min-inline-size: 40px; padding: 0 10px;
}
.rk-theme:hover { color: var(--ink); border-color: var(--line-strong); }
.rk-menu-btn { display: none; }

@media (max-width: 860px) {
  .rk-bar-inner { flex-wrap: wrap; padding-bottom: 6px; }
  .rk-nav { order: 3; width: 100%; margin-left: 0; }
  .rk-theme { margin-left: auto; }
}

/* ── page ────────────────────────────────────────────────────────────────── */
.rk-page {
  width: 100%; max-width: var(--page-max); margin: 0 auto;
  padding: 24px 16px 64px;
  flex: 1;
}
.rk-page.is-wide { max-width: 1440px; }
.rk-hero { margin: 8px 0 24px; }
.rk-hero .eyebrow, .eyebrow {
  text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.75rem; font-weight: 700;
  color: var(--accent-text); margin: 0 0 6px;
}
.rk-hero .lede, .lede { color: var(--ink-dim); font-size: 1.05rem; max-width: 62ch; }
.rk-foot {
  border-top: 1px solid var(--line); color: var(--ink-faint);
  font-size: var(--fs-small); text-align: center; padding: 18px 16px 28px;
}
.rk-foot a { color: var(--ink-dim); }

/* ── panels and grids ────────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--pad);
  box-shadow: var(--shadow-1);
}
.panel + .panel { margin-top: 16px; }
.panel-title {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--ink-dim); margin: 0 0 12px; font-weight: 700;
}
.panel.sunken { background: var(--surface-sunken); box-shadow: none; }
.grid-2, .grid-3 { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.spread { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--ink-dim); }
.faint { color: var(--ink-faint); }
.small { font-size: var(--fs-small); }

/* ── buttons and controls ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 0.95rem;
  min-block-size: 44px; padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface-hi); color: var(--ink);
  cursor: pointer; text-decoration: none; user-select: none;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}
.btn:hover { border-color: var(--ink-faint); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn.small { min-block-size: 36px; min-inline-size: 36px; padding: 0 10px; font-size: 0.85rem; border-radius: var(--radius-sm); }
.btn.icon { padding: 0; min-inline-size: 44px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn svg { width: 18px; height: 18px; flex: none; }

.seg {
  display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px;
  background: var(--surface-sunken); border: 1px solid var(--line);
  border-radius: var(--radius);
}
.seg button {
  font: inherit; font-weight: 600; font-size: 0.9rem;
  min-block-size: 38px; min-inline-size: 38px; padding: 0 12px;
  border: 0; border-radius: calc(var(--radius) - 3px);
  background: transparent; color: var(--ink-dim); cursor: pointer;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: var(--radius-pill);
  font-size: 0.8rem; font-weight: 600;
  background: var(--surface-hi); color: var(--ink-dim); border: 1px solid var(--line);
}
.chip.ok { color: var(--safe-text); border-color: color-mix(in srgb, var(--safe) 50%, transparent); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.chip.bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.chip.accent { color: var(--accent-text); background: var(--accent-soft); border-color: var(--accent-line); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .label { font-size: var(--fs-small); color: var(--ink-dim); font-weight: 600; }
input[type="text"], input[type="number"], input[type="search"], select, textarea {
  font: inherit; color: var(--ink);
  background: var(--surface-sunken);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  min-block-size: 44px; padding: 8px 12px;
}
textarea { min-height: 88px; resize: vertical; }
input[type="range"] { accent-color: var(--accent); min-block-size: 32px; }

code, .alg, .mono { font-family: var(--font-mono); }
.alg {
  font-size: var(--fs-mono); font-weight: 600; letter-spacing: 0.02em;
  background: var(--surface-sunken); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 2px 8px;
  white-space: normal; word-spacing: 0.15em;
}
.kbd {
  display: inline-block; font-family: var(--font-mono); font-size: 0.8rem; font-weight: 700;
  padding: 1px 7px; border-radius: 6px;
  border: 1px solid var(--line-strong); border-bottom-width: 3px;
  background: var(--surface-hi); color: var(--ink);
}

/* Sticker swatches (painter palette, legends). */
.swatch {
  display: inline-block; width: 1.1em; height: 1.1em; border-radius: 4px;
  border: 1px solid rgb(0 0 0 / 0.35); vertical-align: -0.15em;
}
.swatch[data-c="0"] { background: var(--st-w); }
.swatch[data-c="1"] { background: var(--st-r); }
.swatch[data-c="2"] { background: var(--st-g); }
.swatch[data-c="3"] { background: var(--st-y); }
.swatch[data-c="4"] { background: var(--st-o); }
.swatch[data-c="5"] { background: var(--st-b); }
.swatch[data-c="6"] { background: var(--st-unknown); }

/* A 3-D cube holder. The renderer fills it; the aspect keeps layout stable before
   the canvas exists. */
.stage {
  position: relative; width: 100%; aspect-ratio: 1 / 1; max-height: 70vh;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(120% 90% at 50% 15%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 60%),
    var(--surface-sunken);
  border: 1px solid var(--line);
  overflow: hidden;
  touch-action: none;
}
.stage canvas { display: block; width: 100% !important; height: 100% !important; }
.stage.flat { background: transparent; border: 0; }

/* ── dialogs and toasts ──────────────────────────────────────────────────── */
dialog.rk-dialog {
  border: 1px solid var(--line-strong); border-radius: var(--radius-xl);
  background: var(--surface); color: var(--ink);
  padding: 0; width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  box-shadow: var(--shadow-2);
}
dialog.rk-dialog::backdrop { background: rgb(8 6 12 / 0.6); backdrop-filter: blur(2px); }
.rk-dialog-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.rk-dialog-head h2 { margin: 0; font-size: 1.15rem; flex: 1; }
.rk-dialog-body { padding: 16px; overflow: auto; max-height: calc(100vh - 160px); }
.rk-dialog-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }

.toast-host {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 100;
  width: min(480px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface-hi); color: var(--ink);
  border: 1px solid var(--line-strong); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow-2);
  animation: toast-in 0.2s ease-out;
}
.toast.ok { border-left-color: var(--safe); }
.toast.warn { border-left-color: var(--warn); }
.toast.bad { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── feature cards (home, hubs) ──────────────────────────────────────────── */
.card-link {
  display: flex; flex-direction: column; gap: 6px;
  padding: 18px; border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--line);
  color: var(--ink); text-decoration: none;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.card-link:hover { transform: translateY(-3px); border-color: var(--accent-line); box-shadow: var(--shadow-2); }
.card-link h3 { margin: 4px 0 0; }
.card-link p { margin: 0; color: var(--ink-dim); font-size: 0.93rem; }
.card-link .card-icon { width: 44px; height: 44px; }

/* Loading spinner */
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media print {
  .rk-bar, .rk-foot, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
}

/* Small phones: the seven nav links fit on one line from 375px up; narrower than
   that the row scrolls sideways (it never widens the page). */
@media (max-width: 420px) {
  .rk-nav { gap: 0; justify-content: space-between; }
  .rk-nav a { padding: 0 5px; font-size: 0.8rem; min-height: 38px; }
}

/* Headings that pages focus from script (tabindex="-1", to move screen readers to new
   content) don't need a visible ring: they aren't controls. */
[tabindex="-1"]:focus { outline: none; box-shadow: none; }
