/*
 * Cubik Build 1.1 - Styles
 * 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: #e9fdf8;
  --muted: #91b3aa;
  --accent: #26a69a;
  --green: #22c55e;
  --red: #ef4444;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px rgba(0,0,0,.75);
  --edw: 380px;
}

/* =============================================================================
   Mobile placeholder (video + message + CTA)
   ============================================================================= */

#mobileVideoContainer{
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: radial-gradient(1200px 900px at 30% 20%, rgba(255,255,255,0.06), transparent 60%),
              radial-gradient(900px 700px at 80% 70%, rgba(255,255,255,0.04), transparent 55%),
              #000;
}

#mobileVideoContainer .mobile-card{
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

#mobileVideoContainer .mobile-video-wrap{
  width: 100%;
  border-radius: 18px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 18px 60px rgba(0,0,0,0.65);
}

#mobileVideo{
  display: block;
  width: 100%;
  height: auto;
  max-height: 56vh;
  object-fit: contain;
  background: #000;
}

#mobileVideoContainer .mobile-msg{
  font-size: 16px;
  line-height: 1.35;
  color: rgba(255,255,255,0.86);
}

#mobileVideoContainer .mobile-home-btn{
  width: 100%;
  max-width: 360px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 14px;
  border-radius: 14px;
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: #fff;
  background: linear-gradient(135deg, rgba(0,160,255,0.95), rgba(92,50,255,0.95));
  box-shadow: 0 14px 40px rgba(0,0,0,0.45);
}

#mobileVideoContainer .mobile-home-btn:active{
  transform: translateY(1px);
}

@media (max-width: 420px){
  #mobileVideoContainer{ padding: 14px; }
  #mobileVideoContainer .mobile-msg{ font-size: 15px; }
  #mobileVideo{ max-height: 52vh; }
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 0% 0%, #004d40 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: 18px;
  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: #dfe7f3;
}

.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: 16px;
  border: 1px solid rgba(255,255,255,0.22);
  box-shadow: 0 10px 26px rgba(0,0,0,0.66);
  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: 16px;
  border: none;
  padding: 12px 22px;
  background: radial-gradient(circle 80px at 80% -10%, #e0f2f1, #004d40);
  color: #ffffff;
  font-weight: 600;
  letter-spacing: .02em;
  box-shadow: 0 12px 30px rgba(0,0,0,.65);
  cursor: pointer;
  margin-top: 12px;
  font-size: 14px;
  min-height: 36px;
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}

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

#start:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 36px rgba(0,0,0,.8);
  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: 22px;
  border: 1px solid rgba(255,255,255,0.18);
  padding: 10px 18px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.7);
}

.hud-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border: none;
  border-radius: 14px;
  background: transparent;
  color: #e5e7eb;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

.hud-btn:hover { background: rgba(148,163,184,0.24); }

.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);
}

.hud-sep {
  width: 2px;
  height: 26px;
  margin: 0 12px;
  background: rgba(255, 255, 255, 0.527);
}

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

.hud-pill-clickable {
  cursor: pointer;
  padding: 4px 10px;
  margin: -4px -10px;
  border-radius: 8px;
  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-count span:first-child { font-weight: 600; }
.hud-pill-caption { opacity: .75; }
.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: 5px;
  cursor: pointer;
  padding: 0;
  position: relative;
}

.nav-toggle span {
  width: 19px;
  height: 3px;
  border-radius: 999px;
  background: #e5e7eb;
  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); }

.nav-close { display: none !important; }

#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;
  box-shadow: -24px 0 40px rgba(0,0,0,0.7);
  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 fills the width */
.sideNav-list {
  list-style: none;
  margin: 80px 0 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 20px;
  letter-spacing: 0.02em;
  width: 100%;
}

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;
}

.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,#22c55e);
  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: 18px;
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 22px 50px rgba(0,0,0,0.9);
  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;
  display: block;
}

#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;
  stroke: currentColor;
  fill: currentColor;
}

#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: #090909;
  border-radius: 16px;
  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 rgba(223, 250, 21, 0.9);
  background: rgba(216, 239, 71, 0.1);
  box-shadow: 0 0 0 1px rgba(250,204,21,0.12) inset, 0 0 24px rgba(0,0,0,0.8);
}

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

