:root {
  --bg: #f6f3ee;
  --panel: #ffffff;
  --ink: #23201c;
  --muted: #6b645b;
  --line: #e2dcd2;
  --accent: #d2552f;
  --accent-ink: #ffffff;
  --board: #3b3631;
  --tile: #4a443e;
  --tile-ink: #8d857b;
  --focus: #1d6fd1;
  --radius: 12px;
  --cell: min(112px, 20vw);
  /* cube colours of the "CubiMBox Standard" set */
  --c1: #2f80d8;
  --c2: #2fa860;
  --c3: #e2403f;
  --c4: #f07c32;
  --c5: #8fd4e8;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
}

a { color: #b2401d; }
a:hover { color: #7d2b12; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip { position: absolute; left: -999px; top: 0; background: #fff; padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: .5rem; }

/* ---------- header / nav ---------- */
header.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(246, 243, 238, .94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}

.top-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: .55rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 800;
  font-size: 1.2rem;
  text-decoration: none;
  color: var(--ink);
}
.brand svg { width: 30px; height: 30px; }

nav.menu ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  margin: 0;
  padding: 0;
}
nav.menu a {
  display: block;
  padding: .4rem .7rem;
  border-radius: 999px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 600;
  font-size: .95rem;
}
nav.menu a:hover { background: #ebe5db; }
nav.menu a[aria-current="page"] { background: var(--ink); color: #fff; }

/* ---------- layout ---------- */
main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
main > section { scroll-margin-top: 100vh; } /* the #hash jump always clamps to the top of the page */
@media (max-width: 520px) { .stage { padding: .6rem; } main { padding-left: .7rem; padding-right: .7rem; } }
section > h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); margin: .2rem 0 1rem; line-height: 1.2; }
h2 { margin-top: 2rem; }

.lead { font-size: 1.15rem; color: var(--muted); max-width: 60ch; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
}

.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }

.hero {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 2rem;
  align-items: center;
}
@media (max-width: 820px) { .hero { grid-template-columns: 1fr; } }

.cta { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.2rem; }

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .9rem; color: var(--muted); }

