:root {
  --bg: #080c10;
  --surface: #0f1419;
  --raised: #161c24;
  --frame: #0b0f14;
  --text: #e8eaf0;
  --muted: #6b7585;
  --accent: #00d4ff;
  --border: rgba(255, 255, 255, 0.08);
  --c-U: #f4f5f7;
  --c-R: #e0313c;
  --c-F: #1fae55;
  --c-D: #ffd43b;
  --c-L: #ff8a1f;
  --c-B: #2f6fe4;
  --c-X: #3a4350;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --cube-scale: 1;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.embed { background: var(--surface); }
body.embed .top, body.embed .foot { display: none; }
body.embed .app { padding: 16px; }

.app { max-width: 1180px; margin: 0 auto; padding: 28px 24px; }
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
h1 { font-size: 28px; margin: 0; letter-spacing: -0.01em; }
.sub { color: var(--muted); margin: 4px 0 0; font-family: var(--mono); font-size: 12px; }
h2 { font-size: 12px; margin: 0; font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.14em; color: var(--accent); font-weight: 500; }

.pill { font-family: var(--mono); font-size: 12px; padding: 6px 10px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.pill[data-state="ready"] { color: var(--accent); border-color: rgba(0, 212, 255, 0.35); }
.pill[data-state="error"] { color: #ff6b6b; border-color: rgba(255, 107, 107, 0.4); }

.layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(320px, 1fr); gap: 20px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } :root { --cube-scale: 0.8; } }

/* ---- 3D stage ---- */
.stage { background: var(--frame); border: 1px solid var(--border); padding: 12px 12px 16px; }
.scene {
  height: calc(400px * var(--cube-scale));
  perspective: 1100px;
  display: grid;
  place-items: center;
  cursor: grab;
  touch-action: none;
  user-select: none;
  background: radial-gradient(circle at 50% 45%, rgba(0, 212, 255, 0.07), transparent 60%);
}
.scene:active { cursor: grabbing; }
.cube { position: relative; width: 0; height: 0; transform-style: preserve-3d; scale: var(--cube-scale); }
.cubie { position: absolute; width: 64px; height: 64px; margin: -32px 0 0 -32px; transform-style: preserve-3d; }
.cubie-face {
  position: absolute; inset: 0; background: #07090c; border-radius: 6px;
  backface-visibility: hidden; display: grid; place-items: center;
}
.sticker {
  width: 56px; height: 56px; border-radius: 6px;
  background: var(--c-X);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25), inset 0 6px 10px rgba(255, 255, 255, 0.10);
  transition: background-color 120ms ease, outline-color 120ms ease;
  outline: 3px solid transparent; outline-offset: -3px;
}
.sticker.hl { outline-color: rgba(0, 212, 255, 0.95); }
[data-c="U"] { background: var(--c-U); } [data-c="R"] { background: var(--c-R); }
[data-c="F"] { background: var(--c-F); } [data-c="D"] { background: var(--c-D); }
[data-c="L"] { background: var(--c-L); } [data-c="B"] { background: var(--c-B); }
[data-c="X"] { background: var(--c-X); }
body.painting .scene, body.painting .net .tile { cursor: crosshair; }

.hint { text-align: center; color: var(--muted); font-size: 12px; margin: 4px 0 14px; font-family: var(--mono); }

