/* ===== Токены: как на marmedia1.ru ===== */
:root {
  --bg: #ffffff; --bg2: #f5f5f7; --card: #f8f8fa; --ink: #2b2b2b; --body: #3a3a3a; --mute: #6b6b6b;
  --line: rgba(0,0,0,.08); --accent: #0088CC; --accent-2: #0077B3; --ok: #1f9d55; --bad: #e5484d;
  --plastic: #1c1c1e; --glass: rgba(255,255,255,.86); --icon-off: #ededf0; --icon-line: #d6d6db;
  --sab: env(safe-area-inset-bottom, 0px); --sat: env(safe-area-inset-top, 0px);
}
html.dark {
  --bg: #0a0a0a; --bg2: #1a1a1a; --card: #1c1c1e; --ink: #f5f5f7; --body: #d0d0d0; --mute: #98989d;
  --line: rgba(255,255,255,.1); --plastic: #000; --glass: rgba(16,16,16,.86); --icon-off: #2a2a2e; --icon-line: #3a3a40;
}
/* Палитры кубика */
.theme-classic { --cU: #F7F7F2; --cR: #E0323A; --cF: #20A64B; --cD: #F6D21E; --cL: #F7811E; --cB: #1F66D1; }
.theme-pastel  { --cU: #FFFAF1; --cR: #F79AC0; --cF: #93D79A; --cD: #F7DC6F; --cL: #F9AC66; --cB: #8BC3F0; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); -webkit-text-size-adjust: 100%;
  font: 500 15px/1.45 Manrope, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
body.noscroll, body.ed-open { overflow: hidden; }
button, label.btn, a.btn { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; }
.grow { flex: 1; }
.muted { color: var(--mute); font-size: 13px; }
.center { text-align: center; }
.small-note { font-size: 12.5px; margin: 8px 0 0; line-height: 1.4; }
b { font-weight: 700; }

/* ===== Каркас ===== */
.app { max-width: 600px; margin: 0 auto; padding: 0 16px; min-height: 100vh; }
.app.fixed { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; }
.main { display: block; }
.app.fixed .main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

.top { height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: none; }
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-weight: 800; font-size: 15px; letter-spacing: -.01em; }
.brand img { width: 28px; height: 28px; border-radius: 8px; display: block; }
.seg { display: flex; background: var(--bg2); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; min-height: 36px; padding: 0 12px; border-radius: 999px; font-weight: 700; font-size: 13px; color: var(--mute); white-space: nowrap; }
.seg button.on { background: var(--bg); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg button:disabled { opacity: .45; cursor: default; }
@media (max-width: 380px) { .brand span { display: none; } .seg button { padding: 0 9px; font-size: 12.5px; } }

/* ===== Кнопки ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 18px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--ink); border-radius: 999px; font-weight: 600; font-size: 15px; line-height: 1.2; text-decoration: none; white-space: nowrap; }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 13.5px; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.grow { flex: 1; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes sp { to { transform: rotate(360deg); } }

.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); vertical-align: -2px; margin-right: 3px; }
.cU { background: var(--cU); } .cR { background: var(--cR); } .cF { background: var(--cF); }
.cD { background: var(--cD); } .cL { background: var(--cL); } .cB { background: var(--cB); }

/* ===== Шаг 1: фото ===== */
.scr-photo { padding-bottom: calc(92px + var(--sab)); }
h1 { font-size: 24px; line-height: 1.15; letter-spacing: -.02em; margin: 10px 0 8px; font-weight: 800; }
.lead { font-size: 14.5px; color: var(--body); margin: 0 0 6px; }
.pslot { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 14px; margin-top: 12px; transition: box-shadow .3s; }
.pslot.pulse { box-shadow: 0 0 0 3px var(--accent); }
.pslot-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.pslot-title { font-weight: 800; font-size: 16px; }
.pslot-txt { font-size: 13.5px; color: var(--body); }
.schema { width: 62px; height: 64px; flex: none; }
.schema polygon { stroke: rgba(0,0,0,.25); stroke-width: .6; }
.schema .sch-off { fill: var(--icon-off); }
.schema .cU { fill: var(--cU); } .schema .cR { fill: var(--cR); } .schema .cF { fill: var(--cF); }
.schema .cD { fill: var(--cD); } .schema .cL { fill: var(--cL); } .schema .cB { fill: var(--cB); }
.pick-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pick-row .btn { min-height: 48px; }
.loaded { display: flex; gap: 12px; align-items: flex-start; }
.thumb { flex: none; border-radius: 12px; background: #ddd; display: block; }
.loaded-info { flex: 1; min-width: 0; }
.loaded-ok { font-weight: 700; color: var(--ok); font-size: 14px; }
.loaded-info .muted { margin-top: 2px; font-size: 12.5px; line-height: 1.35; }
.loaded-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.barPhoto { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 10px 16px calc(10px + var(--sab)); }
.barPhoto-in { max-width: 568px; margin: 0 auto; display: flex; }
.barPhoto .btn { min-height: 50px; font-size: 16px; }

.about { margin-top: 32px; color: var(--body); font-size: 14.5px; }
.about h2 { font-size: 18px; margin: 20px 0 8px; color: var(--ink); letter-spacing: -.01em; }
.about ol { padding-left: 20px; margin: 0; }
.about li { margin-bottom: 8px; }
.about p { margin: 0 0 8px; }
.cta { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 16px; margin-top: 20px; }
.cta-t { font-weight: 800; font-size: 16px; color: var(--ink); margin-bottom: 4px; }
.foot { font-size: 12px; color: var(--mute); margin-top: 18px; text-align: center; }

/* ===== Сцена (шаги 2 и 3) ===== */
.stage { position: relative; flex: 1 1 auto; min-height: 150px; display: flex; flex-direction: column; margin: 0 -16px; }
.hold { font-size: 12.5px; color: var(--mute); margin: 2px 16px 0; text-align: center; line-height: 1.4; flex: none; }
.hold b { color: var(--ink); font-weight: 700; }
.scene { position: relative; flex: 1 1 auto; min-height: 0; perspective: 1000px; touch-action: none;
  -webkit-user-select: none; user-select: none; cursor: grab; overflow: hidden; }
.scene:active { cursor: grabbing; }
.c3-cube { position: absolute; left: 50%; top: calc(50% - 14px); width: 0; height: 0; transform-style: preserve-3d; will-change: transform; }
.c3-cube.anim { transition: transform .7s cubic-bezier(.3,.1,.2,1); }
.c3-piv, .c3-cb { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-style: preserve-3d; }
.c3-face { position: absolute; width: var(--S); height: var(--S); left: calc(var(--S) / -2); top: calc(var(--S) / -2);
  background: var(--plastic); border-radius: 5px; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.c3-face > i { position: absolute; inset: 2.5px; border-radius: 22%; transition: box-shadow .2s; }
.c3-face.in > i { display: none; }
.c3-face.dim > i::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: rgba(120,120,130,.62); }
.c3-face.unsure > i { box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 5.5px var(--accent); }
.c3-face.unsure2 > i { animation: doubt 1.1s ease-in-out infinite; }
.nf i.unsure2 { animation: doubt2 1.1s ease-in-out infinite; }
@keyframes doubt { 0%, 100% { box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 5.5px var(--accent); } 50% { box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 9px var(--accent); } }
@keyframes doubt2 { 0%, 100% { box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px var(--accent); } 50% { box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 7px var(--accent); } }
@media (prefers-reduced-motion: reduce) { .c3-face.unsure2 > i, .nf i.unsure2 { animation: none; } }
.c3-face.flash > i { box-shadow: inset 0 0 0 3px #fff, inset 0 0 0 5.5px var(--ok); }
.c3-face.bad > i { box-shadow: inset 0 0 0 4px var(--bad); }
.editing .c3-face[data-i] { cursor: pointer; }
.hint3d { position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; font-size: 12px; color: var(--mute); pointer-events: none; transition: opacity .3s; white-space: nowrap; overflow: hidden; }
.viewbar { position: absolute; left: 0; right: 0; bottom: 8px; display: flex; justify-content: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.viewbar .btn { pointer-events: auto; background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); min-height: 36px; font-size: 12.5px; padding: 0 12px; }
.stage .hint3d { bottom: 50px; }
.stage.short .hint3d { display: none; }
.stage.short .hold { font-size: 12px; margin-top: 0; }

/* ===== Нижняя панель ===== */
.panel { flex: 0 0 auto; max-height: 62vh; max-height: 62dvh; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: var(--card); border: 1px solid var(--line); border-bottom: 0; border-radius: 20px 20px 0 0; margin: 0 -16px;
  padding: 12px 14px calc(12px + var(--sab)); }
.panel > * + * { margin-top: 10px; }
/* Главная кнопка панели всегда видна, даже если панель прокручивается на низком экране */
.actions { display: flex; gap: 8px; position: sticky; bottom: calc(-12px - var(--sab)); background: var(--card); padding: 8px 0 calc(12px + var(--sab)); margin-bottom: calc(-12px - var(--sab)); }
.actions .btn { min-height: 48px; }
.oneline { font-size: 12.5px; margin: 6px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
details.more summary { font-size: 13px; color: var(--mute); cursor: pointer; font-weight: 700; list-style: none; min-height: 36px; display: flex; align-items: center; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::before { content: "▸ "; }
details[open].more summary::before { content: "▾ "; }

/* --- цвета --- */
.status { font-size: 13.5px; padding: 8px 12px; border-radius: 12px; background: var(--bg2); line-height: 1.35; }
.status.ok { background: #e7f5ec; color: #1f6e40; }
.status.err { background: #fdecec; color: #9b2c2f; }
html.dark .status.ok { background: #143d26; color: #a9e4bf; }
html.dark .status.err { background: #4a1d1f; color: #f5b5b8; }
.status ul { margin: 4px 0 0; padding-left: 18px; }
.ring { display: inline-block; width: 14px; height: 14px; border-radius: 4px; box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px var(--accent); background: #ddd; vertical-align: -2px; margin-right: 6px; }
.palette { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 6px; }
.sw { display: flex; align-items: center; gap: 7px; min-height: 44px; border: 1.5px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 12px; padding: 0 8px; font-size: 13px; font-weight: 700; text-align: left; overflow: hidden; }
.sw .chip { width: 24px; height: 24px; border-radius: 7px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); flex: none; }
.sw .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sw .n { margin-left: auto; font-size: 12px; color: var(--mute); font-variant-numeric: tabular-nums; flex: none; }
.sw .n.badn { color: var(--bad); }
@media (max-width: 899px) { .palette:not(.compact) .sw .n:not(.badn) { display: none; } }   /* на телефоне счётчик только при ошибке — чтобы влезло название */
.sw.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.palette.compact { grid-template-columns: repeat(6, minmax(0,1fr)); }
.palette.compact .sw { flex-direction: column; gap: 3px; padding: 5px 0; min-height: 56px; justify-content: center; }
.palette.compact .nm { display: none; }
.palette.compact .n { margin: 0; }
.tools { justify-content: space-between; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--body); min-height: 40px; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

/* --- развёртка крупно --- */
.modal { position: fixed; inset: 0; z-index: 90; background: var(--bg); display: flex; flex-direction: column; }
.modal-top { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--sat)) 16px 10px; border-bottom: 1px solid var(--line); flex: none; }
.modal-top .muted { flex: 1; font-size: 12.5px; line-height: 1.3; }
.modal-top .btn { min-width: 40px; padding: 0; }
.modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px 16px; }
.modal-bottom { flex: none; border-top: 1px solid var(--line); padding: 10px 16px calc(10px + var(--sab)); display: flex; flex-direction: column; gap: 8px; }
.net { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; max-width: 640px; margin: 0 auto; }
@media (min-width: 560px) { .net { grid-template-columns: repeat(3, minmax(0,1fr)); } }
.nf-title { font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.nf-ctr { color: var(--mute); font-weight: 500; }
.nf { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--plastic); padding: 4px; border-radius: 12px; }
.nf i { aspect-ratio: 1; border-radius: 8px; display: block; cursor: pointer; }
.nf i.ctr { cursor: default; }
.nf i.bad { box-shadow: inset 0 0 0 3px var(--bad); }
.nf i.unsure { box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px var(--accent); }
.nf i.flash { box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px var(--ok); }

/* --- сборка --- */
.progress { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--mute); font-variant-numeric: tabular-nums; }
.bar { flex: 1; height: 6px; background: var(--bg2); border-radius: 9px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--ok); border-radius: 9px; transition: width .3s; }
.movecard { display: flex; gap: 12px; align-items: center; min-height: 84px; }
.icon { flex: none; width: 100px; height: 84px; }
.icon svg { width: 100%; height: 100%; display: block; }
.done-icon { font-size: 50px; text-align: center; line-height: 84px; width: 84px; }
.mvtxt { min-width: 0; }
.mv { font-size: 38px; font-weight: 800; line-height: 1; letter-spacing: -.02em; }
.desc { font-size: 15.5px; font-weight: 700; margin-top: 3px; line-height: 1.3; }
.mvname { font-size: 12.5px; color: var(--mute); margin-top: 5px; line-height: 1.35; }
.done { font-size: 22px; font-weight: 800; }
.ctrls { display: grid; grid-template-columns: 52px 52px 1fr; gap: 8px; }
.ctrls .btn { min-height: 50px; padding: 0; font-size: 16px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0; scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-behavior: smooth; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; min-width: 46px; min-height: 40px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 10px; padding: 0 8px; font-size: 14px; font-weight: 700; }
.chips button.past { color: var(--mute); background: var(--bg2); border-color: transparent; }
.chips button.cur { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.subrow { margin-top: 8px; }
.legend { font-size: 12.5px; color: var(--mute); margin-top: 6px; line-height: 1.55; }
.legend b { color: var(--ink); }
@media (max-width: 340px) { .icon { width: 84px; height: 70px; } .mv { font-size: 32px; } }

/* ===== Полноэкранный редактор точек ===== */
.editor { position: fixed; inset: 0; z-index: 100; background: #0d0d0f; color: #fff; display: flex; flex-direction: column; touch-action: none; -webkit-user-select: none; user-select: none; }
.ed-top { flex: none; padding: calc(10px + var(--sat)) 16px 8px; display: flex; flex-direction: column; gap: 2px; font-size: 13px; line-height: 1.35; }
.ed-top b { font-size: 15px; }
.ed-hint { color: #b8b8be; }
.ed-area { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.ed-frame { position: relative; flex: none; }
.ed-frame canvas { display: block; border-radius: 8px; background: #222; }
.ed-handles { position: absolute; inset: 0; }
.ed-handle { position: absolute; width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%; touch-action: none; cursor: grab; display: flex; align-items: center; justify-content: center; }
.ed-handle i { width: 22px; height: 22px; border-radius: 50%; background: rgba(28,28,30,.85); border: 2.5px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.6); transition: transform .12s; }
.ed-handle.c i { background: var(--accent); }
.ed-handle.drag i { transform: scale(1.35); }
.ed-handle.drag { cursor: grabbing; }
.ed-bottom { flex: none; display: flex; gap: 8px; padding: 10px 16px calc(10px + var(--sab)); }
.editor .btn { background: #2a2a2e; color: #fff; border-color: #3a3a40; }
.editor .btn.primary { background: var(--accent); border-color: var(--accent); }
.editor .btn.primary { min-height: 48px; }

/* ===== Широкие экраны и телефон боком: сцена слева, панель справа ===== */
@media (min-width: 900px), (max-height: 520px) and (min-width: 640px) {
  .app.fixed .main { flex-direction: row; gap: 16px; align-items: stretch; padding-bottom: 12px; }
  .stage { margin: 0; }
  .panel { width: 52%; max-width: 440px; margin: 0; align-self: stretch; border: 1px solid var(--line); border-radius: 20px; padding: 14px; max-height: none; }
  .panel .actions { bottom: -14px; padding-bottom: 14px; margin-bottom: -14px; }
  .viewbar { bottom: 10px; }
}
@media (min-width: 900px) {
  .app.fixed { max-width: 1060px; }
  .app.fixed .main { gap: 24px; padding-bottom: 20px; }
  .panel { width: 440px; align-self: center; padding: 16px; max-height: 100%; }
  .viewbar { bottom: 16px; }
}
@media (max-height: 520px) and (min-width: 640px) {
  .top { height: 44px; }
  .hold { display: none; }
  .scr-photo { padding-bottom: calc(84px + var(--sab)); }
}
/* Очень низкие экраны (старые iPhone 5/SE): компактная палитра, без подписи над кубиком */
@media (max-height: 620px) and (max-width: 639px) {
  .palette { grid-template-columns: repeat(6, minmax(0,1fr)); }
  .palette .sw { flex-direction: column; gap: 3px; padding: 5px 0; min-height: 54px; justify-content: center; }
  .palette .nm { display: none; }
  .palette .n { margin: 0; }
  .stage.short .hold { display: none; }
  .top { height: 48px; }
}
