/* Fractal Forge 3D в стиле avr. Цвета, шрифты, радиусы и пружины — из brand/avr.css (роли Material 3);
   здесь только раскладка и компоненты приложения. Тема — тёмная, «ночное море». */
:root {
  --panel-w: 372px;
  --ease: var(--ease-spring, cubic-bezier(.34, 1.56, .64, 1));
  --font-ui: "Google Sans Flex", "Roboto Flex", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--surface-lowest); color: var(--on-surface); font: 420 14px/1.45 var(--font-ui); -webkit-font-smoothing: antialiased; font-feature-settings: "tnum"; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--outline); outline-offset: 2px; }

canvas#view { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; outline: none; touch-action: none; cursor: grab; }
canvas#view.dragging { cursor: grabbing; }
canvas#view.fly { cursor: crosshair; }

.ui { transition: opacity .25s ease, transform .45s var(--ease); }
body.ui-hidden .ui { opacity: 0; pointer-events: none; }
body.ui-hidden #panel { transform: translateX(24px); }
body.ui-hidden #toolbar:hover { opacity: 1; pointer-events: auto; }
.muted { color: var(--on-surface-variant); }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- прогресс накопления — волнистая полоска бренда ---------- */
#progress { position: fixed; left: 16px; top: 8px; right: calc(var(--panel-w) + 32px); height: 10px; z-index: 5; pointer-events: none; }
body.ui-hidden #progress { right: 16px; }
#progress::before { content: ""; position: absolute; left: 0; right: 0; top: 3px; height: 4px; border-radius: 99px; background: color-mix(in oklab, var(--secondary-container) 70%, transparent); }
#progress-fill {
  --heat: 0; --len: 32px;
  position: absolute; left: 0; top: 0; bottom: 0; width: calc(var(--heat) * 100%); background: var(--primary);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='10'%3E%3Cpath d='M0 5Q8 1.2 16 5T32 5' fill='none' stroke='%23000' stroke-width='3'/%3E%3C/svg%3E") 0 0 / var(--len) 10px repeat-x;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='10'%3E%3Cpath d='M0 5Q8 1.2 16 5T32 5' fill='none' stroke='%23000' stroke-width='3'/%3E%3C/svg%3E") 0 0 / var(--len) 10px repeat-x;
  animation: avr-wave 1.4s linear infinite; transition: width .15s linear, opacity .8s ease .6s;
}
#progress-fill.done { opacity: 0; animation: none; }

/* ---------- HUD ---------- */
.hud { position: fixed; left: 20px; top: 26px; z-index: 4; pointer-events: none; font: 500 12px/1.35 var(--font-ui); color: var(--on-surface-variant); font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px rgba(0,0,0,.7); }

