:root {
  --bg: #0B0B0D;
  --surface: #141417;
  --surface-2: #1C1C20;
  --surface-3: #26262B;
  --line: rgba(255, 255, 255, 0.08);
  --text: #F3EFE9;
  --muted: #8E8A85;
  --accent: #E8B57A;
  --accent-text: #1A1208;
  --radius: 16px;
  --app-h: 100vh;
  --serif: 'Didot', 'Bodoni 72', 'Playfair Display', Georgia, 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
@supports (height: 100dvh) { :root { --app-h: 100dvh; } }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); overflow: hidden; }
body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

#app {
  height: var(--app-h);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  background:
    radial-gradient(120% 60% at 50% -10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 60%),
    var(--bg);
}

/* ---------- шапка ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; flex: none; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center; overflow: hidden;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 45%, #000));
  color: var(--accent-text); font-family: var(--serif); font-size: 18px; font-weight: 600;
  box-shadow: 0 0 0 1px rgba(255,255,255,.12) inset;
}
.logo img { width: 100%; height: 100%; object-fit: cover; }
.brand-text { min-width: 0; }
.brand-name { font-family: var(--serif); font-size: 18px; letter-spacing: .22em; line-height: 1.1; white-space: nowrap; }
.brand-tag { font-size: 11px; color: var(--muted); letter-spacing: .06em; margin-top: 2px; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.pro-chip {
  display: inline-flex; align-items: center; gap: 5px; height: 34px; padding: 0 12px; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent); color: var(--accent);
  font-size: 12px; font-weight: 700; letter-spacing: .12em;
}
.pro-chip svg { width: 15px; height: 15px; fill: currentColor; stroke: none; }
.pro-chip.active { background: var(--accent); color: var(--accent-text); }
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; height: 34px; padding: 0 16px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text); font-weight: 650; font-size: 14px; text-decoration: none;
  transition: transform .12s, filter .12s;
}
.btn-primary:active { transform: scale(.97); filter: brightness(.95); }
.btn-wide { width: 100%; height: 52px; font-size: 16px; border-radius: 14px; }
.btn-ghost {
  width: 100%; height: 42px; margin-top: 10px; border-radius: 12px; border: 1px dashed var(--line);
  color: var(--muted); font-size: 13px;
}
body.in-tg #btnSave { display: none; }

/* ---------- фото ---------- */
.stage { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; padding: 6px 16px 10px; }
.frame { position: relative; line-height: 0; border-radius: 10px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.55); touch-action: none; }
#view { display: block; }
.split-line { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: rgba(255,255,255,.9); display: none; pointer-events: none; box-shadow: 0 0 10px rgba(0,0,0,.4); }
.split-knob {
  position: absolute; top: 50%; left: 50%; width: 36px; height: 36px; margin: -18px 0 0 -18px; border-radius: 50%;
  background: rgba(255,255,255,.95); color: #111; display: grid; place-items: center; box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.split-knob svg { width: 18px; height: 18px; stroke-width: 2; }
.tag {
  position: absolute; top: 10px; padding: 4px 9px; border-radius: 999px; font-size: 11px; line-height: 1.3; letter-spacing: .04em;
  background: rgba(10,10,12,.62); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); display: none; pointer-events: none;
}
.tag-l { left: 10px; } .tag-r { right: 10px; } .tag-c { left: 50%; transform: translateX(-50%); }
.frame.comparing .split-line, .frame.comparing .tag-l, .frame.comparing .tag-r { display: block; }
.frame.holding .tag-c { display: block; }