.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
   ======================================== */
#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;
}

#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 18px 18px 0;
  border-width: 1px 1px 1px 0;
  border-style: solid;
  border-color: rgba(255,255,255,0.10);
  box-shadow: 0 18px 38px rgba(0,0,0,0.9);
}

#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);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.9);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  flex-shrink: 0;
}

#ui .row.row-palette #palette .dot:hover {
  transform: scale(1.08);
  box-shadow: 0 0 0 2px rgba(148,163,184,0.9);
}

#ui .row.row-palette #palette .dot.active {
  box-shadow: 0 0 0 3px rgba(56,189,248,1);
}

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

#ui .row-help #helpBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.55);
  background: rgba(0,0,0,0.88);
  width: auto !important;
  height: auto !important;
  transform: none !important;
  position: static !important;
  left: auto !important;
  bottom: auto !important;
  color: #ff3b30;
}

#ui .row-help #helpBtn .icon-img,
#ui .row-help #helpBtn svg {
  width: 18px !important;
  height: 18px !important;
  color: #ff3b30;
  fill: currentColor;
}

#ui .row-help #helpBtn .help-label {
  font-size: 13px;
  line-height: 1;
  color: #e5e7eb;
}

/* Hidden Legacy Elements */
#toolbarToggle, #status, #statsBadge, #stats, 
#exportBtn, #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;
  box-shadow: -18px 0 40px rgba(0,0,0,0.9) !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; }

#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; }

/* 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: 16px !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(3, 1fr);
  gap: 10px;
  margin: 10px 0;
}

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

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

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

.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);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.9);
}

#editor #paletteFace .dot.active {
  box-shadow: 0 0 0 2px 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;
  box-shadow: 0 10px 34px rgba(0,0,0,.6) !important;
  padding: 12px 22px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}

#replaceBtn:hover { background: #050505 !important; }
#replaceBtn:active { 
  background: #0a0a0a !important; 
  box-shadow: 0 6px 20px rgba(0,0,0,.8) !important; 
}

/* Use Button */
body.editor-open #saveAsTypeBtn {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1000;
  border-radius: 16px;
  padding: 12px 22px;
  font-size: 18px;
  font-weight: 700;
  background: radial-gradient(circle 80px at 80% -10%, #e0f2f1, #004d40);
  color: #ffffff;
  box-shadow: 0 14px 34px rgba(0,0,0,0.85);
  animation: useTealPulse 1.8s ease-out infinite;
  border: none;
  cursor: pointer;
}

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

#saveAsTypeBtn:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 40px rgba(0,0,0,0.9);
}

#saveAsTypeBtn:active {
  transform: translateY(1px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.85);
}

@keyframes useTealPulse {
  0% { box-shadow: 0 0 0 0 rgba(38,166,154,.8); }
  70% { box-shadow: 0 0 0 12px rgba(38,166,154,0); }
  100% { box-shadow: 0 0 0 0 rgba(38,166,154,0); }
}

/* ========================================
   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: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  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: #dfe7f3;
  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: #e9f0ff;
  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-list {
  margin: 0;
  padding: 0;
  display: grid;
  row-gap: 8px;
}

.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;
}

.k {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  padding: 0 6px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.2) !important;
  background: #050505 !important;
  color: #ffffff !important;
  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;
  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;
  box-shadow: 0 10px 34px rgba(0,0,0,.6) !important;
  transition: transform .12s ease, box-shadow .12s ease;
}

#helpStart.glow, .helpPulse {
  animation: helpGlow 1.6s ease-in-out infinite;
}

@keyframes helpGlow {
  0% { box-shadow: 0 0 0 0 rgba(255,255,255,.35); }
  50% { box-shadow: 0 0 18px 4px rgba(255,255,255,.35); }
  100% { box-shadow: 0 0 0 0 rgba(255,255,255,.35); }
}

#helpStart:hover { background: #050505 !important; }
#helpStart:active { 
  background: #0a0a0a !important; 
  box-shadow: 0 6px 20px rgba(0,0,0,.8) !important; 
}

#helpCard {
  padding: 12px 16px 10px;
  max-height: 70vh;
}

#helpCard > :not(h2):not(#helpList):not(#helpClose) { display: none !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: 14px;
  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: 8px;
  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: 6px;
  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 (Void Cubes Animation)
   ======================================== */