/* ---------- панель ---------- */
#panel {
  position: fixed; right: 12px; top: 12px; bottom: 12px; width: var(--panel-w); z-index: 4;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border-radius: var(--r-xl, 34px);
}
.panel-head { padding: 18px 18px 0; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.brand .avr-star { width: 26px; height: 26px; }
.brand-name { font: 760 18px/1 var(--font-ui); font-variation-settings: "wght" 760, "wdth" 110, "ROND" 100; letter-spacing: -0.01em; color: var(--on-surface); }
.brand-ver { margin-left: auto; font: 500 12px var(--font-ui); color: var(--on-surface-variant); }
.brand-links { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 14px; }
.brand-links a { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: var(--r-full); text-decoration: none;
  font: 600 12.5px/1 var(--font-ui); background: var(--surface-high); color: var(--on-surface); transition: border-radius .3s var(--ease), background .2s; }
.brand-links a:hover { border-radius: 10px; background: var(--surface-highest); }
.brand-links a.dl { background: var(--primary); color: var(--on-primary); }
.brand-links .avr-star { width: 12px; height: 12px; }
.brand-links svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* поле сида — заполненное поле M3 */
.stamp { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: stretch; }
.stamp-field { position: relative; }
.stamp-field label { position: absolute; left: 16px; top: 8px; font: 600 11.5px var(--font-ui); color: var(--on-surface-variant); pointer-events: none; }
.stamp-field input {
  width: 100%; height: 52px; padding: 22px 16px 6px; border: 0; border-radius: 16px 16px 6px 6px;
  background: var(--surface-highest); box-shadow: inset 0 -2px 0 var(--outline); font: 500 15px var(--font-ui); color: var(--on-surface);
  transition: box-shadow .2s;
}
.stamp-field input:focus { outline: none; box-shadow: inset 0 -3px 0 var(--primary); }
.stamp .btn { height: 52px; }
.stamp .icon-btn { width: 52px; padding: 0; }

.tabs { display: flex; gap: 4px; margin: 14px 0 0; padding: 4px; background: var(--surface-low); border-radius: var(--r-full); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: auto; height: 36px; padding: 0 6px; border: 0; border-radius: var(--r-full); background: none; cursor: pointer;
  font: 620 12.5px var(--font-ui); font-variation-settings: "wght" 620, "wdth" 96; color: var(--on-surface-variant); white-space: nowrap; transition: background .2s, color .2s, border-radius .35s var(--ease);
}
.tabs button:hover { color: var(--on-surface); }
.tabs button[aria-selected=true] { background: var(--secondary-container); color: var(--on-secondary-container); }

.panel-body { flex: 1; overflow-y: auto; padding: 6px 18px 22px; scrollbar-width: thin; scrollbar-color: var(--outline-variant) transparent; }
.panel-body::-webkit-scrollbar { width: 8px; }
.panel-body::-webkit-scrollbar-thumb { background: var(--outline-variant); border-radius: 8px; }
.pane[hidden] { display: none; }

/* надпись над группой — «kicker» бренда */
.group-title { margin: 20px 0 6px; font: 620 12px/18px var(--font-ui); letter-spacing: .14em; text-transform: uppercase; color: var(--primary); }
.note { color: var(--on-surface-variant); font-size: 13px; margin: 4px 0 10px; text-wrap: pretty; }

/* ---------- ряды ---------- */
.row { display: grid; grid-template-columns: 116px 1fr 58px; align-items: center; gap: 10px; min-height: 34px; }
.row > label { color: var(--on-surface); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: default; }
.row.full { grid-template-columns: 116px 1fr; }
.row.check { grid-template-columns: 1fr auto; }

/* ползунок M3: толстая дорожка, заливка акцентом, ручка-палочка */
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; cursor: pointer; --pct: 50%; }
input[type=range]::-webkit-slider-runnable-track {
  height: 10px; border-radius: 99px;
  background: linear-gradient(90deg, var(--primary) 0 calc(var(--pct) - 3px), transparent calc(var(--pct) - 3px) calc(var(--pct) + 3px), var(--secondary-container) calc(var(--pct) + 3px));
}
input[type=range]::-moz-range-track { height: 10px; border-radius: 99px; background: var(--secondary-container); }
input[type=range]::-moz-range-progress { height: 10px; border-radius: 99px; background: var(--primary); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 4px; height: 24px; margin-top: -7px; border-radius: 4px; background: var(--primary); transition: width .2s var(--ease); }
input[type=range]::-moz-range-thumb { width: 4px; height: 24px; border: 0; border-radius: 4px; background: var(--primary); }
input[type=range]:active::-webkit-slider-thumb { width: 2px; }
input[type=range]:focus-visible { outline: none; }
input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px color-mix(in oklab, var(--primary) 30%, transparent); }

input.num {
  width: 100%; padding: 4px 6px; border: 0; border-radius: 8px; text-align: right; background: transparent;
  font: 500 12.5px var(--font-ui); color: var(--on-surface-variant); font-variant-numeric: tabular-nums;
}
input.num:hover { background: var(--surface-low); }
input.num:focus { outline: none; background: var(--surface-highest); color: var(--on-surface); }
input.num::-webkit-inner-spin-button { display: none; }

