/*
 * Cubik Build 1.5.88 - Styles (v=1739)
 * Design & Development: Andrey Bovdurets
 * Cleaned and optimized version
 */

/* ========================================
   CSS Variables
   ======================================== */
:root {
  --bg: #020808;
  --panel: radial-gradient(circle at 0% 0%, rgba(0,77,64,0.92), rgba(0,25,22,0.98));
  --panel-strong: radial-gradient(circle at 0% 0%, rgba(0,92,77,0.95), rgba(0,27,24,0.99));
  --border: rgba(255,255,255,.22);
  --border-strong: rgba(255,255,255,.30);
  --text: #FFFFFF;
  --muted: rgba(255,255,255,0.6);
  --accent: #0B8C5D;
  --green: #0B8C5D;
  --red: #ef4444;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius: var(--radius-md);
  --shadow: none;
  --edw: 380px;
}

/* ========================================
   Cube context menu (long-press, touch mode)
   ======================================== */
.cube-context-menu {
  display: none;
  position: fixed;
  z-index: 9000;
  min-width: 180px;
  padding: 6px 0;
  background: var(--panel-strong);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  flex-direction: column;
  gap: 2px;
}
.cube-context-menu.open {
  display: flex;
}
.cube-context-btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  text-align: left;
  font-size: 14px;
  color: var(--text);
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.cube-context-btn:hover,
.cube-context-btn:focus {
  background: rgba(255,255,255,0.12);
  outline: none;
}
.cube-context-btn-danger {
  color: var(--red);
}
.cube-context-btn-danger:hover,
.cube-context-btn-danger:focus {
  background: rgba(239,68,68,0.2);
}
@media (max-width: 768px) {
  .cube-context-btn { padding: 14px 18px; font-size: 15px; min-height: 44px; }
}

/* Touch mode: larger tap targets */
body.touch-mode .panel .icon-btn,
body.touch-mode .hud-btn {
  min-width: 44px;
  min-height: 44px;
}
body.touch-mode .card {
  min-height: 52px;
}
/* Канвас: убираем задержку клика, не блокируем щипок (zoom) */
body.touch-mode canvas {
  touch-action: manipulation;
}

/* ========================================
   Base Reset & Body
   ======================================== */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 0% 0%, rgba(11,140,93,0.4) 0, #001a18 40%, #000608 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

::selection { background: rgba(127,170,255,.25); }
a { color: var(--accent); text-decoration: none; }

body > canvas {
  position: fixed;
  inset: 0;
  display: block;
}

/* ========================================
   Initial Loader
   ======================================== */
#loader {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 320px;
  max-width: 90vw;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 16px;
  z-index: 9999;
  backdrop-filter: saturate(1.2) blur(6px);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
}

#loader h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 12px 0;
  color: #FFFFFF;
}

.file-item {
  position: relative;
  background: radial-gradient(circle at 0% 0%, rgba(38,166,154,0.26), rgba(0,22,20,0.98));
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255,255,255,0.22);
  overflow: hidden;
  padding: 8px 10px;
  margin-bottom: 8px;
  font-size: 13px;
  line-height: 1.35;
}

.file-item strong {
  color: #fff;
  font-weight: 600;
  font-size: 13px;
}

.file-item input[type=file] {
  width: 100%;
  margin: 6px 0;
  font-size: 12px;
  color: var(--text);
}

.file-item .status {
  font-size: 12px;
  color: var(--muted);
}

#start {
  width: 100%;
  border-radius: var(--radius-lg);
  border: none;
  padding: 12px 22px;
  background: radial-gradient(circle 80px at 80% -10%, rgba(11,140,93,0.3), #0B8C5D);
  color: #ffffff;
  font-weight: 600;
  letter-spacing: .02em;
  cursor: pointer;
  margin-top: 12px;
  font-size: 14px;
  min-height: 36px;
  transition: transform .12s ease, filter .12s ease;
}

#start:disabled {
  filter: grayscale(1) brightness(.4);
  cursor: not-allowed;
}

#start:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

#loader .hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
  line-height: 1.4;
}

/* ========================================
   App Header & HUD
   ======================================== */
#appHeader {
  position: fixed;
  top: 24px;
  left: -40px;
  right: 20px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

#appHeader > * { pointer-events: auto; }

.brand {
  position: fixed;
  top: 20px;
  left: 16px;
  width: 180px; /* Same as #ui.panel width */
  transform: none;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  z-index: 30;
}

.brand-logo {
  width: 140px;
  max-width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  filter: none !important;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.hud-bar {
  display: flex;
  align-items: center;
  background: rgba(0,0,0,0.96);
  border-radius: 999px;
  border: 1px solid var(--border);
  box-shadow: none;
  padding: 10px 14px;
  gap: 0;
}

.hud-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 12px;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: #e5e7eb;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

.hud-btn:hover { background: rgba(255, 255, 255, 0.12); }

.hud-icon { font-size: 19px; line-height: 1; }
.hud-icon img {
  display: block;
  width: 18px;
  height: 18px;
  object-fit: contain;
  pointer-events: none;
  filter: brightness(0) invert(1);
}

/* Hide Load/Save labels - icons only */
.hud-btn .hud-label { display: none !important; }

.hud-sep {
  width: 1px;
  align-self: stretch;
  margin: -10px 10px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.35);
}

.hud-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  color: #e5e7eb;
  padding: 0 6px;
}

.hud-pill-count {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 14px;
  min-width: 56px;
}

.hud-pill-count #hudCnt {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.2;
}

.hud-pill-count .hud-pill-caption {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.9;
  line-height: 1.2;
}

.hud-pill-clickable {
  cursor: pointer;
  margin: -4px -4px;
  border-radius: var(--radius-sm);
  box-shadow: none;
  transition: background-color 0.2s ease, transform 0.15s ease;
  user-select: none;
}

.hud-pill-clickable:hover {
  background-color: rgba(255, 255, 255, 0.12);
}

.hud-pill-clickable:active {
  transform: scale(0.96);
  background-color: rgba(255, 255, 255, 0.18);
}

.hud-pill-price { font-weight: 600; }

/* ========================================
   Navigation Toggle & Side Nav
   ======================================== */
.nav-toggle {
  width: 40px;
  height: 40px;
  border-radius: 0;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  padding: 0;
  position: relative;
}

.nav-toggle span {
  display: block;
  width: 17px;
  height: 0;
  border-top: 1px solid #e5e7eb;
  background: none;
  border-radius: 0;
  transition: transform .18s ease, opacity .18s ease;
}

body.nav-open .nav-toggle span {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: center;
}

body.nav-open .nav-toggle span:nth-child(1) { transform: translate(-50%,-50%) rotate(45deg); }
body.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
body.nav-open .nav-toggle span:nth-child(3) { transform: translate(-50%,-50%) rotate(-45deg); }

#navOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease;
  z-index: 29;
}

#sideNav {
  position: fixed;
  top: 0;
  right: 0;
  width: 560px;
  max-width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.96);
  color: #f9fafb;
  padding: 24px 24px 32px 49px;
  transition: transform .2s ease, visibility .2s ease;
  z-index: 30;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transform: translateX(100%);
  visibility: hidden;
}

/* SideNav header with HUD bar */
.sideNav-top {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-shrink: 0;
  width: 100%;
}

/* HUD bar inside sideNav */
.sideNav-top .hud-bar,
#sideNav .hud-bar {
  flex-shrink: 0;
  width: auto;
  white-space: nowrap;
}

/* Close button in sideNav */
.sideNav-top .nav-toggle {
  flex-shrink: 0;
}

/* sideNav list: сдвиг влево на 25px (блок Load/Save не трогаем — он в header) */
#sideNav .sideNav-list {
  list-style: none;
  margin: 80px 0 0 -25px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 20px;
  letter-spacing: 0.02em;
  width: calc(100% + 25px);
  box-sizing: border-box;
}

body.nav-open #navOverlay { opacity: 1; pointer-events: auto; }
body.nav-open #sideNav { 
  transform: translateX(0); 
  visibility: visible;
}

.sideNav-list li {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid rgba(148,163,184,0.25);
  cursor: pointer;
  color: #f9fafb;
  margin: 0;
}

.sideNav-list li:last-child { border-bottom: none; }

.sideNav-list li::after {
  content: "\2192";
  font-size: 18px;
  color: #6b7280;
  -webkit-text-fill-color: currentColor;
  margin-left: 12px;
  opacity: .7;
  transition: transform .16s ease, color .16s ease, opacity .16s ease;
}

/* Мобильное меню: 9 пунктов по центру, без прокрутки, компактные отступы */
body.touch-mode.nav-open #sideNav {
  background: rgba(0,0,0,0.96);
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 95px 16px 72px;
  box-sizing: border-box;
  overflow: hidden;
}
body.touch-mode.nav-open #sideNav .sideNav-list {
  align-items: center;
  text-align: center;
  margin-left: 0;
  margin-right: 0;
  width: 100%;
  flex: 0 0 auto;
  justify-content: center;
  margin-top: auto;
  margin-bottom: auto;
  gap: 0;
}
body.touch-mode.nav-open #sideNav .sideNav-list li {
  justify-content: center;
  border-bottom: none;
  padding: 8px 0;
}
body.touch-mode.nav-open #sideNav .sideNav-list li::after {
  content: none;
  display: none;
}
@media (max-width: 540px) {
  body.touch-mode.nav-open #sideNav { padding: 88px 16px 68px; }
  body.touch-mode.nav-open #sideNav .sideNav-list li { padding: 7px 0; }
}
@media (max-width: 400px) {
  body.touch-mode.nav-open #sideNav { padding: 82px 12px 62px; }
  body.touch-mode.nav-open #sideNav .sideNav-list li { padding: 6px 0; }
}
@media (max-width: 360px) {
  body.touch-mode.nav-open #sideNav { padding: 76px 12px 56px; }
  body.touch-mode.nav-open #sideNav .sideNav-list li { padding: 5px 0; }
}

