/* =========================================================================
   2x2 Cube Solver — design system
   Dark glassmorphism · premium typography · responsive
   ========================================================================= */

:root {
  --bg-0: #06070c;
  --bg-1: #0a0c14;
  --glass: rgba(20, 24, 38, 0.55);
  --glass-2: rgba(30, 35, 54, 0.5);
  --stroke: rgba(255, 255, 255, 0.08);
  --stroke-strong: rgba(255, 255, 255, 0.16);
  --text: #eef1f8;
  --text-dim: #9aa3bd;
  --text-faint: #8b93af; /* lightened from #69718c for WCAG AA contrast on dark */
  --accent: #7c9cff;
  --accent-2: #59e6c3;
  --accent-grad: linear-gradient(135deg, #7c9cff 0%, #9a7cff 100%);
  --good: #34d399;
  --bad: #ff6b6b;
  --warn: #ffd23f;

  --c-white: #f6f7fb;
  --c-yellow: #ffd23f;
  --c-green: #16c172;
  --c-blue: #2b6fff;
  --c-red: #ff3b3b;
  --c-orange: #ff8c1a;

  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.7);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font: "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 80% -10%, rgba(124, 156, 255, 0.16), transparent 60%),
    radial-gradient(900px 600px at 0% 110%, rgba(89, 230, 195, 0.12), transparent 55%),
    var(--bg-0);
  background-attachment: fixed;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-height: 1.5;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--accent); color: #06070c; padding: 10px 16px; border-radius: 0 0 var(--r-sm) 0;
}
.skip-link:focus { left: 0; }

/* ---- glass primitive ---------------------------------------------------- */
.glass {
  background: var(--glass);
  border: 1px solid var(--stroke);
  border-radius: var(--r-lg);
  backdrop-filter: blur(22px) saturate(150%);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
  box-shadow: var(--shadow);
}

/* ---- header ------------------------------------------------------------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  max-width: 1500px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand__logo {
  display: grid; place-items: center;
  width: 48px; height: 48px; border-radius: 14px;
  background: var(--glass-2); border: 1px solid var(--stroke-strong);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
}
.brand__text h1 { font-size: 1.18rem; line-height: 1.1; }
.brand__text p { font-size: 0.78rem; color: var(--text-dim); margin-top: 2px; }

.status-pill {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 16px; border-radius: 999px;
  background: var(--glass-2); border: 1px solid var(--stroke);
  font-size: 0.85rem; font-weight: 550; color: var(--text-dim);
  transition: color .3s, border-color .3s;
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-faint); box-shadow: 0 0 0 0 rgba(0,0,0,0); transition: background .3s, box-shadow .3s; }
.status-pill[data-state="idle"] .status-dot { background: var(--text-faint); }
.status-pill[data-state="invalid"] { color: var(--bad); } .status-pill[data-state="invalid"] .status-dot { background: var(--bad); box-shadow: 0 0 12px var(--bad); }
.status-pill[data-state="valid"] { color: var(--good); } .status-pill[data-state="valid"] .status-dot { background: var(--good); box-shadow: 0 0 12px var(--good); }
.status-pill[data-state="solved"] { color: var(--accent-2); } .status-pill[data-state="solved"] .status-dot { background: var(--accent-2); box-shadow: 0 0 12px var(--accent-2); }
.status-pill[data-state="solving"] { color: var(--accent); } .status-pill[data-state="solving"] .status-dot { background: var(--accent); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* ---- layout grid -------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.95fr);
  grid-template-areas:
    "viewer  controls"
    "dash    controls"
    "playback playback";
  gap: clamp(14px, 1.6vw, 22px);
  max-width: 1500px;
  margin: 0 auto;
  padding: 6px clamp(16px, 4vw, 40px) 40px;
  align-items: start;
}
.viewer-card { grid-area: viewer; }
.control-card { grid-area: controls; align-self: stretch; }
.dashboard { grid-area: dash; }
.playback-card { grid-area: playback; }

/* ---- viewer ------------------------------------------------------------- */
.viewer-card { position: relative; overflow: hidden; padding: 0; }
.viewer { width: 100%; height: clamp(360px, 52vh, 620px); touch-action: none; }
.viewer__bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px;
  background: linear-gradient(to top, rgba(6,7,12,0.75), transparent);
}
.move-readout { display: flex; align-items: baseline; gap: 14px; font-variant-numeric: tabular-nums; }
.move-readout span { font-family: var(--mono); }
.move-readout__prev, .move-readout__next { color: var(--text-faint); font-size: 0.95rem; }
.move-readout__cur {
  font-size: 1.5rem; font-weight: 700; color: var(--text);
  min-width: 2.4ch; text-align: center;
  padding: 2px 12px; border-radius: 10px; background: rgba(124,156,255,0.14);
  border: 1px solid rgba(124,156,255,0.25);
}
.viewer__btns { display: flex; gap: 8px; }