select, input.text {
  width: 100%; height: 40px; padding: 0 12px; border: 0; border-radius: 12px; background: var(--surface-high); color: var(--on-surface); font-size: 13.5px;
}
select { cursor: pointer; }
select option { background: var(--surface-low); }
select:focus, input.text:focus { outline: 2px solid var(--primary); outline-offset: 0; }

input[type=color] { -webkit-appearance: none; appearance: none; width: 100%; height: 32px; padding: 0; border: 0; border-radius: 10px; background: none; cursor: pointer; }
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch { border: 0; border-radius: 10px; }
.colors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

/* переключатель M3 */
.switch { position: relative; width: 52px; height: 32px; display: inline-block; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--surface-highest); box-shadow: inset 0 0 0 2px var(--outline); cursor: pointer; transition: background .2s; }
.switch span::before { content: ""; position: absolute; left: 8px; top: 8px; width: 16px; height: 16px; border-radius: 50%; background: var(--outline); transition: transform .35s var(--ease), width .35s var(--ease), height .35s var(--ease), left .35s var(--ease), top .35s var(--ease), background .2s; }
.switch input:checked + span { background: var(--primary); box-shadow: none; }
.switch input:checked + span::before { left: 4px; top: 4px; width: 24px; height: 24px; transform: translateX(20px); background: var(--on-primary); }
.switch input:focus-visible + span { outline: 2px solid var(--outline); outline-offset: 2px; }

/* ---------- кнопки-таблетки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 44px; padding: 0 20px; border: 0; border-radius: var(--r-full);
  background: var(--primary); color: var(--on-primary); cursor: pointer; font: 620 14px var(--font-ui); font-variation-settings: "wght" 620, "ROND" 50;
  transition: border-radius .35s var(--ease), transform .3s var(--ease), filter .2s;
}
.btn:hover { border-radius: 14px; filter: brightness(1.05); }
.btn:active { transform: scale(.95); }
.btn.ghost { background: var(--secondary-container); color: var(--on-secondary-container); }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btns { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; margin-top: 10px; }

/* ---------- типы — чипы ---------- */
.types { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 14px; }
.types button {
  display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px; text-align: left; cursor: pointer; border: 0;
  background: var(--surface-high); border-radius: var(--r-full); color: var(--on-surface); font: 560 13px var(--font-ui); white-space: nowrap; overflow: hidden;
  transition: border-radius .35s var(--ease), background .2s;
}
.types button span { overflow: hidden; text-overflow: ellipsis; }
.types button kbd { margin-left: auto; font: 500 11px var(--font-ui); color: var(--on-surface-variant); }
.types button:hover { background: var(--surface-highest); }
.types button.on { background: var(--secondary-container); color: var(--on-secondary-container); border-radius: 12px; }

/* ---------- палитры ---------- */
.palettes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 14px; }
.pal { position: relative; height: 34px; padding: 0; border: 0; border-radius: 12px; cursor: pointer; overflow: hidden; transition: border-radius .35s var(--ease); }
.pal span { position: absolute; left: 0; top: 0; bottom: 0; display: flex; align-items: center; padding: 0 12px; font: 600 12px var(--font-ui); color: #fff; background: linear-gradient(90deg, rgba(6,46,51,.85), rgba(6,46,51,0)); }
.pal:hover { border-radius: 18px; }
.pal.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--surface-low); border-radius: var(--r-full); }
.seg button { height: 36px; border: 0; border-radius: var(--r-full); background: none; color: var(--on-surface-variant); cursor: pointer; font: 600 13px var(--font-ui); }
.seg button.on { background: var(--secondary-container); color: var(--on-secondary-container); }

/* ---------- карточки режимов (без теней) ---------- */
.mode-card { padding: 16px 18px 12px; margin-top: 12px; border-radius: 26px; background: var(--surface-low); transition: border-radius .45s var(--ease), background .3s; }
.mode-card.on { background: var(--surface-high); border-radius: 34px; }
.mode-head { display: flex; align-items: center; gap: 10px; }
.mode-head b { font: 700 16px var(--font-ui); font-variation-settings: "wght" 700, "wdth" 106, "ROND" 80; }
.mode-head .btn { margin-left: auto; height: 36px; padding: 0 16px; font-size: 13px; }
.mode-card p { margin: 6px 0 8px; color: var(--on-surface-variant); font-size: 13px; }