.sideNav-list a {
  display: block;
  padding: 2px 0;
  text-decoration: none;
  color: #f9fafb;
  font-weight: 500;
}

.sideNav-list li:hover,
.sideNav-list li:hover a,
.sideNav-list a:hover,
.sideNav-list a:focus-visible,
.sideNav-list a.is-active {
  background: linear-gradient(90deg,#fb7185,#f97316,#0B8C5D);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

.sideNav-list li:hover::after {
  color: #f9fafb;
  opacity: 1;
  transform: translateX(4px);
}

/* ========================================
   Left Panel (#ui) - Main Cube Menu
   ======================================== */
#ui.panel {
  position: fixed;
  left: 16px;
  top: 76px;
  width: 180px;
  max-height: calc(100vh - 130px);
  padding: 14px 12px 18px;
  background: rgba(0,0,0,0.96);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255,255,255,0.12);
  overflow: visible;
  z-index: 10;
  transition: opacity 0.18s ease;
}

/* Panel Header & Actions */
#ui .panel-header {
  position: relative;
  padding-bottom: 0;
  margin-bottom: 12px;
}

#ui .panel-hint { display: none; }

#ui .panel-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

#ui .panel-actions .icon-btn {
  flex: 0 0 auto;
  width: 33px;
  height: 33px;
  padding: 0;
  border: none !important;
  border-radius: 999px;
  background: transparent !important;
  box-shadow: none !important;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #d1d7e2;
  transform: scale(1.1);
  transform-origin: center;
}

#ui .panel-actions .icon-btn .icon-img,
#ui .panel-actions .icon-btn svg {
  width: 18px;
  height: 18px;
  min-width: 18px;
  min-height: 18px;
  display: block;
  object-fit: contain;
}

#ui .panel-actions .icon-btn .icon-label {
  font-size: 16px;
  line-height: 1;
}

/* Button Order */
#clearBtn { order: 1; }
#undoBtn { order: 2; }
#redoBtn { order: 3; }
#replayBuildBtn, #recordTimelapseBtn { display: none !important; }
#helpBtn { order: 6; }

/* Help Button */
#helpBtn {
  width: 33px !important;
  height: 33px !important;
  margin: 0;
  padding: 0;
  background: transparent !important;
  border: none !important;
  color: #ff3b30 !important;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(1.3);
  transform-origin: center;
  position: static !important;
  left: auto !important;
  bottom: auto !important;
}

#helpBtn svg {
  width: 24px !important;
  height: 24px !important;
}
#helpBtn img.icon-img {
  width: 24px !important;
  height: 24px !important;
  filter: invert(1);
}

#helpBtn::after { content: ""; }

/* ========================================
   Gallery (Cube Slots)
   ======================================== */
#ui .row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

#ui .gallery {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 10px;
}

#ui .gallery .card {
  position: relative;
  background: radial-gradient(circle at center, #4a4a4a 0%, #1a1a1a 100%);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(32, 32, 32, 0.45);
  overflow: hidden;
  cursor: pointer;
}

#ui .gallery .card canvas {
  display: block;
  width: 100%;
  height: 96px;
  background: transparent;
}

#ui .gallery .card.active {
  outline: none;
  border: 2px solid #0B8C5D;
}

#gallery .badge { display: none !important; }

#ui .gallery .card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,0.05) 50%, transparent 70%);
  background-size: 200% 100%;
  animation: cardShimmer 1.8s ease-in-out infinite;
  pointer-events: none;
}
#ui .gallery .card.loaded::after {
  display: none;
}
@keyframes cardShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.card-rotate-btn {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.5);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}

.card-rotate-btn:hover { background: rgba(0,0,0,0.8); }
.card-rotate-btn-x { right: 6px; top: 6px; }
.card-rotate-btn-z { right: 34px; top: 6px; }

/* ========================================
   Palette - Attached to Cube Menu
   ======================================== */
/* Обёртка палитры + стрелки: на десктопе не ломает позиционирование */
.panel-right-strip {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 90px;
  pointer-events: none;
}
.panel-right-strip > * { pointer-events: auto; }
#ui .row.row-palette {
  position: absolute;
  top: auto;
  bottom: 60px;
  right: -54px;
  width: 54px;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.panel-right-strip .row.row-palette {
  right: 0;
}

#ui .row.row-palette #palette {
  position: static;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 12px 8px;
  gap: 8px;
  background: rgba(0,0,0,0.96);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  border-width: 1px 1px 1px 0;
  border-style: solid;
  border-color: rgba(255,255,255,0.10);
}

#ui .row.row-palette #palette .dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin: 2px 0;
  border: 2px solid rgba(255,255,255,0.88);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
  flex-shrink: 0;
}

#ui .row.row-palette #palette .dot:hover {
  transform: scale(1.08);
  border-color: rgba(148,163,184,0.9);
}

#ui .row.row-palette #palette .dot.active {
  outline: 2px solid rgba(56,189,248,1);
  outline-offset: 1px;
}

/* ========================================
   Help Row (Below Cubes)
   ======================================== */
#ui .row-help {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 0;
  width: 100%;
}

#ui .row-help #helpBtn,
#ui .row-help #tutorialBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 14px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.4);
  background: #1A1A1A;
  width: auto !important;
  height: auto !important;
  transform: none !important;
  position: static !important;
  left: auto !important;
  bottom: auto !important;
  color: #ffffff;
  cursor: pointer;
  transition: all 0.2s ease;
}

#ui .row-help #helpBtn:hover,
#ui .row-help #tutorialBtn:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.6);
}

#ui .row-help #helpBtn .icon-img,
#ui .row-help #helpBtn svg,
#ui .row-help #helpBtn img,
#ui .row-help #tutorialBtn .icon-img,
#ui .row-help #tutorialBtn svg {
  width: 0.72em !important;
  height: 0.72em !important;
  color: #ffffff;
  fill: currentColor;
  stroke: currentColor;
}

#ui .row-help #helpBtn .help-label,
#ui .row-help #tutorialBtn .help-label {
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  color: #ffffff;
}

/* Hidden Legacy Elements */
#toolbarToggle, #status, #statsBadge, #stats, 
#exportStatsBtn, #facetStats,
#panelHint, .hidden-legacy { 
  display: none !important; 
}

#projectPanel { position: fixed; left: -9999px; }


/* ========================================
   Editor Side Panel
   ======================================== */
#editor {
  position: fixed;
  top: 0;
  right: calc(-1 * var(--edw));
  width: var(--edw);
  height: 100vh;
  background: #000000 !important;
  border-left: 1px solid rgba(255,255,255,0.18) !important;
  transition: right .22s ease;
  z-index: 30;
  padding: 14px;
  backdrop-filter: saturate(1.15) blur(8px);
  overflow: auto;
  max-width: 100vw;
}

#editor.open { right: 0; }

body.touch-mode #editor {
  width: 100%;
  right: calc(-1 * 100%);
  max-width: none;
}
body.touch-mode #editor.open {
  right: 0;
}
body.touch-mode #previewWrap {
  height: min(40vh, 320px);
}
body.touch-mode #previewWrap canvas {
  touch-action: manipulation;
}
body.touch-mode #replaceBtn {
  min-height: 48px;
  font-size: 15px;
}

/* ========================================
   Mobile: editor preview collapsible (header tap + tab)
   ======================================== */
.mobile-panel-collapse-header,
.mobile-editor-collapse-header {
  display: none;
}
body.touch-mode .mobile-panel-collapse-header,
body.touch-mode .mobile-editor-collapse-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 12px;
  margin: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
body.touch-mode .mobile-panel-collapse-header:active,
body.touch-mode .mobile-editor-collapse-header:active {
  background: rgba(255,255,255,0.1);
}
.mobile-panel-collapse-arrow {
  font-size: 10px;
  opacity: 0.8;
  transition: transform 0.2s ease;
}
body.touch-mode .mobile-panel-collapse.collapsed .mobile-panel-collapse-arrow,
body.touch-mode .mobile-editor-collapse.collapsed .mobile-panel-collapse-arrow {
  transform: rotate(-90deg);
}
.mobile-panel-collapse-body,
.mobile-editor-collapse-body {
  overflow: hidden;
  transition: max-height 0.25s ease;
}
body.touch-mode .mobile-panel-collapse.collapsed .mobile-panel-collapse-body {
  max-height: 0 !important;
  opacity: 0;
  pointer-events: none;
}
body.touch-mode .mobile-panel-collapse .mobile-panel-collapse-body {
  max-height: 500px;
}

/* Левая панель: на десктопе без стрелки; в touch-mode — стрелка + палитра всегда видны, кубы сворачиваются */
#ui .panel-left-slide {
  transition: transform 0.25s ease;
}
.panel-toggle-arrow {
  display: none;
}
/*
 * Touch-mode layout: panel-cubes-palette = flex-row [row-main(кубы)] [row-palette(стрелка+палитра)]
 * row-palette содержит стрелку НАД точками палитры (flex-column, align-self: flex-end).
 * При коллапсе: row-main → width:0, header + help → скрыты. row-palette остаётся.
 * JS перемещает panelToggleArrow внутрь row-palette (перед #palette).
 */
