/* ============================================================
   xCubes — сканер граней по фото (cubescan/scanner.js).
   Токены цвета/шрифтов — из static/ui/xc.css.
   ============================================================ */
html.xs-open, html.xs-open body { overflow: hidden; }

.xs {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center;
  background: rgba(3, 3, 8, .78);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  padding: 24px;
}
.xs[hidden] { display: none; }

.xs__panel {
  position: relative;
  width: min(760px, 100%); height: min(860px, calc(100dvh - 48px));
  display: grid; grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--surface, #0c0c14); color: var(--fg, #f4f4f8);
  border: 1px solid var(--line-2, rgba(255, 255, 255, .13)); border-radius: var(--r-lg, 28px);
  box-shadow: 0 40px 120px -20px rgba(0, 0, 0, .8), 0 0 0 1px rgba(123, 109, 255, .08);
  overflow: hidden;
}

/* ---- шапка ---- */
.xs__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 22px 24px 10px;
}
.xs__kicker { margin: 0 0 4px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-2, #a9a1ff); }
.xs__title { margin: 0; font-family: var(--f-display); font-weight: 600; font-size: 22px; line-height: 1.15; }
.xs__close {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line-2, rgba(255, 255, 255, .13)); background: var(--surface-2, #11111c);
  color: var(--fg, #fff); font-size: 24px; line-height: 1; cursor: pointer;
}
.xs__close:hover { background: var(--surface-3, #181826); }

/* ---- шаги ---- */
.xs__steps { list-style: none; margin: 0; padding: 4px 24px 14px; display: flex; gap: 8px; }
.xs__chip {
  position: relative; width: 44px; height: 44px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line-2, rgba(255, 255, 255, .13)); background: var(--surface-2, #11111c);
  display: grid; place-items: center; padding: 0;
  transition: border-color .2s, transform .2s;
}
.xs__chip i {
  width: 20px; height: 20px; border-radius: 6px; background: var(--c);
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, .25);
}
.xs__chip-n {
  position: absolute; right: -5px; top: -6px; min-width: 18px; height: 18px; border-radius: 9px;
  display: grid; place-items: center; font-size: 10px; font-weight: 700;
  background: var(--surface-3, #181826); color: var(--fg-2, #a7a7ba); border: 1px solid var(--line-2);
}
.xs__chip-even {
  width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-style: normal;
  font-size: 12px; font-weight: 700; background: var(--surface-3, #181826); color: var(--fg, #fff);
}
.xs__chip-even + .xs__chip-n:empty { display: none; }
.xs__chip.is-done .xs__chip-even + .xs__chip-n { display: grid; }
.xs__chip.is-on { border-color: var(--accent, #7b6dff); box-shadow: 0 0 0 3px rgba(123, 109, 255, .25); }
.xs__chip.is-done .xs__chip-n { background: var(--ok, #4ade80); color: #062b12; border-color: transparent; }
.xs__chip.is-done .xs__chip-n::before { content: "✓"; }
.xs__chip.is-done .xs__chip-n { font-size: 0; }
.xs__chip.is-done .xs__chip-n::before { font-size: 11px; }
/* грань можно не снимать (2×2 / 3×3) — пунктирная рамка */
.xs__chip.is-opt:not(.is-done):not(.is-on) { border-style: dashed; opacity: .75; }

/* подсказка «можно не снимать» / «снимите и эту» */
.xs__opt {
  display: grid; justify-items: center; gap: 10px; margin-top: 14px; padding: 12px 14px;
  border: 1px dashed var(--line-2, rgba(255, 255, 255, .13)); border-radius: 12px; text-align: center;
}
.xs__opt-t { margin: 0; font-size: 14px; line-height: 1.45; color: var(--fg-2, #a7a7ba); }
.xs__opt.is-need { border-style: solid; border-color: var(--warn, #ffc857); }
.xs__opt.is-need .xs__opt-t { color: var(--warn, #ffc857); }
.xs__opt [hidden] { display: none; }

/* ---- тело ---- */
.xs__body { min-height: 0; display: grid; padding: 0 24px 24px; }
.xs__capture, .xs__review, .xs__final { min-height: 0; display: grid; gap: 16px; }
.xs__capture[hidden], .xs__review[hidden], .xs__final[hidden] { display: none; }

.xs__capture { align-content: center; justify-items: center; text-align: center; }
.xs__how { display: grid; justify-items: center; gap: 10px; }
/* ---- модель кубика N×N (класс NCube в scanner.js) ---- */
.xs__cube {
  appearance: none; border: 0; padding: 0; background: none; cursor: pointer;
  --s: 122px; width: 210px; aspect-ratio: 1;
}
.xn { position: relative; perspective: 900px; -webkit-tap-highlight-color: transparent; }
.xn::before {
  content: ""; position: absolute; inset: 4%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(closest-side, rgba(88, 66, 255, .38), rgba(88, 66, 255, .1) 60%, transparent 76%);
}
.xn__scene {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0; transform-style: preserve-3d;
  transition: transform 1.15s cubic-bezier(.5, .05, .25, 1);
}
.xn__face {
  position: absolute; left: calc(var(--s) / -2); top: calc(var(--s) / -2);
  width: var(--s); height: var(--s); box-sizing: border-box;
  display: grid; grid-template-columns: repeat(var(--n), 1fr); grid-template-rows: repeat(var(--n), 1fr);
  gap: max(1px, calc(var(--s) * .04 / var(--n) * 2)); padding: calc(var(--s) * .035);
  background: #06060a; border-radius: 9%;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
}
.xn__face[data-f="F"] { transform: translateZ(calc(var(--s) / 2)); }
.xn__face[data-f="B"] { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
.xn__face[data-f="R"] { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.xn__face[data-f="L"] { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.xn__face[data-f="U"] { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
.xn__face[data-f="D"] { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }
/* простое «освещение»: верх светлее, низ темнее */
.xn__face::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: #000; opacity: 0; pointer-events: none; }
.xn__face[data-f="D"]::after { opacity: .36; }
.xn__face[data-f="B"]::after, .xn__face[data-f="L"]::after { opacity: .18; }
.xn__face[data-f="R"]::after { opacity: .1; }
.xn__st {
  display: block; min-width: 0; min-height: 0; border-radius: 16%;
  background: linear-gradient(145deg, rgba(255, 255, 255, .35), rgba(255, 255, 255, 0) 50%), var(--sc, #2c2c3e);
}
/* нечётный: центр грани, которая смотрит на нас, мигает */
.xn--odd .xn__face.is-on .xn__st:not(.xn__st--c) { filter: brightness(.62) saturate(.8); }
.xn--odd.xn--all .xn__st:not(.xn__st--c) { filter: brightness(.7) saturate(.85); }
.xn--odd.xn--all .xn__st--c,
.xn--odd .xn__face.is-on .xn__st--c {
  position: relative; z-index: 1;
  box-shadow: 0 0 0 max(2px, calc(var(--s) * .025)) #fff, 0 0 0 max(4px, calc(var(--s) * .05)) rgba(123, 109, 255, .9),
    0 0 calc(var(--s) * .16) calc(var(--s) * .04) rgba(169, 161, 255, .8);
  animation: xn-blink 1.1s ease-in-out infinite;
}
@keyframes xn-blink {
  50% { box-shadow: 0 0 0 max(2px, calc(var(--s) * .025)) rgba(255, 255, 255, .35), 0 0 0 max(4px, calc(var(--s) * .05)) rgba(123, 109, 255, .25), 0 0 0 0 transparent; }
}
/* чётный: нейтральные грани с номерами снимков, текущая — подсвечена */
.xn--even .xn__st { --sc: #2c2c42; }
.xn--even .xn__face.is-on .xn__st { --sc: #5b4fd6; }
.xn__num {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 1;
  font: 700 calc(var(--s) * .42)/1 var(--f-display, system-ui); color: rgba(255, 255, 255, .9);
  text-shadow: 0 2px 8px rgba(0, 0, 0, .55);
}
@media (prefers-reduced-motion: reduce) { .xn__scene { transition: none; } .xn--odd .xn__face.is-on .xn__st--c { animation: none; } }
.xs__hint { margin: 0; max-width: 460px; font-size: 16px; line-height: 1.45; color: var(--fg, #fff); }
.xs__btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.xs__btns .btn { cursor: pointer; }
.xs__shot svg { margin-right: 8px; flex: none; }
.xs__tips {
  margin: 4px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; max-width: 460px;
  font-size: 13px; color: var(--fg-2, #a7a7ba); text-align: left;
}
.xs__tips li { padding-left: 18px; position: relative; }
.xs__tips li::before { content: ""; position: absolute; left: 4px; top: .6em; width: 5px; height: 5px; border-radius: 50%; background: var(--accent, #7b6dff); }

.xs__review { grid-template-rows: minmax(0, 1fr) auto auto; }
.xs__stage {
  position: relative; min-height: 220px; border-radius: var(--r, 20px); overflow: hidden;
  background: #000; border: 1px solid var(--line, rgba(255, 255, 255, .07));
}
.xs__canvas { position: absolute; inset: 0; display: block; touch-action: none; cursor: crosshair; }
.xs__loupe {
  position: absolute; width: 110px; height: 110px; border-radius: 50%; pointer-events: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .6);
}
.xs__loupe[hidden] { display: none; }
.xs__busy {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px;
  background: rgba(5, 5, 10, .55); font-weight: 600;
}
.xs__busy[hidden] { display: none; }
.xs__status { margin: 0; font-size: 14px; line-height: 1.4; color: var(--fg-2, #a7a7ba); min-height: 20px; text-align: center; }
.xs__status.is-ok { color: var(--ok, #4ade80); }
.xs__status.is-warn { color: var(--warn, #ffc857); }

.xs__final { place-content: center; justify-items: center; text-align: center; font-size: 16px; }

.xs__spin {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .18); border-top-color: var(--accent-2, #a9a1ff);
  animation: xs-spin .8s linear infinite;
}
.xs__spin--lg { width: 44px; height: 44px; border-width: 4px; }
@keyframes xs-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .xs__spin { animation-duration: 2.4s; } }

/* ---- телефон: на весь экран ---- */
@media (max-width: 640px) {
  .xs { padding: 0; }
  .xs__panel { width: 100%; height: 100dvh; border-radius: 0; border: 0; }
  .xs__head { padding: 16px 16px 8px; }
  .xs__title { font-size: 19px; }
  .xs__steps { padding: 2px 16px 12px; gap: 6px; }
  .xs__chip { width: 40px; height: 40px; }
  .xs__body { padding: 0 16px calc(16px + env(safe-area-inset-bottom)); }
  .xs__cube { width: 176px; --s: 100px; }
  .xs__hint { font-size: 15px; }
  .xs__btns .btn { flex: 1 1 140px; }
}

/* ---- та же модель на странице ручного ввода ---- */
.orient__cube.xn { --s: 54px; width: 96px; height: 96px; padding: 0; border: 0; background: none; }
.fw__cube.xn { --s: 92px; width: 168px; aspect-ratio: 1; padding: 0; border: 0; background: none; cursor: pointer; }
.fw__tab i.fw__tab-even { background: var(--surface-3, #181826); color: var(--fg, #fff); font-style: normal; }
.fw__tab i.fw__tab-odd { position: relative; }
.fw__tab:not(.is-done) i.fw__tab-odd::after, .fw__tab.is-on i.fw__tab-odd::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 30%; height: 30%; transform: translate(-50%, -50%);
  border-radius: 3px; box-shadow: 0 0 0 1.5px #fff; pointer-events: none;
}
@media (max-width: 640px) {
  .orient__cube.xn { --s: 38px; width: 68px; height: 68px; }
  .fw__cube.xn { --s: 54px; width: 96px; }
}
.swatch--num { display: inline-grid; place-items: center; background: var(--surface-3, #181826); color: var(--fg, #fff); font: 700 11px var(--f-mono); }

/* Письмо справа налево (арабский): подсказки — по правому краю. */
[dir="rtl"] .xs__tips { text-align: right; }
[dir="rtl"] .xs__tips li { padding-left: 0; padding-right: 18px; }
[dir="rtl"] .xs__tips li::before { left: auto; right: 4px; }
[dir="rtl"] .xs__shot svg { margin-right: 0; margin-left: 8px; }