/* ---------- архив ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  max-width: 100%; height: 32px; padding: 0 12px; border: 0; border-radius: var(--r-full); background: var(--surface-high); cursor: pointer;
  font: 500 12.5px var(--font-ui); color: var(--on-surface); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: border-radius .35s var(--ease);
}
.chip i { font-style: normal; color: var(--primary); margin-right: 6px; }
.chip:hover { border-radius: 10px; background: var(--surface-highest); }
.favs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fav { position: relative; aspect-ratio: 16 / 9; border-radius: 18px; cursor: pointer; background: #000 center / cover no-repeat; overflow: hidden; transition: border-radius .45s var(--ease), transform .45s var(--ease); }
.fav:hover { border-radius: 26px; transform: translateY(-2px); }
.fav span { position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 10px 6px; font: 500 11px var(--font-ui); color: var(--avr-mist); background: linear-gradient(transparent, rgba(6,46,51,.9)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fav b { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; line-height: 21px; text-align: center; border-radius: 50%; background: rgba(6,46,51,.85); color: var(--avr-mist); font-size: 13px; font-weight: 500; opacity: 0; transition: opacity .2s; }
.fav em { position: absolute; top: 6px; left: 6px; padding: 2px 10px; border-radius: 99px; background: var(--primary); color: var(--on-primary); font: normal 600 11px var(--font-ui); opacity: 0; transition: opacity .2s; }
.fav:hover b, .fav:hover em { opacity: 1; }
.empty { color: var(--on-surface-variant); font-size: 13px; padding: 2px 0 6px; }

/* ---------- островок с действиями ---------- */
#toolbar {
  position: fixed; bottom: 16px; left: calc((100vw - var(--panel-w) - 24px) / 2); transform: translateX(-50%); z-index: 4;
  display: flex; align-items: center; gap: 2px; padding: 6px 8px; border-radius: var(--r-full); background: var(--surface-mid); box-shadow: 0 6px 18px rgba(0,0,0,.28);
}
#toolbar button, #toolbar a { position: relative; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: var(--r-full); background: none; color: var(--on-surface-variant); cursor: pointer; transition: border-radius .35s var(--ease), background .2s; }
#toolbar button:hover, #toolbar a:hover { background: var(--surface-highest); color: var(--on-surface); }
#toolbar button.on { background: var(--secondary-container); color: var(--on-secondary-container); border-radius: 12px; }
#toolbar svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#toolbar .sep { width: 1px; height: 20px; margin: 0 4px; background: var(--outline-variant); }
#toolbar button[data-act=record].on { color: var(--error); }
#toolbar button[data-act=record].on .rec-dot { fill: currentColor; }
body.ui-hidden #toolbar { left: 50%; }

#hint { position: fixed; left: 20px; bottom: 20px; z-index: 3; max-width: calc((100vw - var(--panel-w)) / 2 - 260px); font-size: 12px; color: color-mix(in oklab, var(--on-surface-variant) 70%, transparent); pointer-events: none; text-shadow: 0 1px 3px rgba(0,0,0,.6); }

/* ---------- снекбары ---------- */
#toasts { position: fixed; bottom: 84px; left: calc((100vw - var(--panel-w) - 24px) / 2); transform: translateX(-50%); z-index: 20; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { max-width: 520px; padding: 12px 18px; border-radius: 14px; background: var(--avr-mist); color: var(--avr-teal); font: 500 13.5px var(--font-ui); box-shadow: 0 6px 18px rgba(0,0,0,.28); animation: toast-in .45s var(--ease); }
.toast.err { background: var(--error-container); color: var(--on-error-container); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity .3s, transform .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.96); } }

