: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);
  --c1: #e2574c;
  --c2: #f0a23a;
  --c3: #45a872;
  --c4: #3b86d6;
  --c5: #9563d3;
}

* { 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; }
}