code, .mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: .92em; }
code { background: #efe9df; padding: .05rem .35rem; border-radius: 5px; }

.note {
  border-left: 4px solid var(--accent);
  background: #fff6f1;
  padding: .8rem 1rem;
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* ---------- buttons / forms ---------- */
button, .btn {
  font: inherit;
  font-weight: 650;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: .5rem .9rem;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
}
button:hover, .btn:hover { background: #f0ebe3; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover, .btn.primary:hover { background: #b9461f; }
button:disabled { opacity: .5; cursor: not-allowed; }

select, input[type="text"] {
  font: inherit;
  padding: .4rem .5rem;
  border: 1px solid #cfc7ba;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
input.state { width: 100%; max-width: 22rem; font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: .05em; }
label { font-weight: 600; font-size: .9rem; }

.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* ---------- 3D board ---------- */
.game-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(260px, 1fr); gap: 1.5rem; align-items: start; }
@media (max-width: 860px) { .game-layout { grid-template-columns: 1fr; } }

.stage {
  background: radial-gradient(ellipse at 50% 30%, #fffdf9, #e9e2d7);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
}

.scene {
  perspective: 1100px;
  width: calc(var(--cell) * 3 + 30px);
  max-width: 100%;
  height: calc(var(--cell) * 2.35 + 30px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.board {
  position: relative;
  width: calc(var(--cell) * 3);
  height: calc(var(--cell) * 2);
  transform-style: preserve-3d;
  transition: transform .45s ease;
  background: var(--board);
  border-radius: 10px;
  box-shadow: 0 0 0 12px #2c2824, 0 18px 30px rgba(0, 0, 0, .35);
}

.tile {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: calc(var(--cell) * .42);
  color: var(--tile-ink);
}
.tile::before {
  content: "";
  position: absolute;
  inset: 5%;
  border-radius: 8px;
  background: var(--tile);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .35);
  z-index: -1;
}
.tile span { position: relative; }

.cube {
  position: absolute;
  left: 0;
  top: 0;
  transform-style: preserve-3d;
  cursor: pointer;
}
.cube.locked { cursor: default; }

.face {
  position: absolute;
  inset: 0;
  border-radius: 9%;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(0, 0, 0, .18);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .18), inset 0 -6px 10px rgba(0, 0, 0, .12);
}
.face.num {
  font-weight: 900;
  color: #1f1b17;
  flex-direction: column;
  gap: 2%;
}
.face.num .digit { line-height: 1; }
.face.num .base { width: 34%; height: 6%; border-radius: 4px; background: #1f1b17; opacity: .8; }

.cube.hint .face { box-shadow: inset 0 0 0 5px #fff, 0 0 18px #fff; }

.view-controls { margin-top: .7rem; }

.arrows {
  display: grid;
  grid-template-columns: repeat(3, 3rem);
  grid-template-rows: repeat(2, 3rem);
  gap: .3rem;
  justify-content: center;
  margin-top: .8rem;
}
.arrows button { justify-content: center; font-size: 1.3rem; padding: 0; }
.arrows .up { grid-column: 2; grid-row: 1; }
.arrows .left { grid-column: 1; grid-row: 2; }
.arrows .down { grid-column: 2; grid-row: 2; }
.arrows .right { grid-column: 3; grid-row: 2; }

.stats { display: flex; gap: 1.5rem; font-size: 1.05rem; }
.stats b { font-size: 1.4rem; display: block; }

.status { min-height: 1.6em; font-weight: 600; }
.status.win { color: #237a46; }
.status.err { color: #b3261e; }

/* ---------- move lists ---------- */
.moves {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  margin: .6rem 0;
  padding: 0;
  list-style: none;
}
.moves li {
  min-width: 2.6rem;
  text-align: center;
  padding: .15rem .3rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  font-size: .85rem;
}
.moves li small { display: block; color: var(--muted); font-size: .7rem; }
.moves li .a { font-size: 1.15rem; }
.moves li.done { background: #e6f4ea; border-color: #9fd2b0; }
.moves li.now { background: var(--accent); color: #fff; border-color: var(--accent); }
.moves li.now small { color: #ffe4d8; }

/* ---------- solver editor ---------- */
.editor { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .6rem; }
@media (max-width: 640px) { .editor { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.cell-ed { border: 1px solid var(--line); border-radius: 10px; padding: .6rem; background: #fff; }
.cell-ed h3 { margin: 0 0 .4rem; font-size: .9rem; color: var(--muted); }
.cell-ed .f { display: grid; grid-template-columns: auto 1fr; gap: .3rem .5rem; align-items: center; }
.cell-ed select { width: 100%; }
.swatch { display: inline-block; width: .9em; height: .9em; border-radius: 3px; vertical-align: -1px; margin-right: .3rem; }

.macro h3 { margin: .1rem 0 .3rem; }
.macro .meta { color: var(--muted); font-size: .9rem; }

footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .9rem;
  text-align: center;
  padding: 1.5rem 1rem 2rem;
}

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

@media (prefers-reduced-motion: reduce) {
  .board { transition: none; }
  html { scroll-behavior: auto; }
}

/* ---------- photos ---------- */
.hero-photo figure, .gallery figure, .photo-row figure { margin: 0; }
.hero-photo img {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: var(--radius);
  box-shadow: 0 14px 30px rgba(0, 0, 0, .18);
  display: block;
  background: #e9e2d7;
}
figcaption { font-size: .88rem; color: var(--muted); margin-top: .35rem; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.gallery img, .photo-row img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  background: #e9e2d7;
  transition: transform .2s ease, box-shadow .2s ease;
}
.gallery a:hover img, .photo-row a:hover img { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(0, 0, 0, .18); }
.photo-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .8rem; margin-top: .8rem; }
.credit { font-size: .85rem; color: var(--muted); margin-top: 1rem; }
.card-h { margin: 0 0 .3rem; font-size: 1.1rem; }

/* ---------- history timeline ---------- */
.timeline { list-style: none; margin: 1.5rem 0 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 7.2rem; top: .3rem; bottom: .3rem; width: 3px; background: var(--line); border-radius: 2px; }
.timeline li { display: grid; grid-template-columns: 6.5rem 1fr; gap: 1.6rem; margin-bottom: 2rem; position: relative; }
.timeline li::before {
  content: ""; position: absolute; left: calc(7.2rem - 6px); top: .35rem; width: 15px; height: 15px;
  border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--bg);
}
.timeline .when { font-weight: 800; color: var(--accent); text-align: right; padding-top: .1rem; }
.timeline h2 { margin: 0 0 .3rem; font-size: 1.2rem; }
.timeline p { margin: 0; max-width: 70ch; }
@media (max-width: 640px) {
  .timeline::before { left: .45rem; }
  .timeline li { grid-template-columns: 1fr; gap: .2rem; padding-left: 1.8rem; }
  .timeline li::before { left: 0; }
  .timeline .when { text-align: left; }
}

/* ---------- solver editor (visual) ---------- */
.solver-layout { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(250px, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 860px) { .solver-layout { grid-template-columns: 1fr; } }
.cell-panel { border: 1px solid var(--line); border-radius: 10px; padding: .9rem; background: #fff; }
.cell-panel h3 { margin: 0 0 .6rem; font-size: 1rem; }
.cell-panel .f { display: grid; grid-template-columns: auto 1fr; gap: .4rem .6rem; align-items: center; }
.cell-panel select { width: 100%; }
.cell-panel .meta { color: var(--muted); font-size: .85rem; }
.cp-desc { font-weight: 600; min-height: 1.5em; }
.tumble { margin-top: .4rem; }
.tumble .arrows { justify-content: start; margin: .3rem 0 .5rem; }
.arrows.small { grid-template-columns: repeat(3, 2.5rem); grid-template-rows: repeat(2, 2.5rem); }
.editor-board .cube, .editor-board .tile { cursor: pointer; }
.tile.selected::before { background: #6b5f52; box-shadow: inset 0 0 0 3px var(--accent); }
.cube.selected .face { box-shadow: inset 0 0 0 4px #fff, 0 0 0 3px var(--accent); }

/* ---------- playback navigation ---------- */
.pb-pos { margin: 0 0 .5rem; font-weight: 600; }
.pb-nav { margin-bottom: .4rem; }
.moves.clickable li { cursor: pointer; }
.moves.clickable li:hover { border-color: var(--accent); }
kbd { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85em; border: 1px solid #cfc7ba; border-bottom-width: 2px; border-radius: 4px; padding: 0 .3rem; background: #fff; }

/* ---------- solver: explanation + 6 cards ---------- */
.explain-grid { display: grid; grid-template-columns: 260px 1fr; gap: 1.2rem; align-items: start; }
@media (max-width: 700px) { .explain-grid { grid-template-columns: 1fr; } }
.explain-fig { margin: 0; }
.explain-fig svg { width: 100%; height: auto; font-family: inherit; }
table.faces th { color: var(--accent); font-size: 1rem; width: 1.6rem; }
table.faces td { padding-right: 1rem; }

.editor { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .7rem; }
@media (max-width: 900px) { .editor { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .editor { grid-template-columns: 1fr; } }
.cell-ed { border: 1px solid var(--line); border-radius: 10px; padding: .7rem; background: #fff; transition: box-shadow .3s; }
.cell-ed.flash { box-shadow: 0 0 0 3px var(--accent); }
.cell-ed.is-empty { background: #faf8f4; }
.cell-head { display: grid; grid-template-columns: 74px 1fr auto; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.cell-head h3 { margin: 0; font-size: .95rem; line-height: 1.25; }
.cell-head h3 small { color: var(--muted); font-weight: 600; font-size: .78rem; }
.posmap { width: 74px; height: 60px; }
.cell-ed .f { display: grid; grid-template-columns: auto 1fr; gap: .3rem .5rem; align-items: center; }
.cell-ed select { width: 100%; }
.tools { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .5rem; }
.tools button { padding: .25rem .5rem; min-width: 2.1rem; justify-content: center; }
.cell-desc { font-size: .82rem; color: var(--muted); margin: .45rem 0 0; min-height: 2.4em; }

.net { display: grid; grid-template-columns: repeat(3, 24px); grid-template-rows: repeat(4, 24px); gap: 1px; }
.net.empty { display: flex; align-items: center; justify-content: center; width: 74px; height: 99px; font-size: .7rem; color: var(--muted);
  border: 1px dashed #cfc7ba; border-radius: 6px; text-align: center; }
.np { position: relative; border-radius: 3px; display: flex; align-items: center; justify-content: center; }
.np.none { background: transparent !important; }
.np.top { outline: 2px solid #23201c; outline-offset: -1px; }
.np i { position: absolute; left: 2px; top: 0; font-style: normal; font-size: 8.5px; font-weight: 800; color: rgba(0, 0, 0, .6); }
.np b { display: flex; flex-direction: column; align-items: center; font-size: 15px; line-height: 1; color: #1f1b17; font-weight: 900; }
.np b u { display: block; width: 10px; height: 2px; background: #1f1b17; margin-top: 1px; text-decoration: none; }
details.overview { margin-top: 1rem; }
details.overview summary { cursor: pointer; font-weight: 650; }

/* brand logo (block "C" after the CubiMBox lettering) */
.brand svg { width: 32px; height: 32px; }