/* ---------- диалоги ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(6, 46, 51, .62); }
.modal-wrap.hidden { display: none; }
.modal { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow: auto; padding: 26px 28px; border-radius: 28px; background: var(--surface-high); color: var(--on-surface); }
.modal-title { font: 720 24px/1.2 var(--font-ui); font-variation-settings: "wght" 720, "wdth" 110, "ROND" 100; margin-bottom: 8px; }
.modal p { color: var(--on-surface-variant); }
.modal .btn { margin-top: 6px; }
.modal.busy { width: 400px; display: grid; gap: 14px; justify-items: center; text-align: center; }
.modal.busy::before { content: ""; width: 48px; height: 48px; background: var(--avr-gradient); -webkit-mask: var(--avr-star) center / contain no-repeat; mask: var(--avr-star) center / contain no-repeat; animation: avr-breathe 1.5s ease-in-out infinite; }
.modal .bar { width: 100%; height: 10px; position: relative; }
.modal .bar::before { content: ""; position: absolute; left: 0; right: 0; top: 3px; height: 4px; border-radius: 99px; background: var(--secondary-container); }
.modal .bar div { position: relative; height: 4px; top: 3px; width: 0; border-radius: 99px; background: var(--primary); transition: width .2s; }
.modal a { color: var(--primary); }
.keys { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 16px 0; font-size: 13.5px; }
.keys dt { font-weight: 620; color: var(--primary); }
.keys dd { margin: 0; color: var(--on-surface); }

body.dropping::after { content: "Отпустите файл — параметры загрузятся"; position: fixed; inset: 12px; z-index: 40; display: grid; place-items: center; border: 2px dashed var(--primary); border-radius: 34px; background: rgba(6, 46, 51, .82); font: 700 20px var(--font-ui); color: var(--on-surface); }

/* ---------- эволюция ---------- */
.evo { position: fixed; left: 0; top: 0; bottom: 0; right: calc(var(--panel-w) + 12px); z-index: 6; display: flex; flex-direction: column; padding: 14px 16px 12px; gap: 10px; pointer-events: none; }
.evo.hidden { display: none; }
.evo > * { pointer-events: auto; }
.evo-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 8px 8px 20px; background: var(--surface); border-radius: var(--r-full); }
.evo-bar b { font: 720 16px var(--font-ui); font-variation-settings: "wght" 720, "wdth" 108, "ROND" 100; }
.evo-gen { font: 500 12.5px var(--font-ui); color: var(--primary); }
.evo-strength { display: flex; align-items: center; gap: 10px; margin-left: auto; color: var(--on-surface-variant); font-size: 13px; }
.evo-strength input { width: 120px; }
.evo-bar .btn { height: 40px; }
.evo-grid { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 10px; }
.evo-cell { position: relative; padding: 0; background: transparent; border: 0; border-radius: 22px; box-shadow: inset 0 0 0 1px var(--outline-variant); cursor: pointer; transition: border-radius .45s var(--ease), box-shadow .2s; }
.evo-cell:hover { border-radius: 30px; box-shadow: inset 0 0 0 2px var(--on-surface-variant); }
.evo-cell.center { box-shadow: inset 0 0 0 3px var(--primary); }
.evo-cell span { position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 14px 8px; border-radius: 0 0 22px 22px; text-align: left; font: 500 12px var(--font-ui); color: var(--avr-mist); background: linear-gradient(transparent, rgba(6,46,51,.85)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.evo-hint { font-size: 12.5px; color: var(--on-surface-variant); text-align: center; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
body.evolving #toolbar, body.evolving #hint, body.evolving #hud, body.evolving #progress { display: none; }

body.wallpaper #toolbar, body.wallpaper #toasts { display: none; }

@media (max-width: 1180px) { #hint { display: none; } }
@media (max-width: 760px) {
  :root { --panel-w: 0px; }
  #panel { left: 8px; right: 8px; top: auto; bottom: 74px; height: 50vh; width: auto; border-radius: 28px; }
  #toolbar { left: 50%; bottom: calc(50vh + 84px); }
  #progress { right: 16px; }
  .evo { right: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