body.touch-mode #ui {
  overflow: visible;
  transition: width 0.25s ease, padding-left 0.25s ease;
}
body.touch-mode #ui.panel {
  padding: 8px 0 12px 8px;
  top: 72px;
  left: 0;
  bottom: auto;
  max-height: none;
  height: auto;
  width: 130px;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  border-radius: 0;
}
/* Основной блок (кубы+header+help) — отдельный фон через ::before */
body.touch-mode #ui.panel::before {
  content: '';
  position: absolute;
  top: -1px;
  left: -1px;
  bottom: -1px;
  width: 107px;
  background: rgba(0,0,0,0.96);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  z-index: -1;
  pointer-events: none;
  transition: opacity 0.25s ease, width 0.25s ease;
}
body.touch-mode.panel-left-collapsed #ui.panel {
  width: 42px;
  padding-left: 10px;
  pointer-events: none;
}
body.touch-mode.panel-left-collapsed #ui.panel::before {
  left: -20px;
  width: 30px;
  opacity: 1;
  top: -1px;
  bottom: -1px;
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  border-right: none;
}
body.touch-mode #ui .panel-left-slide {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
body.touch-mode #ui .panel-header { order: 0; }
body.touch-mode #ui .panel-cubes-palette { order: 1; }
body.touch-mode #ui .row.row-help { order: 2; }

/* Header */
body.touch-mode #ui .panel-header {
  padding: 6px 8px 4px 8px;
  margin-bottom: 6px;
  overflow: hidden;
  max-height: 40px;
  max-width: 98px;
  width: 100%;
  box-sizing: border-box;
  transition: max-height 0.25s ease, opacity 0.2s ease, margin 0.25s ease;
}
body.touch-mode.panel-left-collapsed #ui .panel-header {
  max-height: 0;
  opacity: 0;
  margin-bottom: 0;
  padding-bottom: 0;
  pointer-events: none;
}
body.touch-mode #ui .panel-actions {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  gap: 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
body.touch-mode #ui .panel-actions .icon-btn {
  width: 14px;
  height: 14px;
  min-width: 14px;
  min-height: 14px;
  flex: 0 0 14px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
body.touch-mode #ui .panel-actions .icon-btn .icon-img,
body.touch-mode #ui .panel-actions .icon-btn svg {
  width: 8px;
  height: 8px;
  object-fit: contain;
}

/* panel-cubes-palette: flex-row — [row-main (кубы)] [row-palette (стрелка + точки)] */
body.touch-mode #ui .panel-cubes-palette {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 0;
  flex: 0 0 auto;
  min-width: 0;
  min-height: 0;
}
body.touch-mode #ui .panel-cubes-palette .row.row-main {
  flex: 0 0 auto;
  width: 98px;
  min-width: 98px;
  max-width: 98px;
  overflow: hidden;
  border-right: none;
  transition: width 0.25s ease, min-width 0.25s ease, max-width 0.25s ease, opacity 0.2s ease;
}
body.touch-mode.panel-left-collapsed #ui .panel-cubes-palette .row.row-main {
  width: 0;
  min-width: 0;
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}
body.touch-mode #ui .gallery {
  gap: 8px;
  padding-bottom: 0;
  padding-right: 8px;
  box-sizing: border-box;
}
body.touch-mode #ui .gallery .card {
  width: 89px;
  min-width: 89px;
  max-width: 89px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}
body.touch-mode #ui .gallery .card canvas {
  height: 72px;
  width: 89px;
  box-sizing: border-box;
  object-fit: contain;
  display: block;
}

/* row-palette: в collapsed — верхняя часть блока, gap +15%, AI Editor margin-top x3 */
body.touch-mode.panel-left-collapsed #ui .panel-left-slide .row.row-palette {
  border-radius: 0 var(--radius-md) 0 0;
  gap: 5px;
}
body.touch-mode.panel-left-collapsed #ui .panel-left-slide .row.row-palette #palette {
  gap: 5px;
}
/* row-palette: единое пространство с preview, без seam */
body.touch-mode #ui .panel-left-slide .row.row-palette {
  position: static;
  width: 32px;
  min-width: 32px;
  margin-left: -1px;
  margin-top: 0;
  margin-bottom: 0;
  margin-right: 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  align-self: flex-end;
  gap: 4px;
  background: rgba(0,0,0,0.96);
  border: 1px solid rgba(255,255,255,0.10);
  border-left: none;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: 6px 3px;
  pointer-events: auto;
}

/* Стрелка (JS перемещает внутрь row-palette, перед #palette) */
body.touch-mode #ui .row.row-palette .panel-toggle-arrow {
  position: static;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  min-width: 22px;
  height: 28px;
  flex-shrink: 0;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: #d1d7e2;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  box-shadow: none;
}
body.touch-mode #ui .row.row-palette .panel-toggle-arrow:hover,
body.touch-mode #ui .row.row-palette .panel-toggle-arrow:active {
  color: #fff;
}
body.touch-mode .panel-toggle-arrow .panel-toggle-arrow-icon {
  color: inherit;
  line-height: 1;
  transition: transform 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
body.touch-mode .panel-toggle-arrow .panel-toggle-arrow-icon svg {
  width: 8px;
  height: 14px;
  display: block;
}
body.touch-mode.panel-left-collapsed .panel-toggle-arrow .panel-toggle-arrow-icon {
  transform: rotate(180deg);
}

/* #palette: точки (фон на родителе row-palette) */
body.touch-mode #ui .panel-left-slide .row.row-palette #palette {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 0;
  gap: 4px;
  border-radius: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  width: auto;
}
body.touch-mode #ui .panel-left-slide .row.row-palette #palette .dot {
  width: 21px;
  height: 21px;
  margin: 0;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.88);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
body.touch-mode #ui .panel-left-slide .row.row-palette #palette .dot:hover {
  transform: scale(1.08);
}
body.touch-mode #ui .panel-left-slide .row.row-palette #palette .dot.active {
  border: 1px solid rgba(255,255,255,0.88);
  outline: none;
}

/* Help — по центру блока превью кубов */
body.touch-mode #ui .row.row-help {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 4px;
  margin-bottom: 0;
  overflow: hidden;
  max-height: 40px;
  width: 98px;
  max-width: 98px;
  padding-left: 0;
  box-sizing: border-box;
  transition: max-height 0.25s ease, opacity 0.2s ease, margin 0.25s ease;
}
body.touch-mode #ui .row.row-help #helpBtn {
  padding: 4px 10px;
  justify-content: center;
  font-size: 14px;
}
body.touch-mode.panel-left-collapsed #ui .row.row-help {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  margin-bottom: 0;
  pointer-events: none;
}

/* Footer divider — full width, flush to panel left edge, hud-sep style */
body.touch-mode #ui .footer-divider {
  order: 2;
  flex-shrink: 0;
  height: 1px;
  min-height: 1px;
  background: rgba(255,255,255,0.25);
  margin-left: -8px;
  width: 106px;
  align-self: flex-start;
}
body.touch-mode.panel-left-collapsed #ui .footer-divider {
  display: none;
}

/* AI Editor — по центру блока превью, иконка над надписью */
body.touch-mode #ui .row.row-ai-editor {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 0;
  overflow: hidden;
  max-height: 56px;
  width: 98px;
  max-width: 98px;
  padding-top: 4px;
  padding-left: 0;
  box-sizing: border-box;
  transition: max-height 0.25s ease, opacity 0.2s ease, margin 0.25s ease;
  order: 3;
  position: relative;
}
body.touch-mode.panel-left-collapsed #ui .row.row-ai-editor {
  max-height: 48px;
  max-width: 32px;
  width: 32px;
  padding-top: 0;
  padding-left: 0;
  opacity: 1;
  margin-top: 0;
  margin-left: 0;
  margin-right: 0;
  align-self: center;
  pointer-events: auto;
  background: rgba(0,0,0,0.96);
  border: 1px solid rgba(255,255,255,0.10);
  border-top: none;
  border-left: none;
  border-radius: 0 0 var(--radius-md) 0;
}
body.touch-mode.panel-left-collapsed #ui .row.row-ai-editor .ai-editor-label {
  display: none !important;
}
body.touch-mode.panel-left-collapsed #ui .row.row-ai-editor #aiToggleFloat {
  padding: 6px 4px 8px !important;
  width: 100% !important;
  max-width: 100% !important;
  justify-content: center !important;
  align-items: center !important;
}
body.touch-mode #ui .row.row-ai-editor #aiToggleFloat {
  position: static !important;
  bottom: auto !important;
  left: auto !important;
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: auto !important;
  max-width: none !important;
  min-width: 0 !important;
  padding: 6px 10px 8px !important;
  margin-left: 0 !important;
  border-radius: 0;
  border: none !important;
  background: transparent;
  color: #ffffff;
  font-size: 11px;
  font-weight: 500;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  box-shadow: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s ease, opacity 0.2s ease;
}
body.touch-mode #ui .row.row-ai-editor #aiToggleFloat:hover {
  background: rgba(255,255,255,0.08);
}
body.touch-mode #ui .row.row-ai-editor #aiToggleFloat svg {
  width: 20px !important;
  height: 20px !important;
  stroke: currentColor;
  fill: none;
  flex-shrink: 0;
}

/* Strip: скрыт в touch-mode (стрелка перенесена JS-ом внутрь row-palette) */
body.touch-mode #ui .panel-right-strip {
  display: none !important;
}

