:root {
  color-scheme: dark;
  font-family: ui-sans-serif, "Segoe UI", sans-serif;
  --bg: #080808;
  --panel: #1a1a1a;
  --glass: linear-gradient(156deg, #fff2, #ffffff08 44%, #0003), #15151585;
  --glass-heavy: linear-gradient(152deg, #444d, #202020f5 46%, #101010f5);
  --surface: #ffffff0d;
  --surface-hover: #fff2;
  --field: #0006;
  --border: #ffffff30;
  --line: #ffffff20;
  --text: #f7f7f7;
  --muted: #bfbfbf;
  --accent: #ececec;
  --on-accent: #151515;
  --radius: 24px;
  --edge: inset 0 1px 0 #ffffff2b, inset 1px 0 0 #ffffff0e;
  --lift: 0 18px 45px #0006, var(--edge);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; min-width: 300px; min-height: 100vh; color: var(--text);
  background:
    radial-gradient(ellipse at 9% -22%, #404040 0%, transparent 49%),
    radial-gradient(ellipse at 96% 14%, #272727 0%, transparent 43%),
    radial-gradient(ellipse at 49% 103%, #1d1d1d 0%, transparent 50%),
    var(--bg);
  background-attachment: fixed;
}
button, input, select { font: inherit; }
button, a, input, label.upload-zone { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { opacity: .47; cursor: not-allowed; }
a { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible, .upload-zone:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

.topbar { max-width: 1500px; margin: 14px auto 0; padding: 0 36px; }
.topbar-inner {
  min-height: 64px; padding: 0 16px; margin: auto;
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 20px; align-items: center;
  border-radius: 25px; border: 1px solid var(--border); background: var(--panel); box-shadow: var(--lift);
}
.brand { display: flex; gap: 9px; align-items: center; width: max-content; text-decoration: none; font-size: .93rem; font-weight: 850; letter-spacing: .085em; }
.brand-mark { display: grid; place-items: center; width: 37px; height: 37px; border-radius: 13px; background: linear-gradient(145deg, #fff 4%, #dedede 54%, #adadad); color: var(--on-accent); font-size: 1.23rem; font-style: italic; letter-spacing: -.1em; padding-right: 2px; box-shadow: inset 0 0 0 1px #fff9, 0 3px 12px #0008; }
.studio-word { color: var(--muted); font-size: .77rem; font-weight: 600; letter-spacing: .09em; }
.navigation { display: flex; align-items: center; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 999px; background: #0005; }
.nav-item { border: 1px solid transparent; color: var(--muted); background: transparent; border-radius: 999px; padding: 7px 15px; font-size: .9rem; font-weight: 650; white-space: nowrap; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.is-active { border-color: var(--border); background: linear-gradient(160deg, #ffffff35, #ffffff16); box-shadow: var(--edge); color: var(--text); }
.nav-item span { font-size: .75rem; background: var(--surface-hover); border-radius: 8px; color: var(--text); margin-left: 3px; padding: 1px 5px; }
.new-set { justify-self: end; }

.shell { max-width: 1500px; margin: auto; padding: 30px 36px 34px; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 26px; }
h1 { font-size: clamp(2.05rem, 4vw, 3.15rem); line-height: 1.06; font-weight: 750; letter-spacing: -.055em; text-shadow: 0 3px 28px #0006; }
h2 { font-size: 1.03rem; line-height: 1.22; font-weight: 730; letter-spacing: -.018em; }
.actions { display: flex; gap: 10px; }
[data-telegram="mini"] .desktop-import { display: none; }
.button {
  height: 43px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 999px; color: var(--text); background: transparent;
  font-size: .875rem; font-weight: 700; white-space: nowrap; text-decoration: none; transition: background .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.button.secondary, .button.quiet { background: linear-gradient(155deg, #fff2, #ffffff0b); border-color: var(--border); box-shadow: var(--edge); }
.button.secondary:hover, .button.quiet:hover { background: var(--surface-hover); border-color: #ffffff6f; }
.button.primary { background: linear-gradient(161deg, #fcfcfc, #dedede 72%, #c7c7c7); color: var(--on-accent); border-color: #ffffffb5; box-shadow: inset 0 1px 0 #fff, 0 5px 16px #0007; }
.button.primary:hover { background: linear-gradient(161deg, #fff, #e8e8e8); box-shadow: inset 0 1px 0 #fff, 0 6px 21px #ffffff24; }
.export-icon, .save-icon { width: 13px; height: 13px; display: inline-block; flex: 0 0 auto; position: relative; }
.export-icon { border: 1.5px solid currentColor; border-top: 0; height: 6px; border-radius: 0 0 2px 2px; margin-top: 6px; }
.export-icon::before { content: ""; position: absolute; width: 5px; height: 5px; transform: rotate(45deg); border-right: 1.5px solid; border-bottom: 1.5px solid; top: -4px; left: 2.4px; }
.export-icon::after { content: ""; position: absolute; width: 1px; height: 7px; background: currentColor; top: -7px; left: 5px; }
.save-icon { border: 1.5px solid; border-radius: 2px; }
.save-icon::before { content: ""; position: absolute; width: 5px; height: 2px; border: 1px solid; border-top: 0; left: 2px; top: 0; }
.save-icon::after { content: ""; position: absolute; width: 6px; height: 4px; border: 1px solid; border-bottom: 0; border-radius: 1px 1px 0 0; left: 1.8px; bottom: 0; }

.workspace { display: grid; grid-template-columns: minmax(245px, .88fr) minmax(360px, 1.9fr) minmax(227px, .77fr); align-items: start; gap: 16px; }
.sidebar { display: grid; gap: 14px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; box-shadow: var(--lift); }
.panel.stage { background: #161616; }
@supports (backdrop-filter: blur(1px)) {
  .panel:not(.stage), .topbar-inner { background: var(--glass); backdrop-filter: blur(24px) saturate(145%); }
}
.import-panel, .layers-panel, .inspector { padding: 18px; }
.import-panel .panel-heading { align-items: baseline; flex-wrap: wrap; }
.import-panel .avito-help { color: var(--accent); font-size: .79rem; }
.import-panel form label { display: block; color: var(--muted); font-size: .875rem; font-weight: 550; margin-bottom: 7px; }
.link-field { position: relative; }
.link-field input { width: 100%; padding: 11px 9px 11px 36px; font-size: .91rem; border-radius: 13px; border: 1px solid var(--line); background: var(--field); color: var(--text); box-shadow: inset 0 1px 5px #0005; }
.link-field input::placeholder { color: #aaa; }
.link-icon { width: 19px; height: 19px; position: absolute; left: 10px; top: 10px; color: var(--muted); transform: rotate(-36deg); pointer-events: none; }
.link-icon::before, .link-icon::after { content: ""; position: absolute; top: 6px; width: 9px; height: 6px; border: 1.5px solid; border-radius: 4px; }
.link-icon::before { left: 1px; }
.link-icon::after { right: 1px; }
.import-button { width: 100%; margin-top: 9px; }
.separator { display: flex; align-items: center; gap: 9px; margin: 11px 0; font-size: .82rem; color: var(--muted); }
.separator::before, .separator::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.upload-zone { position: relative; display: flex; align-items: center; gap: 10px; padding: 11px; min-height: 63px; background: var(--surface); border: 1px dashed var(--border); border-radius: 15px; cursor: pointer; }
.upload-zone:hover, .upload-zone.is-dragging { background: var(--surface-hover); border-color: var(--accent); }
.upload-zone:has(input:disabled) { opacity: .5; cursor: not-allowed; }
.upload-zone strong, .upload-zone small { display: block; }
.upload-zone strong { font-size: .88rem; font-weight: 680; }
.upload-zone small { margin-top: 3px; color: var(--muted); font-size: .76rem; }
.upload-plus { flex: 0 0 auto; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 11px; background: var(--surface-hover); color: var(--accent); font-size: 1.16rem; box-shadow: var(--edge); }
.upload-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.form-status { margin-top: 12px; color: var(--muted); font-size: .86rem; line-height: 1.45; }
.form-status.is-error { color: #ffd2dd; }
.avito-fallback { display: grid; gap: 5px; margin-top: 9px; }
.avito-fallback .button { min-height: 37px; height: auto; padding-block: 7px; }
.avito-fallback .text-button { text-align: center; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 13px; }
.counter { color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 2px 7px; font-size: .77rem; }
.layers { display: grid; gap: 6px; }
.layer { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; border: 1px solid var(--line); background: var(--surface); padding: 7px; color: var(--text); border-radius: 13px; }
.layer:hover { background: var(--surface-hover); }
.layer.is-selected { border-color: #ffffff70; background: linear-gradient(135deg, #ffffff30, #ffffff13); box-shadow: var(--edge); }
.layer img, .selection img { width: 43px; height: 43px; padding: 4px; flex: 0 0 auto; border-radius: 8px; background: var(--field); object-fit: contain; }
.layer-copy, .selection div { display: grid; min-width: 0; gap: 2px; }
.layer strong, .selection strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 680; font-size: .87rem; }
.layer small, .selection span { font-size: .76rem; color: var(--muted); }
.layer-empty, .inspector-empty { color: var(--muted); font-size: .9rem; line-height: 1.45; }

.stage { overflow: hidden; }
.stage-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 17px; min-height: 50px; border-bottom: 1px solid var(--line); background: linear-gradient(105deg, #ffffff15, #ffffff07); }
.board-title-field { display: flex; align-items: center; gap: 5px; min-width: 0; max-width: 75%; }
.board-title-field input { font-weight: 670; font-size: .95rem; padding: 5px 2px; width: min(224px, 100%); min-width: 0; background: transparent; color: var(--text); border: 1px solid transparent; border-radius: 4px; }
.board-title-field input:hover { border-color: var(--border); }
.edit-icon { position: relative; width: 10px; height: 5px; border: 1px solid var(--muted); border-radius: 1px; transform: rotate(-40deg); flex: 0 0 auto; }
.resolution { font-size: .77rem; color: var(--muted); font-weight: 580; font-variant-numeric: tabular-nums; white-space: nowrap; background: var(--field); border: 1px solid var(--line); border-radius: 999px; padding: 5px 8px; }
.canvas-area {
  min-height: clamp(406px, calc(100dvh - 258px), 553px); padding: 19px 17px; display: grid; place-items: center; isolation: isolate;
  background: radial-gradient(ellipse at 50% 32%, #2e2e2e 0, #1a1a1a 58%, #101010 100%);
}
.board {
  position: relative; width: min(100%, 362px, max(258px, calc((100dvh - 296px) * .703125))); aspect-ratio: 1080 / 1536; overflow: hidden;
  background: #0a0a0a url('/studio/assets/grid.webp') center/100% 100%; box-shadow: 0 19px 38px #000b, 0 0 0 1px var(--border);
  touch-action: none;
}
.piece { position: absolute; padding: 0; border: 0; background: none; translate: -50% -50%; cursor: grab; touch-action: none; }
.piece:active { cursor: grabbing; }
.piece img { display: block; width: 100%; height: auto; pointer-events: none; user-select: none; filter: drop-shadow(2px 5px 4px #000a); }
.piece.is-selected::after { content: ""; position: absolute; inset: -2px; border: 1px dashed #ffffffcf; pointer-events: none; }
.stage-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px 12px; min-height: 41px; padding: 7px 12px; color: var(--muted); font-size: .83rem; text-align: center; border-top: 1px solid var(--line); }
.empty-board { display: grid; position: absolute; inset: 0; align-content: center; justify-items: center; gap: 8px; text-align: center; pointer-events: none; padding: 20px; }
.empty-board strong { font-size: 1rem; }
.empty-board span:last-child { color: var(--muted); font-size: .88rem; }
.empty-plus { display: grid; place-items: center; width: 43px; height: 43px; border: 1px solid var(--border); color: var(--accent); background: var(--surface-hover); border-radius: 12px; font-size: 1.5rem; }

.inspector h2 { margin-bottom: 15px; }
.selection { display: flex; align-items: center; gap: 9px; padding: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 15px; margin-bottom: 18px; }
.selection img { width: 46px; height: 46px; }
.photo-edge { margin: -7px 0 14px; padding: 8px 10px; border-left: 2px solid var(--border); color: var(--muted); font-size: .8rem; line-height: 1.4; }
.type-label { display: block; margin-bottom: 7px; font-size: .9rem; font-weight: 650; }
.type-select { width: 100%; height: 38px; appearance: none; padding: 0 33px 0 10px; border: 1px solid var(--border); border-radius: 12px; color: var(--text); background: linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 14px) center/5px 5px no-repeat, linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 9px) center/5px 5px no-repeat, var(--field); }
.type-select option { background: var(--panel); color: var(--text); }
.type-status { color: var(--muted); font-size: .8rem; line-height: 1.4; margin: 6px 0 1px; }
.type-actions { display: flex; flex-wrap: wrap; column-gap: 13px; row-gap: 0; margin-bottom: 16px; }
.type-actions .text-button { color: var(--accent); }
.asset-credit { color: var(--muted); font-size: .8rem; line-height: 1.4; margin-top: 9px; }
.training-panel { max-width: 560px; margin-top: 16px; padding: 13px 16px; }
.training-panel summary { cursor: pointer; font-weight: 640; font-size: .93rem; }
.training-panel .counter { margin-left: 5px; }
.training-panel p { color: var(--muted); font-size: .875rem; line-height: 1.45; margin: 10px 0; }
.positions { border: 0; padding: 0; margin: 0 0 17px; display: flex; flex-wrap: wrap; gap: 5px; }
.positions legend { margin-bottom: 8px; font-weight: 650; font-size: .9rem; }
.positions button { padding: 5px 9px; border: 1px solid var(--line); color: var(--muted); background: var(--surface); border-radius: 999px; font-size: .84rem; line-height: 1.3; }
.positions button:hover { background: var(--surface-hover); }
.positions button[aria-pressed="true"] { background: #fff3; border-color: #ffffff70; color: var(--text); box-shadow: var(--edge); }
.range-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .88rem; font-weight: 630; }
.range-label output { font-size: .83rem; color: var(--muted); font-variant-numeric: tabular-nums; }
input[type="range"] { display: block; width: 100%; margin: 6px 0 14px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.inspector-actions { display: grid; justify-items: start; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.text-button, .source { background: none; color: var(--accent); border: 0; padding: 4px 0; font-size: .87rem; font-weight: 600; text-align: left; text-decoration: none; }
.text-button:hover, .source:hover { text-decoration: underline; color: var(--text); }
.danger { color: #ffd0dd; }

.library-head { align-items: center; }
.library-head p { margin-top: 10px; color: var(--muted); font-size: .98rem; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(192px, 1fr)); gap: 16px; }
.library-card { display: grid; grid-template-rows: 1fr auto; overflow: hidden; }
.library-open { border: 0; background: var(--surface); color: var(--text); padding: 13px; display: grid; gap: 9px; text-align: left; width: 100%; }
.library-open:hover { background: var(--surface-hover); }
.library-open img { aspect-ratio: 1080 / 1536; width: 100%; display: block; object-fit: cover; border-radius: 6px; }
.library-open strong { overflow-wrap: anywhere; font-size: 1rem; }
.library-details { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px; border-top: 1px solid var(--border); padding: 6px 13px; color: var(--muted); font-size: .82rem; }
.empty-library { text-align: center; padding: 58px 16px; margin-top: 20px; }
.empty-library p { color: var(--muted); margin: 9px 0 17px; }
.toast { position: fixed; z-index: 3; right: 26px; bottom: 20px; max-width: min(390px, calc(100vw - 52px)); padding: 12px 17px; background: var(--glass-heavy); border: 1px solid var(--border); color: var(--text); border-radius: 16px; box-shadow: var(--lift); backdrop-filter: blur(14px); font-size: .9rem; }
.panel.avito-dialog { width: min(490px, calc(100% - 28px)); margin: auto; padding: 19px 21px 20px; color: var(--text); background: var(--glass-heavy); }
.avito-dialog::backdrop { background: #000b; backdrop-filter: blur(6px); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; }
.dialog-header h2 { font-size: 1.17rem; }
.dialog-close { width: 34px; height: 34px; padding: 0; font-size: 1.25rem; }
.avito-dialog ol { padding-left: 22px; line-height: 1.55; }
.avito-dialog li + li { margin-top: 6px; }
.avito-dialog code { color: var(--accent); overflow-wrap: anywhere; }
.avito-dialog p { margin-top: 13px; color: var(--muted); line-height: 1.45; font-size: .87rem; }

@media (prefers-reduced-transparency: reduce) {
  .panel:not(.stage), .topbar-inner, .toast { background: var(--panel); backdrop-filter: none; }
}
@media (prefers-reduced-motion: reduce) {
  .button { transition: none; }
}

@media (max-width: 1110px) {
  .shell, .topbar { padding-left: 22px; padding-right: 22px; }
  .workspace { grid-template-columns: minmax(223px, .88fr) minmax(310px, 1.55fr) minmax(205px, .77fr); gap: 12px; }
  .import-panel, .layers-panel, .inspector { padding: 14px; }
}
@media (max-width: 890px) {
  .workspace { grid-template-columns: minmax(213px, .8fr) minmax(280px, 1.25fr); }
  .stage { grid-column: 2; grid-row: 1 / span 2; }
  .inspector { grid-column: 1; grid-row: 2; }
  .canvas-area { min-height: 0; }
  .board { width: min(100%, 362px); }
}
@media (max-width: 620px) {
  .shell { padding: 22px 14px; }
  .topbar { margin-top: 9px; padding: 0 10px; }
  .topbar-inner { padding: 10px 14px; gap: 9px; grid-template-columns: 1fr auto; min-height: 0; }
  .brand { font-size: .84rem; }
  .brand-mark { width: 28px; height: 28px; }
  .studio-word { display: none; }
  .navigation { grid-row: 2; grid-column: 1 / -1; justify-content: stretch; }
  .navigation button { flex: 1; }
  .new-set { grid-row: 1; grid-column: 2; height: 34px; }
  .page-head { align-items: flex-start; flex-direction: column; margin-bottom: 16px; }
  .actions { width: 100%; flex-wrap: wrap; }
  .actions button { flex: 1; padding-inline: 8px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: contents; }
  .import-panel, .stage, .inspector, .layers-panel { grid-column: 1; grid-row: auto; }
  .stage { order: 1; }
  .inspector { order: 2; }
  .layers-panel { order: 3; }
  .canvas-area { padding: 15px; }
  .library-grid { grid-template-columns: repeat(auto-fill, minmax(146px, 1fr)); }
}