/* ---- flat net: 4 columns x 3 rows of faces ---- */
.net {
  display: grid; gap: 6px; justify-content: center;
  grid-template-columns: repeat(4, 84px);
  grid-template-areas: ". U . ." "L F R B" ". D . .";
}
.net .face { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.net .tile { aspect-ratio: 1; border-radius: 3px; border: 0; padding: 0; cursor: default; }
.net .tile.center { box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35); }
.net .tile.hl { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (max-width: 480px) { .net { grid-template-columns: repeat(4, 66px); } }

/* ---- panel ---- */
.panel { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); padding: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.status { margin: 12px 0 0; font-family: var(--mono); font-size: 13px; min-height: 1.5em; }
.status.error { color: #ff7a7a; }

.btn {
  font: inherit; font-size: 14px; color: var(--muted); background: transparent;
  border: 1px solid var(--border); padding: 9px 16px; cursor: pointer;
  transition: color 150ms, border-color 150ms, opacity 150ms;
}
.btn:hover:not(:disabled) { color: var(--accent); border-color: rgba(0, 212, 255, 0.4); }
.btn.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover:not(:disabled) { color: var(--bg); opacity: 0.9; }
.btn.small { padding: 6px 12px; font-size: 12px; }
.btn:disabled, .icon:disabled { opacity: 0.4; cursor: not-allowed; }

.moves { display: flex; flex-wrap: wrap; gap: 6px; min-height: 36px; align-content: flex-start; }
.moves .empty { color: var(--muted); font-size: 13px; }
.chip {
  font-family: var(--mono); font-size: 13px; min-width: 38px; text-align: center;
  padding: 5px 6px; border: 1px solid var(--border); background: var(--frame); color: var(--text);
  cursor: pointer;
}
.chip.done { color: var(--muted); }
.chip.current { border-color: var(--accent); color: var(--accent); background: rgba(0, 212, 255, 0.08); }

.playback { display: flex; align-items: center; gap: 6px; margin-top: 14px; flex-wrap: wrap; }
.icon {
  width: 38px; height: 34px; font-size: 13px; background: var(--raised); color: var(--text);
  border: 1px solid var(--border); cursor: pointer;
}
.icon:hover:not(:disabled) { border-color: rgba(0, 212, 255, 0.4); color: var(--accent); }
.icon.play { width: 46px; }
.speed { margin-left: auto; display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); font-family: var(--mono); }
.speed input { width: 96px; accent-color: var(--accent); direction: rtl; }

.badges { display: flex; gap: 6px; }
.badge { font-family: var(--mono); font-size: 11px; padding: 2px 8px; border: 1px solid rgba(0, 212, 255, 0.35); color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0 0; }
.stats:empty { display: none; }
.stats div { background: var(--frame); border: 1px solid var(--border); padding: 8px 10px; }
.stats dt { font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); font-family: var(--mono); }
.stats dd { margin: 2px 0 0; font-family: var(--mono); font-size: 16px; }

.turnpad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.turnpad button {
  font-family: var(--mono); font-size: 13px; padding: 8px 0; background: var(--frame);
  color: var(--text); border: 1px solid var(--border); cursor: pointer; position: relative;
}
.turnpad button::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--face);
}
.turnpad button:hover { border-color: rgba(0, 212, 255, 0.4); color: var(--accent); }
.alg { display: flex; gap: 8px; margin-top: 10px; }
.alg input {
  flex: 1; min-width: 0; font-family: var(--mono); font-size: 13px; background: var(--frame);
  color: var(--text); border: 1px solid var(--border); padding: 8px 10px;
}
.alg input:focus { outline: none; border-color: rgba(0, 212, 255, 0.5); }

.switch { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); cursor: pointer; }
.switch input { accent-color: var(--accent); }
.palette { display: flex; gap: 8px; margin: 12px 0; }
.swatch {
  width: 34px; height: 34px; border-radius: 4px; border: 2px solid transparent; cursor: pointer;
}
.swatch[aria-checked="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg) inset; }

.settings summary { cursor: pointer; font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--accent); }
.settings label { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.settings select { background: var(--frame); color: var(--text); border: 1px solid var(--border); padding: 6px 8px; font: inherit; font-size: 13px; }

.foot { display: flex; justify-content: space-between; gap: 16px; margin-top: 18px; flex-wrap: wrap; align-items: center; }
.foot code { font-family: var(--mono); font-size: 11px; color: var(--muted); word-break: break-all; }
.foot a { color: var(--accent); font-size: 13px; text-decoration: none; }
.foot a:hover { text-decoration: underline; }