/* Логотип по центру блока превью */
body.touch-mode #appHeader {
  position: fixed;
  left: 0;
  right: 0;
  padding: 0 8px;
}
body.touch-mode .brand {
  position: absolute;
  left: 54px;
  transform: translateX(-50%);
  width: auto;
  margin: 0;
}
body.touch-mode .brand-logo {
  width: 94px;
}
body.touch-mode .header-right {
  margin-left: auto;
}

/* Touch-mode: адаптация по ширине экрана */
@media (min-width: 600px) {
  body.touch-mode #ui .panel-header { padding: 6px 10px 4px 10px; }
  body.touch-mode #ui .panel-actions { justify-content: space-between; width: 100%; }
  body.touch-mode #ui.panel { width: 168px; }
  body.touch-mode #ui.panel::before { width: 145px; }
  body.touch-mode.panel-left-collapsed #ui.panel { width: 45px; padding-left: 10px; }
  body.touch-mode.panel-left-collapsed #ui .row.row-ai-editor { max-width: 35px; width: 35px; padding-left: 0; }
  body.touch-mode #ui .panel-header { max-width: 132px; }
  body.touch-mode #ui .row.row-help { width: 132px; max-width: 132px; }
  body.touch-mode #ui .row.row-ai-editor { width: 132px; max-width: 132px; }
  body.touch-mode #ui .footer-divider { max-width: 140px; width: 140px; }
  body.touch-mode #ui .panel-cubes-palette .row.row-main { width: 132px; min-width: 132px; max-width: 132px; }
  body.touch-mode #ui .gallery .card { width: 123px; min-width: 123px; max-width: 123px; }
  body.touch-mode #ui .gallery .card canvas { height: 99px; width: 123px; }
  body.touch-mode #ui .panel-left-slide .row.row-palette { width: 35px; min-width: 35px; padding: 6px 4px; }
  body.touch-mode #ui .panel-left-slide .row.row-palette #palette .dot { width: 23px; height: 23px; }
  body.touch-mode #ui .row.row-palette .panel-toggle-arrow { width: 26px; min-width: 26px; height: 35px; }
  body.touch-mode #ui .panel-actions .icon-btn { width: 16px; height: 16px; min-width: 16px; flex: 0 0 16px; }
  body.touch-mode #ui .panel-actions .icon-btn .icon-img,
  body.touch-mode #ui .panel-actions .icon-btn svg { width: 9px; height: 9px; }
  body.touch-mode .brand-logo { width: 105px; }
  body.touch-mode .brand { left: 84px; }
}
@media (max-width: 400px) {
  body.touch-mode #ui .panel-header { padding: 5px 6px 4px 6px; }
  body.touch-mode #ui .panel-actions { justify-content: space-between; width: 100%; }
  body.touch-mode #ui.panel { width: 134px; bottom: auto; }
  body.touch-mode #ui.panel::before { width: 108px; }
  body.touch-mode.panel-left-collapsed #ui.panel { width: 40px; padding-left: 10px; }
  body.touch-mode.panel-left-collapsed #ui .row.row-ai-editor { max-width: 30px; width: 30px; padding-left: 0; }
  body.touch-mode #ui .panel-header { max-width: 96px; }
  body.touch-mode #ui .row.row-help { width: 96px; max-width: 96px; }
  body.touch-mode #ui .row.row-ai-editor { width: 96px; max-width: 96px; }
  body.touch-mode #ui .footer-divider { max-width: 104px; width: 104px; }
  body.touch-mode #ui .panel-cubes-palette .row.row-main { width: 96px; min-width: 96px; max-width: 96px; }
  body.touch-mode #ui .gallery .card { width: 87px; min-width: 87px; max-width: 87px; }
  body.touch-mode #ui .gallery .card canvas { height: 72px; width: 87px; }
  body.touch-mode #ui .panel-left-slide .row.row-palette { width: 30px; min-width: 30px; padding: 4px 2px; }
  body.touch-mode #ui .panel-left-slide .row.row-palette #palette .dot { width: 19px; height: 19px; }
  body.touch-mode #ui .row.row-palette .panel-toggle-arrow { width: 20px; min-width: 20px; height: 24px; }
  body.touch-mode #ui .panel-actions .icon-btn { width: 12px; height: 12px; min-width: 12px; flex: 0 0 12px; }
  body.touch-mode #ui .panel-actions .icon-btn .icon-img,
  body.touch-mode #ui .panel-actions .icon-btn svg { width: 7px; height: 7px; }
  body.touch-mode .brand-logo { width: 79px; }
  body.touch-mode .brand { left: 54px; }
}
@media (max-width: 360px) {
  body.touch-mode #ui .panel-header { padding: 5px 6px 4px 6px; }
  body.touch-mode #ui .panel-actions { justify-content: space-between; width: 100%; }
  body.touch-mode #ui.panel { width: 124px; }
  body.touch-mode #ui.panel::before { width: 101px; }
  body.touch-mode.panel-left-collapsed #ui.panel { width: 38px; padding-left: 10px; }
  body.touch-mode.panel-left-collapsed #ui .row.row-ai-editor { max-width: 28px; width: 28px; padding-left: 0; }
  body.touch-mode #ui .panel-header { max-width: 88px; }
  body.touch-mode #ui .row.row-help { width: 88px; max-width: 88px; }
  body.touch-mode #ui .row.row-ai-editor { width: 88px; max-width: 88px; }
  body.touch-mode #ui .footer-divider { max-width: 96px; width: 96px; }
  body.touch-mode #ui .panel-cubes-palette .row.row-main { width: 88px; min-width: 88px; max-width: 88px; }
  body.touch-mode #ui .gallery { gap: 6px; }
  body.touch-mode #ui .gallery .card { width: 79px; min-width: 79px; max-width: 79px; }
  body.touch-mode #ui .gallery .card canvas { height: 64px; width: 79px; }
  body.touch-mode #ui .panel-left-slide .row.row-palette { width: 28px; min-width: 28px; padding: 4px 2px; }
  body.touch-mode #ui .panel-left-slide .row.row-palette #palette .dot { width: 17px; height: 17px; }
  body.touch-mode #ui .row.row-palette .panel-toggle-arrow { width: 18px; min-width: 18px; height: 22px; }
  body.touch-mode #ui .panel-actions .icon-btn { width: 11px; height: 11px; min-width: 11px; flex: 0 0 11px; }
  body.touch-mode #ui .panel-actions .icon-btn .icon-img,
  body.touch-mode #ui .panel-actions .icon-btn svg { width: 6px; height: 6px; }
  body.touch-mode .brand-logo { width: 72px; }
  body.touch-mode .brand { left: 51px; }
}
@media (max-height: 600px) {
  body.touch-mode #ui .panel-header { padding-bottom: 3px; margin-bottom: 4px; }
  body.touch-mode #ui .gallery { gap: 6px; }
  body.touch-mode #ui .gallery .card canvas { height: 68px; }
  body.touch-mode #ui .row.row-help { margin-top: 4px; }
}
@media (max-height: 500px) {
  body.touch-mode #ui .panel-header { padding-bottom: 2px; margin-bottom: 3px; }
  body.touch-mode #ui .gallery .card canvas { height: 61px; }
  body.touch-mode #ui .panel-left-slide .row.row-palette #palette .dot { width: 17px; height: 17px; }
}

/* Редактор граней: в touch-mode сворачивается вся панель целиком */
.editor-toggle-tab {
  display: none;
}
body.touch-mode #editorWrap {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 56px;
  z-index: 30;
  pointer-events: none;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  transition: width 0.25s ease;
}
#editorWrap > * { pointer-events: auto; }
body.touch-mode.editor-panel-expanded #editorWrap {
  width: 100%;
}
body.touch-mode.editor-open .editor-toggle-tab {
  display: flex;
}
body.touch-mode .editor-toggle-tab {
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  min-width: 40px;
  padding: 0;
  border: 1px solid rgba(255,255,255,0.12);
  border-right: none;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  background: rgba(0,0,0,0.92);
  color: #d1d7e2;
  font-size: 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
body.touch-mode .editor-toggle-tab:active {
  background: rgba(255,255,255,0.08);
}
body.touch-mode #editorWrap #editor {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  right: auto !important;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
body.touch-mode.editor-panel-expanded #editorWrap #editor {
  transform: translateX(0);
}
body.touch-mode .editor-toggle-tab .editor-toggle-icon {
  transition: transform 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
body.touch-mode .editor-toggle-tab .editor-toggle-icon svg {
  width: 10px;
  height: 16px;
  display: block;
}
body.touch-mode.editor-panel-expanded .editor-toggle-tab .editor-toggle-icon {
  transform: rotate(180deg);
}

#edOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s;
  z-index: 20;
}

body.editor-open #edOverlay { opacity: 1; pointer-events: auto; }
body.editor-open #hudBar, body.editor-open #navToggle { display: none !important; }
body.editor-open #projectPanel { display: none !important; }
body.touch-mode.editor-open .brand { display: none !important; }

/* Editor Groups */
.group {
  margin: 12px 0;
  padding: 12px;
  border: 1px solid rgba(255,255,255,0.16) !important;
  border-radius: var(--radius);
  background: #000000 !important;
}

.group-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

#previewWrap {
  width: 100%;
  height: 260px;
  background: #000000 !important;
  border: 1px solid rgba(255,255,255,0.16) !important;
  border-radius: var(--radius-lg) !important;
  overflow: hidden;
  position: relative;
}

#previewHint {
  position: absolute;
  left: 10px;
  bottom: 10px;
  font-size: 11px;
  color: #94a3b8;
  pointer-events: none;
}

/* Face Type Gallery */
.face-type-gallery {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 10px 0;
}