#globalLoader {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 0% 0%, #004d40 0, #000810 55%, #000000 100%);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.loader-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
}

.legos {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.lego {
  position: absolute;
  width: 120px;
  height: 120px;
  transform: rotate(-23deg);
  border-radius: 20px;
  background:
    radial-gradient(circle at 0% 0%, #3fe9ff33 0, transparent 50%),
    radial-gradient(circle at 30% 20%, #26a69a, #004d40 60%, #001615 100%);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

.lego::before {
  content: "";
  position: absolute;
  inset: 18px;
  border-radius: 14px;
  border: 2px solid rgba(0, 0, 0, 0.65);
  box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.85), 0 0 18px rgba(0, 255, 200, 0.25);
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.15), transparent 60%),
    radial-gradient(circle at 70% 80%, rgba(0, 0, 0, 0.7), transparent 60%);
}

.blue {
  top: calc(50% - 15px);
  left: calc(50% - 140px);
  z-index: 1;
  animation: blue-move 10s infinite linear;
  filter: hue-rotate(0deg);
}

.red {
  top: calc(50% - 134px);
  left: calc(50% - 78px);
  z-index: 2;
  animation: red-move 10s infinite linear;
  filter: hue-rotate(40deg);
}

.yellow {
  top: calc(50% - 202px);
  left: calc(50% - 140px);
  z-index: 3;
  animation: yellow-move 10s infinite linear;
  filter: hue-rotate(80deg);
}

.loader-label {
  position: absolute;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  color: #c8f5eb;
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.8;
}

/* Loader Animations */
@keyframes blue-move {
  0% { top: calc(50% - 15px); left: calc(50% - 140px); z-index: 1; }
  3.334% { top: calc(50% + 100px); }
  6.668% { left: calc(50% + 180px); }
  10% { left: calc(50% + 180px); top: calc(50% - 290px); }
  13.336% { top: calc(50% - 290px); left: calc(50% - 78px); z-index: 3; }
  16.67% { top: calc(50% - 202px); left: calc(50% - 78px); z-index: 3; }
  33.337% { top: calc(50% - 134px); left: calc(50% - 78px); z-index: 2; }
  50% { top: calc(50% - 15px); left: calc(50% - 78px); z-index: 1; }
  53.334% { top: calc(50% + 100px); }
  56.668% { left: calc(50% - 400px); }
  60% { left: calc(50% - 200px); top: calc(50% - 290px); }
  63.336% { top: calc(50% - 290px); left: calc(50% - 140px); z-index: 3; }
  66.68% { top: calc(50% - 202px); left: calc(50% - 140px); z-index: 3; }
  83.35% { top: calc(50% - 83px); left: calc(50% - 137px); z-index: 2; }
}

@keyframes red-move {
  0% { top: calc(50% - 134px); left: calc(50% - 78px); z-index: 2; }
  16.67% { top: calc(50% - 15px); left: calc(50% - 78px); z-index: 1; }
  20% { top: calc(50% + 100px); }
  23.338% { left: calc(50% - 400px); }
  26.672% { left: calc(50% - 200px); top: calc(50% - 290px); }
  30% { top: calc(50% - 290px); left: calc(50% - 140px); z-index: 3; }
  33.337% { top: calc(50% - 202px); left: calc(50% - 140px); z-index: 3; }
  50% { top: calc(50% - 83px); left: calc(50% - 137px); z-index: 2; }
  66.68% { top: calc(50% - 15px); left: calc(50% - 140px); z-index: 1; }
  70.014% { top: calc(50% + 100px); }
  73.348% { left: calc(50% + 168px); }
  76.68% { left: calc(50% + 168px); top: calc(50% - 290px); }
  80.016% { top: calc(50% - 290px); left: calc(50% - 78px); z-index: 3; }
  83.35% { top: calc(50% - 202px); left: calc(50% - 78px); z-index: 3; }
}

@keyframes yellow-move {
  0% { top: calc(50% - 202px); left: calc(50% - 140px); z-index: 3; }
  16.67% { top: calc(50% - 83px); left: calc(50% - 137px); z-index: 2; }
  33.337% { top: calc(50% - 15px); left: calc(50% - 140px); z-index: 1; }
  36.671% { top: calc(50% + 100px); }
  40% { left: calc(50% + 168px); }
  43.339% { left: calc(50% + 168px); top: calc(50% - 290px); }
  46.673% { top: calc(50% - 290px); left: calc(50% - 78px); z-index: 3; }
  50% { top: calc(50% - 202px); left: calc(50% - 78px); z-index: 3; }
  66.68% { top: calc(50% - 134px); left: calc(50% - 78px); z-index: 2; }
  83.35% { top: calc(50% - 15px); left: calc(50% - 78px); z-index: 1; }
  86.684% { top: calc(50% + 100px); }
  90.018% { left: calc(50% - 400px); }
  93.352% { left: calc(50% - 200px); top: calc(50% - 290px); z-index: 1; }
  96.686% { top: calc(50% - 290px); left: calc(50% - 140px); z-index: 3; }
}

/* ========================================
   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;
  }
  
  #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 */
  #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; }
  .k { height: 22px; padding: 0 6px; font-size: 11px; white-space: nowrap; }
  
  #sideNav { 
    min-width: 380px;
    max-width: 100vw; 
    padding: 20px 20px 24px; 
  }
  .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 {
    padding: 5px 10px;
  }
  
  #ui .row-help #helpBtn .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; }
  .k { font-size: 10px; padding: 0 5px; }
  
  .hud-label { display: none; }
  .hud-sep { margin: 0 6px; }
}

