/* Анатомика — общая оболочка и полировка интерфейса. Подключается последней и аккуратно
   переопределяет старые правила: шапка без переполнения, плавные переходы, нижнее меню на телефоне. */

/* ---------- шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; gap: clamp(10px, 1.4vw, 23px);
  background: color-mix(in srgb, var(--panel) 84%, transparent) !important;
  -webkit-backdrop-filter: saturate(1.4) blur(16px); backdrop-filter: saturate(1.4) blur(16px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 80%, transparent) !important;
}
.workspace-nav { min-width: 0; }
.workspace-nav button { transition: color .15s, background-color .15s; border-radius: 8px 8px 0 0; }
.workspace-nav button:hover { background: color-mix(in srgb, var(--text) 7%, transparent) !important; color: var(--text); }
.workspace-nav button[aria-current]:hover { color: var(--accent); }
.top-actions { gap: 8px; flex-shrink: 0; }
.brand-icon { transition: transform .4s cubic-bezier(.2, .8, .2, 1); }
.brand:hover .brand-icon { transform: rotate(-18deg) scale(1.04); }

/* 1251–1700 px: подписи у «Избранное» и «Экспорт» прячем, поиск компактнее */
@media (max-width: 1700px) and (min-width: 1251px) {
  .top-plain:not(.account-trigger) .action-text { display: none; }
  .top-plain:not(.account-trigger) { width: 36px; padding: 0; justify-content: center; }
  .top-search { width: clamp(170px, 13vw, 240px); }
  .workspace-nav button { padding-inline: 9px; }
}
@media (max-width: 1460px) and (min-width: 1251px) {
  .top-search { width: 38px; padding: 0; justify-content: center; }
  .top-search > span:not([data-icon]), .top-search kbd { display: none; }
  .account-trigger .profile-name { display: none; }
  .account-trigger { padding: 0 4px !important; }
}
@media (max-width: 1250px) {
  .account-trigger .profile-name { display: none; }
  .account-trigger { padding: 0 4px !important; width: auto !important; }
}

/* ---------- общие мелочи ---------- */
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }
button, a, select, input { transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s; }
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--muted) 35%, transparent) transparent; }
.panel { box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 4%, transparent), 0 18px 40px -28px #000c; }
:root[data-theme="paper"] .panel { box-shadow: 0 1px 0 #fff inset, 0 14px 34px -26px #2a3a3655; }
.toast { border-radius: 12px !important; padding: 11px 16px !important; font-size: 13px !important; background: var(--panel-2) !important; color: var(--text) !important; border-color: color-mix(in srgb, var(--accent) 45%, var(--line)) !important; animation: toast-in .3s cubic-bezier(.2, .8, .2, 1); z-index: 60 !important; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* плавное появление раздела при переключении */
main.workspace:not([hidden]) { animation: workspace-in .38s cubic-bezier(.2, .8, .2, 1); }
@keyframes workspace-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.process-svg-in { animation: workspace-in .5s cubic-bezier(.2, .8, .2, 1); }

/* загрузка 3D-модели: полоса прогресса под надписью */
.viewer-status { overflow: hidden; border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line)); background: color-mix(in srgb, var(--panel) 92%, transparent) !important; color: var(--text) !important; box-shadow: 0 16px 40px -18px #000a; }
.viewer-status::after { content: ""; position: absolute; left: 0; bottom: 0; height: 2px; width: var(--load, 0%); background: var(--accent-strong); transition: width .2s; }

/* галерея: мерцающая заглушка, пока картинка грузится */
.gallery-grid img { background: linear-gradient(100deg, var(--panel-2) 30%, color-mix(in srgb, var(--panel-2) 70%, var(--text) 8%) 50%, var(--panel-2) 70%) 0 0 / 300% 100%; animation: shimmer 1.6s linear infinite; }
.gallery-grid img[data-loaded] { animation: none; background: none; }
@keyframes shimmer { to { background-position: -150% 0; } }

/* сцена 3D: кнопки инструментов приятнее на ощупь */
.stage-tools .icon-btn, .stage-toggle .icon-btn { border-radius: 9px; }
.stage-tools .icon-btn:active, .stage-toggle .icon-btn:active { transform: scale(.94); }
.motion-start { transition: transform .15s, box-shadow .2s, background-color .15s; }
.motion-start[aria-pressed="true"] { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent), 0 0 24px color-mix(in srgb, var(--accent) 35%, transparent); }

@media (prefers-reduced-motion: reduce) {
  main.workspace:not([hidden]), .process-svg-in, .toast, .gallery-grid img { animation: none !important; }
}

/* ---------- телефон: разделы — в нижнем меню, как в приложении ---------- */
@media (max-width: 680px) {
  .topbar { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--panel) !important; }
  .workspace-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; order: initial; width: auto !important;
    display: flex; justify-content: space-around; gap: 0; min-height: 0; height: calc(62px + env(safe-area-inset-bottom));
    padding: 4px 4px env(safe-area-inset-bottom); overflow-x: auto; scrollbar-width: none;
    background: color-mix(in srgb, var(--panel) 94%, transparent); border-top: 1px solid var(--line);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); box-shadow: 0 -10px 30px -18px #000a;
  }
  .workspace-nav::-webkit-scrollbar { display: none; }
  .topbar { flex-wrap: nowrap !important; height: 56px !important; min-height: 0 !important; }
  .topbar .brand, .topbar .top-actions { height: 56px !important; }
  .brand { font-size: 18px; flex-shrink: 0; }
  .brand-icon { width: 31px; height: 31px; }
  .top-actions { gap: 3px !important; margin-left: auto; }
  .topbar .top-actions :is(.top-plain, .top-search, .theme-trigger, .help-btn) { width: 32px !important; min-height: 32px !important; height: 32px !important; padding: 0 !important; }
  .topbar .top-actions .account-trigger { width: 34px !important; border: 0; padding: 0 !important; justify-content: center; }
  .export-trigger { display: none !important; } /* экспорт есть в каждом разделе отдельной кнопкой */
  .workspace-nav button {
    flex: 1 0 auto; min-width: 50px; flex-direction: column; justify-content: center; gap: 4px !important;
    padding: 4px 2px !important; font-size: 10.5px !important; font-weight: 600; border-radius: 12px;
  }
  .workspace-nav button svg { display: block !important; width: 21px !important; height: 21px !important; }
  .workspace-nav button[aria-current] { background: color-mix(in srgb, var(--accent) 14%, transparent); }
  .workspace-nav button[aria-current]::after { display: none; }
  body { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  .gate-on body { padding-bottom: 0; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)) !important; left: 12px; right: 12px !important; text-align: center; }
}