.face-type-card {
  position: relative;
  background: #000000 !important;
  border: 1px solid rgba(255,255,255,0.18) !important;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.face-type-card.active { outline: 2px solid #ffffff !important; }

.face-type-card canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
}

.face-type-card .face-type-thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: transparent;
  pointer-events: none;
}

.face-type-label {
  position: absolute;
  bottom: 4px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  color: #f5f5f5 !important;
  background: none !important;
  padding: 0;
  border: none;
  text-shadow: 0 0 6px rgba(0,0,0,0.95);
}

/* Editor Palette */
#editor #paletteFace {
  display: flex !important;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  margin-top: 8px;
  background: #000000;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.18) !important;
}

#editor #paletteFace .dot {
  width: 28px;
  height: 28px;
  margin: 0;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.7);
}

#editor #paletteFace .dot.active {
  border: 2px solid rgba(255,255,255,0.95);
}

/* Editor Typography */
#editor .panel-header h3 {
  margin: 0;
  font-family: "Montserrat", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-weight: 600;
  font-size: 15px;
  color: #ffffff !important;
}

#editor .hint { color: #b3b3b3 !important; }

/* Editor Buttons */
#replaceBtn {
  width: 100%;
  border-radius: 999px !important;
  background: #000000 !important;
  color: #ffffff !important;
  border: 1px solid rgba(255,255,255,0.9) !important;
  padding: 12px 22px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease;
}

#replaceBtn:hover { background: #050505 !important; }
#replaceBtn:active { background: #0a0a0a !important; }

/* Use Button */
body.editor-open #saveAsTypeBtn {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1000;
  border-radius: var(--radius-lg);
  padding: 12px 22px;
  font-size: 18px;
  font-weight: 700;
  background: radial-gradient(circle 80px at 80% -10%, rgba(11,140,93,0.3), #0B8C5D);
  color: #ffffff;
  border: none;
  cursor: pointer;
}

body:not(.editor-open) #saveAsTypeBtn { display: none !important; }

#saveAsTypeBtn:hover {
  transform: translateY(-1px);
}

#saveAsTypeBtn:active {
  transform: translateY(1px);
}

/* ========================================
   Help Modal
   ======================================== */
#helpOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65) !important;
  -webkit-backdrop-filter: blur(8px) saturate(1.05);
  backdrop-filter: blur(8px) saturate(1.05);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
  z-index: 4000;
}

.help-open #helpOverlay { opacity: 1; pointer-events: auto; }

#helpModal {
  position: fixed;
  left: 50%;
  top: 50%;
  /* Adaptive width based on content */
  width: fit-content;
  min-width: 280px;
  max-width: min(92vw, 420px);
  max-height: 85vh;
  overflow-x: hidden;
  overflow-y: auto;
  background: #000000 !important;
  border: 1px solid rgba(255,255,255,0.18) !important;
  border-radius: var(--radius-lg);
  padding: 24px 28px 24px;
  z-index: 4010;
  transform: translate(-50%,-52%) scale(.98);
  opacity: 0;
  pointer-events: none;
  transition: transform .18s ease, opacity .18s ease;
  color: #f5f5f5 !important;
}

.help-open #helpModal {
  opacity: 1;
  transform: translate(-50%,-50%) scale(1);
  pointer-events: auto;
}

.help-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 16px 0;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.18);
  font-family: "Montserrat", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-weight: 600;
  font-size: 15px;
  color: #ffffff !important;
}

.help-title .txt {
  font-size: 14px;
  color: #FFFFFF;
  font-weight: 600;
}

#helpClose {
  width: 28px;
  height: 28px;
  margin-left: auto;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.9);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.9);
  cursor: pointer;
  transition: transform .06s ease, background .12s ease;
  flex: 0 0 auto;
  position: static;
}

#helpClose:hover {
  background: rgba(255,255,255,0.08);
  transform: translateY(-1px);
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}

.help-row {
  list-style: none;
  display: grid;
  grid-template-columns: max-content 1fr;
  align-items: center;
  column-gap: 14px;
  padding: 2px 0;
}

.help-row .ico {
  width: auto;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.help-row .ico.two { display: flex; align-items: center; gap: 6px; }

.help-row .txt { 
  color: #d4d4d4 !important; 
  font-size: 14px; 
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.icon-img {
  height: 28px;
  width: auto;
  display: block;
  object-fit: contain;
  image-rendering: auto;
  background: none;
}

.kbd, .kbd-wide {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  padding: 0 6px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.2);
  background: #050505;
  color: #ffffff;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.2px;
  line-height: 1;
}

.help-subtitle {
  margin: 6px 0 4px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #9fb3cc;
  opacity: .9;
}

.help-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  justify-content: center;
  padding-top: 8px;
  margin-top: 12px;
}

#helpStart {
  width: 100%;
  font-weight: 800;
  font-size: 18px;
  line-height: 1;
  padding: 18px 22px;
  border-radius: 999px !important;
  cursor: pointer;
  background: #000000 !important;
  color: #ffffff !important;
  border: 1px solid rgba(255,255,255,0.9) !important;
  transition: transform .12s ease;
}

#helpTutorialBtn {
  width: 100%;
  font-weight: 600;
  font-size: 15px;
  line-height: 1;
  padding: 14px 20px;
  border-radius: 999px !important;
  cursor: pointer;
  background: rgba(255,255,255,0.1) !important;
  color: #ffffff !important;
  border: 1px solid rgba(255,255,255,0.3) !important;
  transition: all .12s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

#helpTutorialBtn:hover {
  background: rgba(255,255,255,0.15) !important;
  border-color: rgba(255,255,255,0.5) !important;
}

#helpTutorialBtn .tutorial-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
}

#helpStart:hover { background: #050505 !important; }
#helpStart:active { background: #0a0a0a !important; }

/* ========================================
   Project Modal
   ======================================== */
#projectModal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
}

#projectModal.active { display: block; }

#projectModal .project-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}

#projectModal .project-modal-window {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-width: 360px;
  max-width: 320px;
  padding: 14px 16px 12px;
  background: var(--panel-strong);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
}

#projectModal .project-modal-header {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
}

#projectModal .project-modal-body input {
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #050915;
  color: var(--text);
  font-size: 13px;
  outline: none;
}

#projectModal .project-modal-body input::placeholder { color: var(--muted); }

#projectModal .project-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

#projectModal .project-btn {
  height: 32px;
  padding: 4px 12px;
  font-size: 12px;
}

/* ========================================
   Language Switcher
   ======================================== */
.hud-lang-switcher {
  display: flex;
  gap: 4px;
  padding: 4px 6px;
}

.lang-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.lang-btn:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border-color: var(--border-strong);
}

.lang-btn.active,
html[data-lang="en"] .lang-btn[data-lang="en"],
html[data-lang="ru"] .lang-btn[data-lang="ru"] {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* ========================================
   Global Loader (CubikOne logo + 3D Bion cube + Loading...)
   ======================================== */
#globalLoader {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000000;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.loader-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  gap: 0;
}

.loader-logo {
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  height: 72px;
  width: auto;
  max-width: 360px;
  object-fit: contain;
}

.loader-cube-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  width: 100%;
}

.loader-label {
  position: absolute;
  left: 50%;
  bottom: 48px;
  transform: translateX(-50%);
  color: #ffffff;
  font-size: 28px;
  font-weight: 400;
  letter-spacing: 0.04em;
}

#globalLoader.fade-out {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

/* ========================================
   Responsive Design
   ======================================== */

/* Tablet & Small Desktop */
@media (max-width: 900px) {
  #appHeader { top: 10px; left: 12px; right: 12px; }
  
  .hud-bar {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 14px;
    justify-content: space-between;
    flex-wrap: nowrap;
    white-space: nowrap;
    padding: 8px 10px;
    gap: 0;
    border-radius: 999px;
  }
  .hud-bar .hud-btn {
    padding: 6px 8px;
    font-size: 13px;
    min-width: 40px;
    min-height: 40px;
  }
  .hud-bar .hud-icon img {
    width: 16px;
    height: 16px;
  }
  .hud-bar .hud-sep {
    margin: -8px 6px;
    align-self: stretch;
    flex-shrink: 0;
  }
  .hud-bar .hud-pill {
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .hud-bar .hud-pill-count {
    padding: 4px 10px;
    min-width: 48px;
  }
  .hud-bar .hud-pill-count #hudCnt {
    font-size: 15px;
  }
  .hud-bar .hud-pill-count .hud-pill-caption {
    font-size: 11px;
  }
  .hud-bar .hud-pill-price {
    white-space: nowrap;
  }
  .hud-bar #continueBtn {
    padding: 8px 12px;
    font-size: 13px;
    flex-shrink: 0;
  }
  
  #ui.panel { top: 72px; left: 12px; }
}