/* ---- buttons ------------------------------------------------------------ */
.btn {
  appearance: none; border: 1px solid var(--stroke-strong);
  background: var(--glass-2); color: var(--text);
  padding: 11px 16px; border-radius: 12px; font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: transform .15s var(--ease), background .2s, border-color .2s, box-shadow .2s;
}
.btn:hover { background: rgba(40,46,70,0.7); border-color: var(--stroke-strong); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn--ghost { background: rgba(255,255,255,0.03); }
.btn--small { padding: 9px 13px; border-radius: 10px; font-size: 0.84rem; white-space: nowrap; }
.btn--primary { color: #05060a; border: none; background: var(--accent-grad); box-shadow: 0 10px 30px -8px rgba(124,156,255,0.55); }
.btn--primary:hover { box-shadow: 0 14px 36px -8px rgba(124,156,255,0.7); }
.btn--solve { width: 100%; padding: 14px; font-size: 1rem; margin-top: 12px; }

.icon-btn {
  appearance: none; cursor: pointer;
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; font-size: 1.05rem;
  background: var(--glass-2); border: 1px solid var(--stroke); color: var(--text);
  transition: background .2s, transform .15s var(--ease), border-color .2s;
}
.icon-btn:hover { background: rgba(40,46,70,0.8); transform: translateY(-1px); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.icon-btn--play { width: 56px; height: 56px; font-size: 1.3rem; background: var(--accent-grad); color: #05060a; border: none; box-shadow: 0 10px 26px -8px rgba(124,156,255,0.6); }

/* ---- control card ------------------------------------------------------- */
.control-card { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
/* puzzle (2x2 / 3x3) selector */
.puzzle-select { display: flex; gap: 6px; background: rgba(0,0,0,0.28); padding: 5px; border-radius: 14px; }
.puzzle-btn {
  flex: 1; appearance: none; border: 1px solid transparent; cursor: pointer;
  padding: 11px; border-radius: 10px; font-weight: 750; font-size: 0.98rem; letter-spacing: .01em;
  color: var(--text-dim); background: transparent; transition: background .2s, color .2s, border-color .2s;
}
.puzzle-btn:hover { color: var(--text); }
.puzzle-btn.is-active { background: var(--accent-grad); color: #05060a; border-color: transparent; box-shadow: 0 8px 22px -10px rgba(124,156,255,0.7); }

.tabs { display: flex; gap: 6px; background: rgba(0,0,0,0.25); padding: 5px; border-radius: 14px; }
[hidden] { display: none !important; }
.tab {
  flex: 1; appearance: none; border: none; cursor: pointer;
  padding: 10px; border-radius: 10px; font-weight: 600; font-size: 0.9rem;
  color: var(--text-dim); background: transparent; transition: background .2s, color .2s;
}
.tab.is-active { background: var(--glass-2); color: var(--text); box-shadow: inset 0 1px 0 rgba(255,255,255,0.06); }
.tab-panel { display: none; flex-direction: column; gap: 14px; }
.tab-panel.is-active { display: flex; }
.hint { font-size: 0.84rem; color: var(--text-dim); }

/* cube colour theme selector */
.theme-field { display: flex; align-items: center; gap: 10px; margin: 12px 0 4px; }
.theme-field > span { font-size: 0.8rem; color: var(--text-dim); white-space: nowrap; }
.theme-field select {
  flex: 1; min-width: 0; padding: 9px 12px; border-radius: 11px;
  background: rgba(0,0,0,0.3); border: 1px solid var(--stroke-strong); color: var(--text);
  font-family: inherit; font-size: 0.86rem; cursor: pointer;
  transition: border-color .2s, box-shadow .2s;
}
.theme-field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,156,255,0.25); }
.theme-field select option { background: #14161f; color: var(--text); }

/* palette */
.palette { display: flex; flex-wrap: wrap; gap: 9px; }
.swatch {
  width: 46px; height: 46px; border-radius: 12px; cursor: pointer;
  border: 2px solid rgba(255,255,255,0.14); position: relative;
  touch-action: manipulation;
  transition: transform .15s var(--ease), box-shadow .2s, border-color .2s;
}
.swatch:hover { transform: translateY(-2px) scale(1.04); }
.swatch.is-active { border-color: #fff; box-shadow: 0 0 0 3px rgba(124,156,255,0.5), 0 8px 20px -6px rgba(0,0,0,0.6); transform: translateY(-2px) scale(1.06); }
.swatch[data-color="white"] { background: var(--c-white); }
.swatch[data-color="yellow"] { background: var(--c-yellow); }
.swatch[data-color="green"] { background: var(--c-green); }
.swatch[data-color="blue"] { background: var(--c-blue); }
.swatch[data-color="red"] { background: var(--c-red); }
.swatch[data-color="orange"] { background: var(--c-orange); }

/* net editor */
.net {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(3, 1fr);
  grid-template-areas: ". u . ." "l f r b" ". d . .";
  /* Aspect-ratio on the net (not per-face) gives the rows a definite height so
     the faces don't collapse to a line on Safari/iPadOS 16. */
  aspect-ratio: 4 / 3;
  gap: 8px; padding: 8px; border-radius: var(--r-md);
  background: rgba(0,0,0,0.22); border: 1px solid var(--stroke);
  max-width: 360px; margin: 0 auto; width: 100%;
}
.face {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 4px; min-width: 0; min-height: 0;
}
/* 3x3 net: each face is a 3x3 grid of stickers. */
.net--3 .face { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 3px; }
.sticker.is-locked { cursor: default; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.22), inset 0 -2px 4px rgba(0,0,0,0.3); }
.sticker.is-locked:hover { transform: none; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.22); }
.face[data-face="U"] { grid-area: u; } .face[data-face="L"] { grid-area: l; }
.face[data-face="F"] { grid-area: f; } .face[data-face="R"] { grid-area: r; }
.face[data-face="B"] { grid-area: b; } .face[data-face="D"] { grid-area: d; }
.face::before {
  content: attr(data-label); position: absolute; margin-top: -16px; font-size: 0.62rem;
  color: var(--text-faint); letter-spacing: .08em; font-weight: 700;
}
.face { position: relative; }
.sticker {
  appearance: none; border: 1px solid rgba(0,0,0,0.35); border-radius: 7px; cursor: pointer;
  touch-action: manipulation;
  background: #7c8494; transition: transform .12s var(--ease), box-shadow .2s, background .15s;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.12), inset 0 -2px 4px rgba(0,0,0,0.3);
}
/* unpainted ("blank") stickers read as a neutral medium grey, clearly not white */
.sticker:not([data-color]) {
  background: #7c8494;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.12), inset 0 -2px 5px rgba(0,0,0,0.28);
}
.sticker:hover { transform: scale(1.06); z-index: 2; box-shadow: 0 0 0 2px rgba(124,156,255,0.6); }
.sticker[data-color="white"] { background: var(--c-white); }
.sticker[data-color="yellow"] { background: var(--c-yellow); }
.sticker[data-color="green"] { background: var(--c-green); }
.sticker[data-color="blue"] { background: var(--c-blue); }
.sticker[data-color="red"] { background: var(--c-red); }
.sticker[data-color="orange"] { background: var(--c-orange); }

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row .btn { flex: 1; }

/* ---- Color Cube start button + coloring gate ---- */
.btn--colorcube {
  width: 100%; margin: 6px 0 4px; padding: 14px 18px; font-size: 1rem; font-weight: 700;
  letter-spacing: .01em;
}
.start-hint { text-align: center; }
/* Hide the coloring tools until the user taps "Color Cube". */
#coloring-ui[hidden] { display: none; }
.is-coloring #btn-color-cube { display: none; }
#btn-start-over { width: 100%; margin-top: 2px; }

/* depleted palette swatch (0 of that colour left) */
.swatch.is-depleted { opacity: 0.32; filter: grayscale(0.4); }
.swatch.is-depleted::after {
  content: ""; position: absolute; inset: 0; border-radius: 10px;
  background: repeating-linear-gradient(45deg, transparent 0 6px, rgba(0,0,0,0.35) 6px 8px);
}

/* ---- colour inventory panel ---- */
.inventory {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin: 12px 0 4px; padding: 12px;
  background: rgba(0,0,0,0.22); border: 1px solid var(--stroke); border-radius: var(--r-md);
}
.inventory__title {
  grid-column: 1 / -1; font-size: 0.72rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--text-dim); margin-bottom: 2px;
}
.inv-item {
  display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 10px;
  background: rgba(255,255,255,0.03); border: 1px solid var(--stroke);
  transition: opacity .2s, border-color .2s;
}
.inv-item.is-empty { opacity: 0.5; }
.inv-item.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(124,156,255,0.25); }
.inv-swatch {
  width: 20px; height: 20px; border-radius: 6px; flex: none;
  border: 1px solid rgba(0,0,0,0.4); box-shadow: inset 0 1px 2px rgba(255,255,255,0.25);
}
.inv-swatch[data-color="white"] { background: var(--c-white); }
.inv-swatch[data-color="yellow"] { background: var(--c-yellow); }
.inv-swatch[data-color="green"] { background: var(--c-green); }
.inv-swatch[data-color="blue"] { background: var(--c-blue); }
.inv-swatch[data-color="red"] { background: var(--c-red); }
.inv-swatch[data-color="orange"] { background: var(--c-orange); }
.inv-name { font-size: 0.82rem; color: var(--text); flex: 1; }
.inv-count { font-family: var(--mono); font-size: 0.82rem; font-weight: 600; color: var(--text-dim); }
.inv-item.is-empty .inv-count { color: var(--c-red); }

/* validation */
.validation { font-size: 0.85rem; display: flex; flex-direction: column; gap: 6px; }
.validation:empty { display: none; }
.validation .v-line { display: flex; gap: 8px; align-items: flex-start; padding: 9px 12px; border-radius: 10px; }
.validation .v-ok { background: rgba(52,211,153,0.12); border: 1px solid rgba(52,211,153,0.3); color: #9af3cf; }
.validation .v-err { background: rgba(255,107,107,0.1); border: 1px solid rgba(255,107,107,0.28); color: #ffc2c2; }
.validation .v-warn { background: rgba(255,210,63,0.1); border: 1px solid rgba(255,210,63,0.28); color: #ffe79a; }

/* fields */
.advanced-input { border: 1px solid var(--stroke); border-radius: var(--r-md); padding: 4px 14px; background: rgba(0,0,0,0.16); }
.advanced-input summary { cursor: pointer; padding: 10px 0; font-weight: 600; font-size: 0.88rem; color: var(--text-dim); }
.field { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 12px; }
.field > span { font-size: 0.8rem; color: var(--text-dim); }
.field__row { display: flex; gap: 8px; }
input[type="text"] {
  flex: 1; min-width: 0; padding: 11px 13px; border-radius: 11px;
  background: rgba(0,0,0,0.3); border: 1px solid var(--stroke-strong); color: var(--text);
  font-family: var(--mono); font-size: 0.88rem; transition: border-color .2s, box-shadow .2s;
}
input[type="text"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,156,255,0.25); }

/* solver controls */
.solver-controls { margin-top: 4px; }
.mode-select { display: flex; gap: 6px; background: rgba(0,0,0,0.25); padding: 5px; border-radius: 12px; }
.mode-select label {
  flex: 1; text-align: center; padding: 9px 6px; border-radius: 9px; cursor: pointer;
  font-size: 0.84rem; font-weight: 600; color: var(--text-dim); transition: background .2s, color .2s;
}
.mode-select input { position: absolute; opacity: 0; pointer-events: none; }
.mode-select label:has(input:checked) { background: var(--glass-2); color: var(--text); }
/* Visible keyboard focus for the otherwise-hidden mode radios. */
.mode-select label:has(input:focus-visible) { box-shadow: 0 0 0 2px var(--accent); color: var(--text); }
.mode-hint { margin-top: 8px; }

kbd {
  font-family: var(--mono); font-size: 0.74em; padding: 1px 6px; border-radius: 6px;
  background: rgba(255,255,255,0.08); border: 1px solid var(--stroke-strong);
  color: var(--text); box-shadow: inset 0 -1px 0 rgba(0,0,0,0.3); white-space: nowrap;
}
.kbd-hint { text-align: center; }

/* saves */
.saves__title { font-size: 0.85rem; color: var(--text-dim); margin-top: 6px; }
.saves { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 280px; overflow-y: auto; }
.saves__item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 11px; background: rgba(0,0,0,0.2); border: 1px solid var(--stroke); }
.saves__item .name { flex: 1; min-width: 0; font-weight: 600; font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saves__item .meta { font-size: 0.72rem; color: var(--text-faint); }
.saves__empty { font-size: 0.82rem; color: var(--text-faint); padding: 8px 2px; }

/* ---- dashboard ---------------------------------------------------------- */
.dashboard { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.stat { padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.stat__label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); }
.stat__value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- playback card ------------------------------------------------------ */
.playback-card { padding: 18px clamp(16px, 2vw, 24px); display: flex; flex-direction: column; gap: 16px; }
.timeline {
  display: flex; gap: 7px; overflow-x: auto; padding: 6px 2px 12px; scroll-behavior: smooth;
  scrollbar-width: thin;
}
.timeline:empty::before { content: "Your solution moves will appear here."; color: var(--text-faint); font-size: 0.85rem; padding: 6px; }
.tl-move {
  flex: 0 0 auto; min-width: 46px; padding: 9px 10px; border-radius: 11px; cursor: pointer;
  background: rgba(255,255,255,0.04); border: 1px solid var(--stroke);
  font-family: var(--mono); font-weight: 700; text-align: center; color: var(--text-dim);
  transition: background .15s, color .15s, transform .15s var(--ease), border-color .15s;
  position: relative;
}
.tl-move .tl-idx { display: block; font-size: 0.6rem; color: var(--text-faint); font-family: var(--font); font-weight: 600; }
.tl-move:hover { transform: translateY(-2px); border-color: var(--stroke-strong); color: var(--text); }
.tl-move.is-done { color: var(--text); background: rgba(124,156,255,0.1); }
.tl-move.is-current { color: #05060a; background: var(--accent-grad); border-color: transparent; box-shadow: 0 8px 20px -8px rgba(124,156,255,0.7); }
.tl-move[data-stage-start="true"] { margin-left: 14px; }
.tl-move[data-stage-start="true"]::before {
  content: ""; position: absolute; left: -9px; top: 10%; height: 80%; width: 2px; border-radius: 2px;
  background: var(--accent-2); opacity: .7;
}

.playback { display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.playback__btns { display: flex; align-items: center; gap: 10px; }
.speed { display: flex; align-items: center; gap: 10px; font-size: 0.82rem; color: var(--text-dim); }
.speed input[type="range"] { width: clamp(120px, 18vw, 200px); accent-color: var(--accent); }
.speed output { font-family: var(--mono); font-weight: 700; color: var(--text); min-width: 3ch; }

/* learn panel */
.learn { border-top: 1px solid var(--stroke); padding-top: 14px; }
.learn__head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.learn__head h2 { font-size: 1.05rem; }
.learn__stage { font-size: 0.72rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: rgba(89,230,195,0.14); color: var(--accent-2); border: 1px solid rgba(89,230,195,0.3); }
.learn__stage:empty { display: none; }
.learn__what { color: var(--text); font-size: 0.95rem; }
.learn__cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 12px; }
.learn__cols h4 { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); margin-bottom: 4px; }
.learn__cols p { font-size: 0.86rem; color: var(--text-dim); }

/* ---- footer ------------------------------------------------------------- */
.app-footer { text-align: center; padding: 10px 20px 30px; color: var(--text-faint); font-size: 0.78rem; }

/* ---- toasts ------------------------------------------------------------- */
.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 10px; z-index: 200; width: min(420px, calc(100vw - 32px)); }
.toast {
  padding: 13px 16px; border-radius: 13px; font-size: 0.88rem; font-weight: 550;
  background: rgba(20,24,38,0.92); border: 1px solid var(--stroke-strong); color: var(--text);
  backdrop-filter: blur(16px); box-shadow: var(--shadow);
  animation: toast-in .35s var(--ease); display: flex; gap: 10px; align-items: flex-start;
}
.toast--error { border-color: rgba(255,107,107,0.5); }
.toast--success { border-color: rgba(52,211,153,0.5); }
.toast--info { border-color: rgba(124,156,255,0.5); }
.toast.is-leaving { animation: toast-out .3s var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px) scale(.97); } }

/* ---- loader ------------------------------------------------------------- */
.loader {
  position: fixed; inset: 0; z-index: 500; display: grid; place-content: center; justify-items: center; gap: 22px;
  background: var(--bg-0); transition: opacity .5s var(--ease), visibility .5s;
}
.loader.is-hidden { opacity: 0; visibility: hidden; }
.loader__cube { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; width: 64px; height: 64px; animation: spin 2.4s var(--ease) infinite; }
.loader__cube span { border-radius: 8px; animation: pulse 1.4s ease-in-out infinite; }
.loader__cube span:nth-child(1) { background: var(--c-green); }
.loader__cube span:nth-child(2) { background: var(--c-yellow); animation-delay: .15s; }
.loader__cube span:nth-child(3) { background: var(--c-red); animation-delay: .3s; }
.loader__cube span:nth-child(4) { background: var(--c-blue); animation-delay: .45s; }
.loader__text { color: var(--text-dim); font-size: 0.92rem; }
@keyframes spin { 50% { transform: rotate(180deg); } 100% { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .4; transform: scale(.85); } }

/* ---- responsive --------------------------------------------------------- */
/* Desktop: pin the cube so it stays in view while you scrub the playback
   controls, even when expanding the colouring tools makes the control column
   (and therefore the page) much taller than the viewport. */
@media (min-width: 1081px) {
  .viewer-card {
    position: sticky;
    top: 12px;
    align-self: start;
    z-index: 20;
  }
}
@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas: "viewer" "controls" "dash" "playback";
  }
  .dashboard { grid-template-columns: repeat(2, 1fr); }
  /* Keep the 3D cube pinned to the top while scrolling the controls, so you can
     reach the Solve button (and the net) and still watch the cube solve. */
  .viewer-card {
    position: sticky;
    top: 8px;
    z-index: 20;
    box-shadow: 0 14px 30px -18px rgba(0,0,0,0.8);
  }
  .viewer { height: clamp(260px, 38vh, 420px); }
}
@media (max-width: 620px) {
  .app-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .dashboard { grid-template-columns: repeat(2, 1fr); }
  .learn__cols { grid-template-columns: 1fr; }
  .playback { justify-content: center; }
  .move-readout__cur { font-size: 1.25rem; }
  /* Use the full width on phones so the net stickers are as tappable as possible
     (the 4-face-wide cross is inherently tight; the 3D cube is the larger target). */
  .net { max-width: min(94vw, 360px); }
  .swatch { width: 48px; height: 48px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ===================================================================
   Auth gate (signup / login overlay) + account chip
   Added for the signup-before-cube flow.
   =================================================================== */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(4, 6, 12, 0.82);
  backdrop-filter: blur(14px) saturate(120%);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  animation: auth-fade 0.25s var(--ease);
}
.auth-gate.is-leaving { opacity: 0; transition: opacity 0.2s var(--ease); }
@keyframes auth-fade { from { opacity: 0; } to { opacity: 1; } }

.auth-card {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, rgba(24, 28, 44, 0.92), rgba(14, 17, 27, 0.92));
  border: 1px solid var(--stroke-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 1.6rem 1.5rem 1.4rem;
  animation: auth-rise 0.3s var(--ease);
}
@keyframes auth-rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

.auth-brand { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.1rem; }
.auth-brand img { border-radius: 9px; }
.auth-brand h2 { font-size: 1.12rem; margin: 0; line-height: 1.2; }
.auth-brand p { margin: 0.15rem 0 0; color: var(--text-dim); font-size: 0.86rem; }

.auth-tabs {
  display: flex; gap: 0.35rem; padding: 0.25rem;
  background: rgba(0, 0, 0, 0.25); border-radius: var(--r-sm);
  margin-bottom: 1rem;
}
.auth-tab {
  flex: 1; cursor: pointer; border: none; background: transparent;
  color: var(--text-dim); font: inherit; font-weight: 600; font-size: 0.9rem;
  padding: 0.5rem; border-radius: 8px; transition: all 0.18s var(--ease);
}
.auth-tab.is-active { background: var(--glass-2); color: var(--text); box-shadow: 0 1px 0 var(--stroke); }

.auth-google {
  display: flex; align-items: center; justify-content: center; gap: 0.6rem;
  width: 100%; cursor: pointer; font: inherit; font-weight: 600; font-size: 0.92rem;
  padding: 0.7rem; border-radius: var(--r-sm);
  background: #fff; color: #1f2330; border: 1px solid transparent;
}
.auth-google[disabled] { opacity: 0.55; cursor: not-allowed; }
.auth-soon {
  font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em;
  background: #e7e9f0; color: #6b7280; padding: 0.1rem 0.4rem; border-radius: 999px;
}
.auth-or { display: flex; align-items: center; gap: 0.7rem; margin: 0.95rem 0 0.6rem; color: var(--text-faint); font-size: 0.78rem; }
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: var(--stroke); }

