:root {
  --bg: #07070a;
  --panel: #111118;
  --panel2: #181822;
  --line: #2a2a38;
  --text: #ecebf3;
  --muted: #9a98ad;
  --accent: #a78bfa;
  --accent2: #7c6cf0;
  --ring: #4a4a5c;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, sans-serif; }
button, input { font: inherit; color: inherit; }

header { padding: 18px 24px 6px; text-align: center; }
h1 { font: 600 30px/1.1 Lora, Georgia, serif; margin: 0; letter-spacing: .2px; }
h1 .accent { color: var(--accent); }
.sub { color: var(--muted); margin: 6px 0 0; }

main { display: grid; grid-template-columns: 320px 1fr; gap: 18px; padding: 14px 18px 22px; max-width: 1600px; margin: 0 auto; }

.panel { display: flex; flex-direction: column; gap: 12px; }
.panel section { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.num { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--accent2); color: #fff; font-size: 11px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.row > button:last-child:not(:first-child) { flex: 0 0 auto; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; cursor: pointer; transition: background .15s, border-color .15s, transform .1s; }
button:hover { border-color: #3d3d52; background: #20202c; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; font-weight: 600; }
button.primary:hover { background: #8b7cf6; }
button.big { width: 100%; padding: 11px; font-size: 15px; margin-top: 10px; }
input { background: #0b0b11; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; width: 100%; min-width: 0; }
input:focus { outline: 2px solid var(--accent2); outline-offset: -1px; }
.field { display: block; margin-top: 10px; }
.field > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
input[type=range] { padding: 0; accent-color: var(--accent); }
.file-pick { display: flex; align-items: center; gap: 10px; min-width: 0; }
.file-btn { position: relative; flex: none; background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; cursor: pointer; font-size: 13px; transition: background .15s, border-color .15s; }
.file-btn:hover { border-color: var(--accent); background: #20202c; }
.file-btn:focus-within { outline: 2px solid var(--accent2); outline-offset: -1px; }
.file-btn input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; padding: 0; border: 0; }
.file-name { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
#scramble { font-family: var(--mono); font-size: 12px; }
.note { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.status { color: var(--muted); font-size: 12px; margin: 8px 0 0; min-height: 1em; }
.status.err { color: #f87171; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 1 auto; padding: 6px 10px; font-size: 13px; }
.seg button.on { background: #2a2346; border-color: var(--accent); color: #fff; }
#skinExtra:not(:empty) { margin-top: 10px; }
#skinExtra .words { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
#skinExtra .words input { padding: 6px 8px; font-size: 12px; text-align: center; }

.methods { display: flex; flex-direction: column; gap: 6px; }
.method { text-align: left; padding: 9px 11px; }
.method b { display: block; font-weight: 600; }
.method small { color: var(--muted); font-size: 12px; }
.method.on { background: #211c38; border-color: var(--accent); }

.help p { color: var(--muted); font-size: 12px; margin: 0; }
kbd { font-family: var(--mono); font-size: 11px; background: #22222e; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 4px; color: var(--text); }

.stage { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.views { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.view3d, .diagram-wrap { position: relative; background: radial-gradient(circle at 50% 40%, #12121b, #07070a 70%); border: 1px solid var(--line); border-radius: 16px; aspect-ratio: 1 / 1; overflow: hidden; }
.view3d canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
.move-badge { position: absolute; right: 18px; top: 14px; text-align: center; pointer-events: none; }
.move-now { font: 600 56px/1 Lora, Georgia, serif; color: var(--accent); min-width: 70px; }
.move-count { font: 500 18px Lora, Georgia, serif; color: var(--muted); margin-top: 6px; }

.diagram { width: 100%; height: 100%; display: block; }
.ring { fill: none; stroke: var(--ring); stroke-width: 3; transition: stroke .2s; }
.ring.hover { stroke: #8a88a6; }
.ring.active { stroke: transparent; }
.ring-hit { fill: none; stroke: transparent; stroke-width: 16; cursor: pointer; pointer-events: stroke; }
.hi-seg { fill: none; stroke-width: 7; stroke-linecap: butt; }
.hi-flow { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 3 14; stroke-linecap: round; opacity: .9; }
.hi-flow.fwd { animation: flow 0.9s linear infinite; }
.hi-flow.back { animation: flow-back 0.9s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -17; } }
@keyframes flow-back { to { stroke-dashoffset: 17; } }
.chev { stroke: var(--accent); stroke-width: 3; fill: none; }
.face-arc { fill: none; stroke: var(--accent); stroke-width: 3; stroke-dasharray: 6 5; opacity: .9; }
.dot { stroke: #0006; stroke-width: 1.5; }
.dot.center { stroke: #fff8; stroke-width: 2; }
.tick { stroke: #000a; stroke-width: 2.5; stroke-linecap: round; pointer-events: none; }
.focus { fill: none; stroke: #fff; stroke-width: 2.5; opacity: .85; filter: url(#glow); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.ring-label text { fill: #fff; font: 700 18px var(--mono); }
.ring-label-bg { fill: #000c; stroke: var(--accent); stroke-width: 1.5; }

.explain { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; min-height: 74px; }
.stage-title { font-weight: 600; font-size: 16px; }
.stage-hint { color: var(--muted); margin-top: 3px; }

.player { display: flex; justify-content: center; gap: 8px; }
.player button { min-width: 52px; font-size: 16px; }
.player .ic { width: 20px; height: 20px; fill: currentColor; display: block; margin: 0 auto; }

.timeline { font-family: var(--mono); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 10px 14px; min-height: 56px; max-height: 260px; overflow: auto; }
.timeline:empty::before { content: 'Тут з’явиться розв’язок'; color: var(--muted); font-family: Inter, sans-serif; }
.tl-step { display: flex; flex-direction: column; gap: 4px; padding: 6px 8px; border-radius: 9px; border: 1px solid transparent; }
.tl-step.current { border-color: #3a3357; background: #16131f; }
.tl-step .tl-title { font: 500 11px Inter, sans-serif; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tl-moves { display: flex; flex-wrap: wrap; gap: 2px 7px; font-size: 16px; }
.mv { cursor: pointer; color: #e7e5f2; border-radius: 4px; padding: 0 2px; }
.mv.done { color: #5d5b70; }
.mv.next { color: #fff; background: var(--accent2); }
.mv:hover { outline: 1px solid var(--accent); }

@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; }
  .panel { order: 2; }
}
@media (max-width: 720px) {
  main { padding: 10px 12px 18px; }
  .views { grid-template-columns: 1fr; }
  h1 { font-size: 24px; }
  .move-now { font-size: 42px; }
}

/* ---------- сенсорные экраны и телефоны ---------- */
button, .diagram, .timeline { touch-action: manipulation; } /* без двойного тап-зума при быстрых нажатиях */
.diagram { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.p-move { display: none; }
.player button.wide { min-width: 120px; font-size: 15px; }
.help-touch { display: none; }

@media (pointer: coarse) {
  .help-touch { display: block; }
  .help-keys { display: none; }
  button { min-height: 44px; }
  .ring-hit { stroke-width: 44; }
  .mv { padding: 2px 5px; }
}

/* нижняя панель управления всегда под пальцем */
@media (max-width: 720px), (max-height: 500px) {
  .player {
    position: sticky; bottom: 0; z-index: 5;
    margin: 0 -12px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    background: var(--bg);
    border-top: 1px solid var(--line); gap: 6px;
  }
  .player button { min-width: 0; flex: 1; padding: 8px 0; }
  .player button.wide { flex: 3; }
  .p-move { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 58px; line-height: 1.15; }
  .p-move:empty { display: none; }
  .p-move b { font: 600 22px Lora, Georgia, serif; color: var(--accent); }
  .p-move span { font-size: 11px; color: var(--muted); }
}

@media (max-width: 720px) {
  .view3d { aspect-ratio: 4 / 3; }
  .move-badge { display: none; } /* ход и счётчик показаны в нижней панели */
  input, #scramble, #skinExtra .words input { font-size: 16px; } /* iOS не приближает страницу при фокусе */
  .timeline { max-height: 180px; }
  .explain { min-height: 0; }
}