/* Tablets */
@media (max-width: 768px) {
  /* Logo centered above cube panel */
  .brand {
    position: fixed;
    top: 12px;
    left: 12px;
    width: 180px;
    transform: none;
    justify-content: center;
  }
  
  .brand .brand-logo { width: 120px; }
  
  /* Panel stays on the left side */
  #ui.panel {
    left: 12px;
    right: auto;
    width: 200px;
    top: 60px;
    max-height: calc(100vh - 80px);
    padding: 12px 12px 14px;
  }
  
  #ui .panel-header { padding-bottom: 10px; margin-bottom: 8px; }
  #ui .panel-actions { flex-wrap: nowrap; gap: 8px; justify-content: space-between; }
  
  #ui .row { margin-top: 8px; }
  
  /* Gallery stays vertical */
  #ui .gallery {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  
  #ui .gallery .card canvas { height: 70px; }
  
  /* Palette goes horizontal below cubes (only when NOT inside .panel-right-strip in touch-mode) */
  #ui .row.row-palette {
    position: static;
    width: 100%;
    height: auto;
    margin-top: 10px;
    right: auto;
  }
  
  #ui .row.row-palette #palette {
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 999px;
    border-width: 1px;
    border-left-width: 1px;
  }
  
  #ui .row.row-palette #palette .dot {
    width: 28px;
    height: 28px;
    margin: 0;
  }
  
  /* Help row centered */
  #ui .row-help {
    margin-top: 12px;
    justify-content: center;
    padding: 0;
  }
  
  /* Help Modal - wider to fit content */
  #helpModal {
    top: 50%;
    bottom: auto;
    left: 50%;
    right: auto;
    width: 340px;
    max-width: 94vw;
    max-height: 90vh;
    padding: 16px 18px 16px;
    transform: translate(-50%, -50%);
    overflow-y: auto;
  }
  
  .help-open #helpModal {
    transform: translate(-50%, -50%) scale(1);
  }
  
  .help-title { margin-bottom: 12px; padding-bottom: 10px; }
  .help-title .txt { font-size: 14px; }
  .help-grid { gap: 4px; }
  .help-row { column-gap: 10px; padding: 4px 0; }
  /* Allow wrapping on high zoom / narrow viewports (prevents modal width blow-outs) */
  .help-row .txt {
    font-size: 13px;
    line-height: 1.35;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .help-row .ico { height: 24px; flex-shrink: 0; }
  .help-row .ico img.icon-img { height: 24px; }
  .help-subtitle { margin: 8px 0 4px; font-size: 11px; }
  .help-actions { margin-top: 16px; padding-top: 14px; }
  #helpStart { font-size: 16px; padding: 14px 18px; }
  #helpTutorialBtn { font-size: 14px; padding: 12px 16px; gap: 8px; }
  #helpTutorialBtn .tutorial-icon { width: 18px; height: 18px; }
  .kbd, .kbd-wide { height: 22px; padding: 0 6px; font-size: 11px; white-space: nowrap; }
  
  #sideNav { 
    min-width: 380px;
    max-width: 100vw; 
    padding: 20px 20px 24px 45px; 
  }
  .sideNav-list { font-size: 18px; margin-top: 60px !important; }
  .sideNav-list li { padding: 14px 0; }
}

/* Mobile */
@media (max-width: 540px) {
  /* Logo above left panel */
  .brand {
    top: 8px;
    left: 8px;
    width: 160px;
    transform: none;
  }
  
  .brand .brand-logo { width: 100px; }
  
  /* Panel on the left */
  #ui.panel {
    top: 50px;
    left: 8px;
    right: auto;
    width: 160px;
    padding: 10px 10px 12px;
    max-height: calc(100vh - 70px);
  }
  
  #ui .panel-actions { gap: 4px; }
  #ui .panel-actions .icon-btn {
    width: 26px;
    height: 26px;
  }
  
  #ui .gallery { gap: 6px; }
  #ui .gallery .card canvas { height: 55px; }
  
  #ui .row.row-palette { margin-top: 8px; }
  #ui .row.row-palette #palette {
    padding: 8px 10px;
    gap: 6px;
  }
  #ui .row.row-palette #palette .dot {
    width: 24px;
    height: 24px;
  }
  
  #ui .row-help {
    margin-top: 8px;
  }
  
  #ui .row-help #helpBtn,
  #ui .row-help #tutorialBtn {
    padding: 5px 10px;
    font-size: 11px;
  }
  
  #ui .row-help #helpBtn .help-label,
  #ui .row-help #tutorialBtn .help-label {
    font-size: 11px;
  }
  
  /* Help Modal - compact but wide enough */
  #helpModal {
    width: 320px;
    max-width: 92vw;
    padding: 14px 16px 14px;
  }
  
  .help-row .txt { font-size: 12px; }
  .kbd, .kbd-wide { font-size: 10px; padding: 0 5px; }
  
  .hud-bar {
    padding: 6px 8px;
    left: 8px;
    right: 8px;
    bottom: 10px;
    border-radius: 999px;
  }
  .hud-bar .hud-btn {
    padding: 5px 6px;
    font-size: 12px;
    min-width: 36px;
    min-height: 36px;
  }
  .hud-bar .hud-icon img {
    width: 14px;
    height: 14px;
  }
  .hud-bar .hud-sep {
    margin: -6px 4px;
    align-self: stretch;
  }
  .hud-bar .hud-pill {
    font-size: 12px;
  }
  .hud-bar .hud-pill-count {
    padding: 3px 8px;
    min-width: 42px;
  }
  .hud-bar .hud-pill-count #hudCnt {
    font-size: 14px;
  }
  .hud-bar .hud-pill-count .hud-pill-caption {
    font-size: 10px;
  }
}

/* Very narrow: hud-bar + panel + help compact */
@media (max-width: 400px) {
  .hud-bar {
    padding: 5px 6px;
    left: 6px;
    right: 6px;
    bottom: 8px;
    border-radius: 999px;
  }
  .hud-bar .hud-btn {
    padding: 4px 5px;
    font-size: 11px;
    min-width: 32px;
    min-height: 32px;
  }
  .hud-bar .hud-icon img { width: 12px; height: 12px; }
  .hud-bar .hud-sep { margin: -5px 3px; align-self: stretch; }
  .hud-bar .hud-pill { font-size: 11px; }
  .hud-bar .hud-pill-count { padding: 2px 6px; min-width: 38px; }
  .hud-bar .hud-pill-count #hudCnt { font-size: 13px; }
  .hud-bar .hud-pill-count .hud-pill-caption { font-size: 9px; }
  .hud-bar #continueBtn { padding: 5px 8px; font-size: 11px; }
  
  .brand { width: 140px; }
  .brand .brand-logo { width: 90px; }
  #ui.panel {
    top: 45px;
    left: 6px;
    width: 140px;
    padding: 8px 8px 10px;
  }
  #ui .panel-actions .icon-btn { width: 22px; height: 22px; }
  #ui .gallery .card canvas { height: 45px; }
  #ui .row.row-palette #palette { padding: 6px 8px; gap: 4px; }
  #ui .row.row-palette #palette .dot { width: 20px; height: 20px; }
  #ui .row-help #helpBtn,
  #ui .row-help #tutorialBtn { padding: 4px 8px; font-size: 10px; }
  #ui .row-help #helpBtn .help-label,
  #ui .row-help #tutorialBtn .help-label { font-size: 10px; }
  #sideNav {
    min-width: 320px;
    max-width: 100vw;
    padding: 16px 16px 20px 41px;
  }
  .sideNav-list { font-size: 16px; margin-top: 50px !important; gap: 12px; }
  .sideNav-list li { padding: 12px 0; }
  #helpModal { width: 280px; padding: 10px 12px 10px; }
  .help-row .txt { font-size: 10px; }
  .kbd, .kbd-wide { height: 16px; padding: 0 3px; font-size: 8px; }
  #helpStart { padding: 10px 12px; font-size: 13px; }
  #helpTutorialBtn { padding: 8px 10px; font-size: 11px; gap: 6px; }
  #helpTutorialBtn .tutorial-icon { width: 14px; height: 14px; }
}

/* Small Help Modal */
@media (max-width: 520px) {
  #helpModal {
    width: 300px;
    max-width: 90vw;
    padding: 12px 14px 12px;
  }
  
  .help-title { margin-bottom: 10px; padding-bottom: 8px; }
  .help-row { padding: 3px 0; column-gap: 8px; }
  .help-row .txt { font-size: 11px; line-height: 1.3; }
  .help-row .ico { height: 20px; }
  .help-row .ico img.icon-img { height: 20px; }
  .help-subtitle { font-size: 10px; }
  .help-actions { margin-top: 12px; padding-top: 10px; }
  #helpStart { font-size: 14px; padding: 12px 14px; }
  #helpTutorialBtn { font-size: 12px; padding: 10px 12px; gap: 7px; }
  #helpTutorialBtn .tutorial-icon { width: 16px; height: 16px; }
  .kbd, .kbd-wide { height: 18px; padding: 0 4px; font-size: 9px; }
}

/* Short Screens */
@media (max-height: 700px) {
  /* Keep brand aligned on short screens (e.g., 1024×663) */
  .brand { top: 6px; }
  .brand .brand-logo { width: 110px; }

  /* Quick start (Help) button below the cube list */
  #ui .row-help { margin-top: 8px; }
  #ui .row-help #helpBtn,
  #ui .row-help #tutorialBtn {
    padding: 6px 12px;
    gap: 6px;
    white-space: nowrap;
    font-size: 12px;
  }
  #ui .row-help #helpBtn .icon-img,
  #ui .row-help #helpBtn svg,
  #ui .row-help #helpBtn img,
  #ui .row-help #tutorialBtn .icon-img,
  #ui .row-help #tutorialBtn svg {
    width: 0.72em !important;
    height: 0.72em !important;
  }
  #ui .row-help #helpBtn .help-label,
  #ui .row-help #tutorialBtn .help-label { font-size: 12px; }

  /* Help modal (Quick start) – slightly more compact for short viewports */
  #helpModal {
    max-height: 90vh;
    padding: 16px 18px 16px;
  }
  .help-row .txt { font-size: 13px; }
  #helpStart { padding: 14px 18px; font-size: 16px; }
  #helpTutorialBtn { padding: 12px 16px; font-size: 14px; gap: 8px; }
  #helpTutorialBtn .tutorial-icon { width: 18px; height: 18px; }

  #ui.panel {
    top: 50px;
    max-height: calc(100vh - 60px);
  }
  
  #ui .gallery .card canvas { height: 55px; }
  
  #ui .row.row-palette #palette {
    padding: 6px 8px;
    gap: 5px;
  }
  
  #ui .row.row-palette #palette .dot {
    width: 22px;
    height: 22px;
  }
}