/* 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; }
  .k { height: 18px; padding: 0 4px; font-size: 9px; }
}

/* Very Small Screens */
@media (max-width: 400px) {
  .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 {
    padding: 4px 8px;
  }
  
  #ui .row-help #helpBtn .help-label {
    font-size: 10px;
  }
  
  #sideNav { 
    min-width: 320px;
    max-width: 100vw;
    padding: 16px 16px 20px; 
  }
  .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; }
  .k { height: 16px; padding: 0 3px; font-size: 8px; }
  #helpStart { padding: 10px 12px; font-size: 13px; }
}

/* 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 {
    padding: 6px 12px;
    gap: 6px;
    white-space: nowrap;
  }
  #ui .row-help #helpBtn .icon-img,
  #ui .row-help #helpBtn svg {
    width: 16px !important;
    height: 16px !important;
  }
  #ui .row-help #helpBtn .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; }

  #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 { 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; }
}

@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); }
}

/* ========================================
   Zoom Scaling Support (100% - 500%)
   Using viewport units for consistent scaling
   ======================================== */

/* Panel uses viewport-relative positioning */
#ui.panel {
  /* Already uses fixed positioning */
  /* Content scales naturally with browser zoom */
}

/* Palette attached to panel - stays connected at all zoom levels */
#ui .row.row-palette {
  /* Uses absolute positioning relative to panel */
  /* Maintains relationship at any zoom */
}

/* Ensure all elements use relative units where possible */
#ui .gallery .card canvas {
  /* Uses percentage width, fixed height for consistency */
}

/* 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{
  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 .k,
  #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;
  }
}

/* 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: clamp(10px, 3vmin, 16px) !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 .k,
  #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;
  }
}

/* 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: 10px !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 .k,
  #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: clamp(8px, 2vmin, 14px) !important;
  }
}

/* Tiny viewports (zoom 400-500%) */
@media (max-width: 300px), (max-height: 300px) {
  #helpModal {
    padding: 6px 8px !important;
    border-radius: 8px !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 .k,
  #helpModal .kbd,
  #helpModal .kbd-wide {
    height: 12px !important;
    padding: 0 2px !important;
    font-size: 6px !important;
    border-radius: 3px !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: 6px !important;
  }
}