.pro-banner {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); width: max-content; max-width: calc(100% - 40px);
  display: none; align-items: center; gap: 10px; padding: 7px 7px 7px 12px; border-radius: 999px; font-size: 12px; line-height: 1.25;
  background: rgba(14,14,16,.78); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--line);
}
.pro-banner.show { display: flex; }
.pro-banner span { display: flex; align-items: center; gap: 6px; }
.pro-banner svg { width: 15px; height: 15px; color: var(--accent); flex: none; }
.pro-banner button { flex: none; height: 28px; padding: 0 12px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-weight: 650; font-size: 12px; }
.hint { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--muted); transition: opacity .6s; pointer-events: none; }
.hint.off { opacity: 0; }
.spinner { position: absolute; width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255,255,255,.15); border-top-color: var(--accent); animation: spin .8s linear infinite; display: none; }
.spinner.show { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- панель ---------- */
.side { flex: none; padding-bottom: env(safe-area-inset-bottom); }
.toolbar { display: flex; justify-content: center; gap: 6px; padding: 0 16px 8px; }
.toolbar button {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px;
  color: var(--muted); font-size: 13px; background: var(--surface); border: 1px solid var(--line); transition: color .15s, border-color .15s;
}
.toolbar button svg { width: 17px; height: 17px; }
.toolbar button.on { color: var(--text); border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.panel { background: var(--surface); border-top: 1px solid var(--line); border-radius: 22px 22px 0 0; padding: 6px 0 12px; }
.tabs { display: flex; gap: 22px; padding: 6px 18px 10px; }
.tab { font-size: 13px; color: var(--muted); letter-spacing: .03em; padding: 4px 0; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* одинаковая высота вкладок на телефоне — фото не прыгает при переключении */
@media (max-width: 899px) {
  .tab-body { height: 172px; display: flex; flex-direction: column; }
  #tabPresets { justify-content: flex-start; }
  #tabAdjust .sliders { flex: 1; max-height: none; min-height: 0; }
  #tabAdjust .btn-ghost { flex: none; width: calc(100% - 36px); margin: 8px 18px 0; height: 36px; }
}
.strip { display: flex; gap: 10px; overflow-x: auto; padding: 2px 16px 10px; scroll-snap-type: x proximity; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.preset { flex: none; width: 70px; scroll-snap-align: start; text-align: center; }
.preset .thumb { position: relative; width: 70px; height: 70px; border-radius: 12px; overflow: hidden; background: var(--surface-2); outline: 2px solid transparent; outline-offset: 2px; transition: outline-color .15s; }
.preset canvas { width: 100%; height: 100%; display: block; }
.preset .name { margin-top: 6px; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preset.active .thumb { outline-color: var(--accent); }
.preset.active .name { color: var(--text); }
.preset .lock {
  position: absolute; right: 4px; top: 4px; display: flex; align-items: center; gap: 2px; padding: 2px 5px; border-radius: 6px;
  background: rgba(10,10,12,.72); color: var(--accent); font-size: 9px; font-weight: 800; letter-spacing: .08em; line-height: 1.3;
}
.preset .lock svg { width: 10px; height: 10px; stroke-width: 2.2; }
body.is-pro .preset .lock { display: none; }

.intensity, .slider-row { display: grid; grid-template-columns: 104px 1fr 34px; align-items: center; gap: 10px; padding: 0 18px; }
.intensity { padding-top: 4px; }
.intensity.disabled { opacity: .35; pointer-events: none; }
.lbl { font-size: 12px; color: var(--muted); }
.val { font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }

.sliders { max-height: 196px; overflow-y: auto; padding-bottom: 4px; }
.slider-row { height: 38px; }
.slider-row .lbl { cursor: pointer; }
.slider-group { padding: 10px 18px 2px; font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: color-mix(in srgb, var(--accent) 70%, var(--muted)); }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; touch-action: pan-y;
  --a: 0%; --b: 100%;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 3px; border-radius: 3px;
  background: linear-gradient(to right, var(--surface-3) var(--a), var(--accent) var(--a), var(--accent) var(--b), var(--surface-3) var(--b));
}
input[type=range]::-moz-range-track { height: 3px; border-radius: 3px; background: linear-gradient(to right, var(--surface-3) var(--a), var(--accent) var(--a), var(--accent) var(--b), var(--surface-3) var(--b)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -8.5px; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.5); border: 0; }
input[type=range]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
input.hue::-webkit-slider-runnable-track { height: 6px; background: linear-gradient(to right, #f33, #fa3, #ff3, #3f6, #3ff, #36f, #c3f, #f33); }
input.hue::-moz-range-track { height: 6px; background: linear-gradient(to right, #f33, #fa3, #ff3, #3f6, #3ff, #36f, #c3f, #f33); }
input.hue::-webkit-slider-thumb { margin-top: -7px; }

/* ---------- нижние окна ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 10; }
.scrim.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-height: 90%; overflow-y: auto;
  background: var(--surface); border-radius: 24px 24px 0 0; border-top: 1px solid var(--line);
  padding: 8px 20px calc(22px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
}
.sheet.show { transform: translateY(0); }
.sheet-grip { width: 38px; height: 4px; border-radius: 4px; background: var(--surface-3); margin: 2px auto 14px; }
.sheet h3 { margin: 0 0 14px; font-size: 17px; font-weight: 600; }
.upload { display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); cursor: pointer; }
.upload input { display: none; }
.upload svg { width: 26px; height: 26px; color: var(--accent); flex: none; }
.upload b { display: block; font-weight: 600; font-size: 15px; }
.upload small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.samples { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.sample { position: relative; aspect-ratio: 3/4; border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.sample img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sample span { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 6px; font-size: 11px; text-align: center; background: linear-gradient(transparent, rgba(0,0,0,.7)); }

.credits { margin: 12px 0 0; font-size: 10px; line-height: 1.45; color: var(--muted); opacity: .75; }
.paywall { text-align: center; }
.pw-logo { width: 64px; height: 64px; margin: 6px auto 12px; font-size: 32px; }
.paywall h2 { margin: 0; font-family: var(--serif); font-weight: 500; letter-spacing: .16em; font-size: 24px; }
.pw-author { margin: 6px 0 16px; color: var(--muted); font-size: 13px; }
.pw-perks { list-style: none; padding: 0; margin: 0 auto 18px; text-align: left; max-width: 380px; }
.pw-perks li { display: flex; gap: 10px; padding: 8px 0; font-size: 14px; line-height: 1.35; border-bottom: 1px solid var(--line); }
.pw-perks li:last-child { border-bottom: 0; }
.pw-perks svg { width: 18px; height: 18px; color: var(--accent); flex: none; margin-top: 1px; stroke-width: 2.2; }
.pw-price { margin-bottom: 14px; }
.pw-price span { font-size: 34px; font-weight: 700; }
.pw-price small { display: block; color: var(--muted); font-size: 13px; }
.pw-note { margin: 12px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; text-align: center; }
.paywall .btn-wide, .result .btn-wide { max-width: 420px; margin: 0 auto; display: flex; }
.result img { display: block; max-width: 100%; max-height: 55vh; margin: 0 auto; border-radius: 10px; -webkit-user-select: auto; user-select: auto; -webkit-touch-callout: default; }
.result .btn-wide { margin-top: 14px; }

.toast {
  position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top)); z-index: 20; transform: translate(-50%, -20px);
  max-width: calc(100% - 32px); width: max-content; padding: 11px 16px; border-radius: 14px; font-size: 13px; line-height: 1.4;
  background: rgba(30,30,34,.96); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 400px) {
  .top { padding: 10px 12px; }
  .brand { gap: 8px; }
  .brand-name { font-size: 16px; letter-spacing: .14em; }
  .pro-chip { padding: 0 10px; }
  .btn-primary:not(.btn-wide) { padding: 0 13px; }
}

/* ---------- компьютер ---------- */
@media (min-width: 900px) {
  #app { display: grid; grid-template-columns: 1fr 400px; grid-template-rows: auto 1fr; }
  .top { grid-column: 1 / -1; padding: 16px 24px; }
  .stage { padding: 8px 24px 24px; }
  .side { display: flex; flex-direction: column; min-height: 0; padding: 0 20px 20px 0; }
  .toolbar { justify-content: flex-start; padding: 8px 0 12px; }
  .panel { flex: 1; min-height: 0; border: 1px solid var(--line); border-radius: 20px; display: flex; flex-direction: column; overflow: hidden; }
  .tab-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; }
  .strip { flex-wrap: wrap; overflow: visible; gap: 14px 12px; padding: 4px 18px 16px; }
  .preset { width: calc((100% - 36px) / 4); }
  .preset .thumb { width: 100%; height: auto; aspect-ratio: 1; }
  .sliders { max-height: none; }
  .sheet { left: 50%; right: auto; bottom: 50%; width: 460px; border-radius: 24px; border: 1px solid var(--line); transform: translate(-50%, 60%); opacity: 0; pointer-events: none; transition: transform .3s, opacity .25s; }
  .sheet.show { transform: translate(-50%, 50%); opacity: 1; pointer-events: auto; }
  .sheet-grip { display: none; }
}