@media (max-height: 600px) {
  .brand { top: 6px; }
  .brand .brand-logo { width: 90px; }
  
  #ui.panel {
    top: 40px;
    max-height: calc(100vh - 50px);
    padding: 8px 10px 10px;
  }
  
  #ui .panel-actions { gap: 4px; margin-bottom: 6px; }
  
  #ui .gallery { gap: 4px; }
  #ui .gallery .card canvas { height: 45px; }
  
  #ui .row.row-palette { margin-top: 6px; }
  #ui .row.row-palette #palette .dot {
    width: 20px;
    height: 20px;
  }
  
  #ui .row-help { margin-top: 6px; }
  #ui .row-help #helpBtn,
  #ui .row-help #tutorialBtn { padding: 4px 8px; }
  
  #helpModal {
    max-height: 90vh;
    padding: 10px 12px 10px;
  }
  .help-row { padding: 2px 0; }
  .help-actions { margin-top: 8px; padding-top: 8px; }
  #helpStart { padding: 10px 14px; font-size: 14px; }
  #helpTutorialBtn { padding: 8px 12px; font-size: 12px; gap: 6px; }
  #helpTutorialBtn .tutorial-icon { width: 14px; height: 14px; }
}

@media (max-height: 500px) {
  #ui.panel {
    top: 35px;
    max-height: calc(100vh - 45px);
  }
  
  #ui .gallery .card canvas { height: 40px; }
  
  #sideNav { padding-top: 12px; padding-bottom: 12px; }
  .sideNav-list { margin-top: 40px !important; gap: 8px; }
  .sideNav-list li { padding: 10px 0; }
}

/* Language-specific width */
@media (min-width: 601px) {
  html[data-lang="en"] #sideNav { width: min(460px, 100vw); }
}

/* Print styles - hide interactive elements */
@media print {
  #appHeader, #ui.panel, #sideNav, #navOverlay, 
  #helpOverlay, #helpModal, #editor { display: none !important; }
}

/* ========================================
   Zoom 200%+ / Small viewport (v3)
   Help (Quick start) modal: compact centered layout
   ======================================== */
@media (max-width: 560px), (max-height: 520px) {
  #helpModal {
    width: fit-content !important;
    min-width: 0 !important;
  }

  #helpModal .help-subtitle {
    margin: 8px 0 4px;
    font-size: 11px;
  }

  #helpModal .help-row {
    column-gap: 10px;
  }

  #helpModal .help-row .txt,
  #helpModal .help-row > div:last-child {
    font-size: 13px;
    line-height: 1.3;
  }
}

/* ========================================
   Help / Quick start – Adaptive compact layout
   Goal: fit content, no scroll, centered
   ======================================== */
#helpModal{
  /* Always constrain to viewport */
  max-height: calc(100vh - 24px);
  max-width: calc(100vw - 24px);
  /* Delegate scrolling to .help-grid so Start stays visible */
  overflow: hidden;
  /* Stable layout under zoom */
  display: flex;
  flex-direction: column;
}

#helpModal .help-grid{
  flex: 1 1 auto;
  min-height: 0; /* critical for overflow inside flex */
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-right: 6px;
}

#helpModal .help-actions{
  flex: 0 0 auto;
}

#helpModal .help-actions #helpStart,
#helpModal .help-actions #helpTutorialBtn{
  width: 100%;
}

/* ========================================
   Adaptive Help Modal - Viewport Scaling
   Scales all content proportionally to fit
   No scroll, always centered, compact width
   ======================================== */

/* Medium viewports - slight reduction */
@media (max-width: 600px), (max-height: 600px) {
  #helpModal {
    position: fixed !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: fit-content !important;
    min-width: 0 !important;
    max-width: calc(100vw - 20px) !important;
    max-height: calc(100vh - 20px) !important;
    padding: clamp(10px, 3vmin, 20px) clamp(12px, 3.5vmin, 24px) !important;
    overflow: hidden !important;
  }

  .help-open #helpModal {
    transform: translate(-50%, -50%) scale(1) !important;
  }

  #helpModal .help-grid {
    overflow-y: auto !important;
    max-height: calc(100vh - 140px) !important;
  }

  #helpModal .help-title {
    margin-bottom: clamp(6px, 1.5vmin, 12px) !important;
    padding-bottom: clamp(6px, 1.5vmin, 10px) !important;
  }

  #helpModal .help-title .txt {
    font-size: clamp(10px, 2.5vmin, 14px) !important;
    letter-spacing: 0.1em !important;
  }

  #helpModal #helpClose {
    width: clamp(22px, 5vmin, 28px) !important;
    height: clamp(22px, 5vmin, 28px) !important;
  }

  #helpModal .help-subtitle {
    margin: clamp(6px, 1.5vmin, 10px) 0 clamp(3px, 0.8vmin, 6px) !important;
    font-size: clamp(9px, 2vmin, 12px) !important;
  }

  #helpModal .help-row {
    padding: clamp(2px, 0.6vmin, 4px) 0 !important;
    column-gap: clamp(8px, 2vmin, 14px) !important;
  }

  #helpModal .help-row .ico {
    height: clamp(20px, 5vmin, 28px) !important;
    flex-shrink: 0 !important;
  }

  #helpModal .help-row .ico img.icon-img {
    height: clamp(20px, 5vmin, 28px) !important;
  }

  #helpModal .help-row > div:last-child,
  #helpModal .help-row .txt {
    font-size: clamp(11px, 2.5vmin, 14px) !important;
    line-height: 1.3 !important;
    white-space: nowrap !important;
  }

  #helpModal .kbd,
  #helpModal .kbd-wide {
    height: clamp(18px, 4vmin, 22px) !important;
    padding: 0 clamp(4px, 1vmin, 6px) !important;
    font-size: clamp(9px, 2vmin, 11px) !important;
  }

  #helpModal .kbd-row {
    gap: clamp(2px, 0.5vmin, 4px) !important;
  }

  #helpModal .ico.two {
    gap: clamp(4px, 1vmin, 6px) !important;
  }

  #helpModal .help-actions {
    margin-top: clamp(8px, 2vmin, 12px) !important;
    padding-top: clamp(8px, 2vmin, 10px) !important;
  }

  #helpModal .help-actions #helpStart {
    padding: clamp(10px, 2.5vmin, 16px) clamp(16px, 4vmin, 24px) !important;
    font-size: clamp(12px, 3vmin, 16px) !important;
  }
  
  #helpModal .help-actions #helpTutorialBtn {
    padding: clamp(8px, 2vmin, 12px) clamp(14px, 3.5vmin, 20px) !important;
    font-size: clamp(11px, 2.8vmin, 14px) !important;
    gap: clamp(6px, 1.5vmin, 8px) !important;
  }
  
  #helpModal .help-actions #helpTutorialBtn .tutorial-icon {
    width: clamp(16px, 2.5vmin, 18px) !important;
    height: clamp(16px, 2.5vmin, 18px) !important;
  }
}

/* Small viewports - more compact */
@media (max-width: 480px), (max-height: 480px) {
  #helpModal {
    padding: clamp(8px, 2.5vmin, 16px) clamp(10px, 3vmin, 18px) !important;
    border-radius: var(--radius-lg) !important;
  }

  #helpModal .help-grid {
    max-height: calc(100vh - 120px) !important;
    padding-right: 4px !important;
  }

  #helpModal .help-title .txt {
    font-size: clamp(9px, 2.2vmin, 12px) !important;
  }

  #helpModal .help-subtitle {
    font-size: clamp(8px, 1.8vmin, 10px) !important;
  }

  #helpModal .help-row .ico {
    height: clamp(18px, 4.5vmin, 24px) !important;
  }

  #helpModal .help-row .ico img.icon-img {
    height: clamp(18px, 4.5vmin, 24px) !important;
  }

  #helpModal .help-row > div:last-child,
  #helpModal .help-row .txt {
    font-size: clamp(10px, 2.2vmin, 13px) !important;
  }

  #helpModal .kbd,
  #helpModal .kbd-wide {
    height: clamp(16px, 3.5vmin, 20px) !important;
    font-size: clamp(8px, 1.8vmin, 10px) !important;
  }

  #helpModal .help-actions #helpStart {
    padding: clamp(8px, 2vmin, 14px) clamp(12px, 3vmin, 20px) !important;
    font-size: clamp(11px, 2.5vmin, 14px) !important;
  }
  
  #helpModal .help-actions #helpTutorialBtn {
    padding: clamp(6px, 1.5vmin, 10px) clamp(10px, 2.5vmin, 16px) !important;
    font-size: clamp(10px, 2.2vmin, 12px) !important;
    gap: clamp(5px, 1.2vmin, 7px) !important;
  }
  
  #helpModal .help-actions #helpTutorialBtn .tutorial-icon {
    width: clamp(14px, 2vmin, 16px) !important;
    height: clamp(14px, 2vmin, 16px) !important;
  }
}