.auth-err { color: var(--bad); font-size: 0.84rem; min-height: 1.1em; margin-bottom: 0.5rem; }

.auth-field { display: block; margin-bottom: 0.7rem; }
.auth-field > span { display: block; font-size: 0.8rem; color: var(--text-dim); margin-bottom: 0.3rem; }
.auth-field input {
  width: 100%; box-sizing: border-box; font: inherit; font-size: 0.98rem;
  padding: 0.65rem 0.75rem; border-radius: var(--r-sm);
  border: 1px solid var(--stroke-strong); background: rgba(0, 0, 0, 0.28); color: var(--text);
  transition: border-color 0.15s var(--ease);
}
.auth-field input:focus { outline: none; border-color: var(--accent); }

.auth-consent {
  display: flex; gap: 0.55rem; align-items: flex-start;
  font-size: 0.84rem; color: var(--text-dim); margin: 0.5rem 0 0.9rem;
}
.auth-consent input { margin-top: 0.18rem; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.auth-consent a { color: var(--accent); }

.auth-submit {
  width: 100%; cursor: pointer; font: inherit; font-weight: 700; font-size: 0.98rem;
  padding: 0.75rem; border: none; border-radius: var(--r-sm);
  background: var(--accent-grad); color: #0b0e18;
}
.auth-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.auth-foot { margin: 1rem 0 0; font-size: 0.76rem; color: var(--text-faint); text-align: center; line-height: 1.45; }

/* Account chip in the header */
.account-chip {
  display: inline-flex; align-items: center; gap: 0.55rem;
  padding: 0.3rem 0.3rem 0.3rem 0.7rem; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--stroke); font-size: 0.82rem;
}
.account-chip__name { color: var(--text-dim); max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-chip__logout {
  cursor: pointer; font: inherit; font-size: 0.78rem; font-weight: 600;
  padding: 0.3rem 0.7rem; border-radius: 999px;
  border: 1px solid var(--stroke-strong); background: transparent; color: var(--text);
}
.account-chip__logout:hover { background: var(--glass-2); }

.app-footer__legal { margin: 0.35rem 0 0; font-size: 0.8rem; }
.app-footer__legal a { color: var(--text-dim); }
.app-footer__legal a:hover { color: var(--accent); }

@media (max-width: 480px) {
  .auth-card { padding: 1.3rem 1.15rem; }
  .account-chip__name { max-width: 84px; }
}

/* closable auth gate (solve-time sign-up) */
.auth-card { position: relative; }
.auth-close {
  position: absolute; top: 12px; right: 14px;
  width: 30px; height: 30px; border: none; border-radius: 50%;
  background: rgba(255,255,255,0.08); color: var(--text-dim);
  font-size: 20px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.auth-close:hover { background: rgba(255,255,255,0.16); color: #fff; }

/* header nav links (About / Contact) */
.app-nav { display: flex; gap: 8px; flex-wrap: wrap; }
.app-nav a {
  color: var(--text-dim); text-decoration: none; font-size: 0.9rem; font-weight: 600;
  padding: 7px 15px; border: 1px solid var(--stroke); border-radius: 999px;
  transition: color .15s, border-color .15s, background .15s;
}
.app-nav a:hover { color: var(--text); border-color: var(--stroke-strong); background: var(--glass-2); }

/* header login / sign-up button */
.app-nav .auth-btn {
  font: inherit; cursor: pointer; color: #0a0c14; background: var(--accent);
  border: none; font-size: 0.88rem; font-weight: 700;
  padding: 7px 16px; border-radius: 999px; transition: filter .15s;
}
.app-nav .auth-btn:hover { filter: brightness(1.08); }