/* Very small viewports (high zoom 300%+) */
@media (max-width: 380px), (max-height: 380px) {
  #helpModal {
    padding: clamp(6px, 2vmin, 12px) clamp(8px, 2.5vmin, 14px) !important;
    border-radius: var(--radius-sm) !important;
  }

  #helpModal .help-grid {
    max-height: calc(100vh - 100px) !important;
  }

  #helpModal .help-title {
    margin-bottom: clamp(4px, 1vmin, 8px) !important;
    padding-bottom: clamp(4px, 1vmin, 8px) !important;
  }

  #helpModal .help-title .txt {
    font-size: clamp(8px, 2vmin, 11px) !important;
  }

  #helpModal #helpClose {
    width: clamp(18px, 4.5vmin, 24px) !important;
    height: clamp(18px, 4.5vmin, 24px) !important;
  }

  #helpModal .help-subtitle {
    margin: clamp(4px, 1vmin, 8px) 0 clamp(2px, 0.5vmin, 4px) !important;
    font-size: clamp(7px, 1.6vmin, 9px) !important;
  }

  #helpModal .help-row {
    padding: clamp(1px, 0.4vmin, 3px) 0 !important;
    column-gap: clamp(6px, 1.5vmin, 10px) !important;
  }

  #helpModal .help-row .ico {
    height: clamp(16px, 4vmin, 22px) !important;
  }

  #helpModal .help-row .ico img.icon-img {
    height: clamp(16px, 4vmin, 22px) !important;
  }

  #helpModal .help-row > div:last-child,
  #helpModal .help-row .txt {
    font-size: clamp(9px, 2vmin, 12px) !important;
  }

  #helpModal .kbd,
  #helpModal .kbd-wide {
    height: clamp(14px, 3vmin, 18px) !important;
    padding: 0 clamp(3px, 0.8vmin, 5px) !important;
    font-size: clamp(7px, 1.5vmin, 9px) !important;
  }

  #helpModal .help-actions {
    margin-top: clamp(6px, 1.5vmin, 10px) !important;
    padding-top: clamp(6px, 1.5vmin, 8px) !important;
  }

  #helpModal .help-actions #helpStart {
    padding: clamp(6px, 1.5vmin, 12px) clamp(10px, 2.5vmin, 16px) !important;
    font-size: clamp(10px, 2.2vmin, 13px) !important;
    border-radius: var(--radius-md) !important;
  }
  
  #helpModal .help-actions #helpTutorialBtn {
    padding: clamp(5px, 1.2vmin, 10px) clamp(8px, 2vmin, 14px) !important;
    font-size: clamp(9px, 2vmin, 11px) !important;
    border-radius: var(--radius-sm) !important;
    gap: clamp(4px, 1vmin, 6px) !important;
  }
  
  #helpModal .help-actions #helpTutorialBtn .tutorial-icon {
    width: clamp(12px, 1.8vmin, 14px) !important;
    height: clamp(12px, 1.8vmin, 14px) !important;
  }
}

/* Tiny viewports (zoom 400-500%) */
@media (max-width: 300px), (max-height: 300px) {
  #helpModal {
    padding: 6px 8px !important;
    border-radius: var(--radius-sm) !important;
    max-width: calc(100vw - 12px) !important;
    max-height: calc(100vh - 12px) !important;
  }

  #helpModal .help-grid {
    max-height: calc(100vh - 80px) !important;
    padding-right: 2px !important;
  }

  #helpModal .help-title {
    margin-bottom: 4px !important;
    padding-bottom: 4px !important;
  }

  #helpModal .help-title .txt {
    font-size: 8px !important;
    letter-spacing: 0.08em !important;
  }

  #helpModal #helpClose {
    width: 16px !important;
    height: 16px !important;
    font-size: 10px !important;
  }

  #helpModal .help-subtitle {
    margin: 4px 0 2px !important;
    font-size: 7px !important;
  }

  #helpModal .help-row {
    padding: 1px 0 !important;
    column-gap: 5px !important;
  }

  #helpModal .help-row .ico {
    height: 14px !important;
  }

  #helpModal .help-row .ico img.icon-img {
    height: 14px !important;
  }

  #helpModal .help-row > div:last-child,
  #helpModal .help-row .txt {
    font-size: 8px !important;
    line-height: 1.2 !important;
  }

  #helpModal .kbd,
  #helpModal .kbd-wide {
    height: 12px !important;
    padding: 0 2px !important;
    font-size: 6px !important;
    border-radius: var(--radius-sm) !important;
  }

  #helpModal .kbd-row {
    gap: 1px !important;
  }

  #helpModal .ico.two {
    gap: 2px !important;
  }

  #helpModal .help-actions {
    margin-top: 4px !important;
    padding-top: 4px !important;
  }

  #helpModal .help-actions #helpStart {
    padding: 6px 10px !important;
    font-size: 9px !important;
    border-radius: var(--radius-sm) !important;
  }
  
  #helpModal .help-actions #helpTutorialBtn {
    padding: 5px 8px !important;
    font-size: 8px !important;
    border-radius: var(--radius-sm) !important;
    gap: 4px !important;
  }
  
  #helpModal .help-actions #helpTutorialBtn .tutorial-icon {
    width: 10px !important;
    height: 10px !important;
  }
}

/* ========================================
   Continue Button
   Десктоп: фиксированная кнопка внизу справа. Мобильная (touch-mode): в hud-bar.
   ======================================== */
#continueBtn {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 184px;
  padding: 16px 30px;
  text-align: center;
  background: #0B8C5D;
  border: 1px solid #ffffff;
  border-radius: 999px;
  box-shadow: none;
  color: #ffffff;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.25;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  cursor: pointer;
  outline: none;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
#continueBtn:focus {
  outline: none;
}
#continueBtn:hover {
  background: rgba(11, 140, 93, 0.92);
  border-color: #ffffff;
  transform: translateY(-2px);
}
#continueBtn:active {
  transform: translateY(0);
  background: rgba(11, 140, 93, 0.88);
}
#continueBtn .continue-text {
  display: inline-block;
  margin: 0;
  padding: 0;
}
#continueBtn .continue-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin: 0;
  padding: 0;
  color: inherit;
}
#continueBtn .continue-icon svg {
  display: block;
  width: 18px;
  height: 18px;
  margin: 0;
}
@media (max-width: 768px) {
  #continueBtn {
    right: 16px;
    bottom: 16px;
    min-width: 161px;
    padding: 14px 25px;
    font-size: 17px;
  }
  #continueBtn .continue-icon svg {
    width: 16px;
    height: 16px;
  }
}
@media (max-width: 540px) {
  #continueBtn {
    right: 12px;
    bottom: 12px;
    min-width: 138px;
    padding: 13px 21px;
    font-size: 16px;
  }
  #continueBtn .continue-icon svg {
    width: 15px;
    height: 15px;
  }
}

/* Только в touch-mode: Continue внутри hud-bar, без закруглений, заполняет правую часть до краёв */
body.touch-mode .hud-bar #continueBtn {
  position: static;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 0;
  padding: 10px calc(12px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) 20px;
  margin: -10px 0 calc(-10px - env(safe-area-inset-bottom)) 0;
  align-self: stretch;
  background: #0B8C5D !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  outline: none;
  color: #ffffff;
  font-size: 19px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
body.touch-mode .hud-bar #continueBtn:focus,
body.touch-mode .hud-bar #continueBtn:focus-visible {
  outline: none !important;
  box-shadow: none !important;
  -webkit-tap-highlight-color: transparent;
}
/* Убрать любую обводку/кольцо фокуса на мобиле */
body.touch-mode .hud-bar #continueBtn::-moz-focus-inner {
  border: 0;
  padding: 0;
}
body.touch-mode .hud-bar #continueBtn:hover {
  background: rgba(11, 140, 93, 0.9);
  transform: none;
}
body.touch-mode .hud-bar #continueBtn:active {
  transform: scale(0.98);
  background: rgba(11, 140, 93, 0.85);
}
body.touch-mode .hud-bar #continueBtn .continue-icon svg {
  width: 22px;
  height: 22px;
}

/* AI Editor в hud-bar: высота как у Continue (stretch), десктоп — до палитры; мобильная — без изменений */
.hud-bar #aiToggleFloat {
  align-self: stretch;
}
body.touch-mode .hud-bar #aiToggleFloat {
  flex: 0 0 auto;
  min-width: 138px;
  align-self: center;
}
/* Десктоп: обе кнопки stretch — одинаковая высота (верх/низ) */
.hud-bar #continueBtn {
  align-self: stretch;
  margin-left: auto;
}
body.touch-mode .hud-bar #continueBtn {
  align-self: stretch;
}

/* Мобильная версия: hud-bar без закруглений, на всю ширину и вплотную к низу */
body.touch-mode .hud-bar {
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  border-radius: 0 !important;
  border: none !important;
  padding-left: 12px;
  padding-right: 0;
  padding-top: 10px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  align-items: stretch;
}
body.touch-mode .hud-bar .hud-btn:not(#continueBtn),
body.touch-mode .hud-bar .hud-pill {
  align-self: center;
}
/* Разделители между Load, Save, Cubiks, Price — оставляем stretch для видимости */
body.touch-mode .hud-bar .hud-sep {
  align-self: stretch;
}

/* ========================================
   iOS input zoom fix (font-size >= 16px)
   Safari auto-zooms on focus when font-size < 16px
   ======================================== */
@media (max-width: 767px) {
  input[type="text"],
  input[type="search"],
  input[type="email"],
  input[type="url"],
  input[type="number"],
  input[type="tel"],
  input[type="password"],
  textarea {
    font-size: 16px !important;
    line-height: 1.4;
  }
  #projectModal .project-modal-body input {
    font-size: 16px !important;
  }
}
