:root {
  --bg: #14110f;
  --bg-2: #1c1815;
  --card: #231e1a;
  --line: rgba(255, 233, 210, .10);
  --line-2: rgba(255, 233, 210, .18);
  --ink: #f4ece3;
  --ink-2: #b9ab9c;
  --ink-3: #8a7d70;
  --amber: #ff9a3c;
  --amber-2: #ffc078;
  --red: #e2553f;
  --ok: #7fd18b;
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(255, 140, 50, .16), transparent 60%),
    radial-gradient(80% 40% at 100% 100%, rgba(226, 85, 63, .08), transparent 70%),
    var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 50; opacity: .06; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* ---------- шапка ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: linear-gradient(var(--bg) 60%, rgba(20, 17, 15, 0));
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; position: relative;
  background: conic-gradient(from 210deg, #ff9a3c, #e2553f, #ffc078, #ff9a3c);
  box-shadow: 0 0 0 1px rgba(255,255,255,.08) inset, 0 6px 18px rgba(255, 120, 40, .35);
}
.brand-mark::after {
  content: ""; position: absolute; inset: 8px; border-radius: 50%;
  background: var(--bg); box-shadow: 0 0 0 2px rgba(255, 236, 214, .9);
}
.brand-name { font-weight: 750; letter-spacing: -.01em; font-size: 18px; }
.balance {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 8px 12px 8px 14px; border-radius: 999px; cursor: pointer;
  background: var(--card); border: 1px solid var(--line-2);
}
.balance-num { font-weight: 800; font-size: 17px; color: var(--amber-2); font-variant-numeric: tabular-nums; }
.balance-label { font-size: 13px; color: var(--ink-2); }
.balance-plus {
  align-self: center; display: grid; place-items: center; width: 22px; height: 22px; margin-left: 2px;
  border-radius: 50%; background: var(--amber); color: #2a1503; font-weight: 800; font-size: 16px; line-height: 1;
}
.balance.pulse { animation: pulse .9s ease 2; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 154, 60, .25); } }

main { width: 100%; max-width: 560px; margin: 0 auto; padding: 4px 16px 24px; }

/* ---------- сцена ---------- */
.stage { position: relative; }
.drop {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; min-height: 300px; aspect-ratio: 4 / 4.2; width: 100%;
  border-radius: 24px; cursor: pointer; text-align: center; padding: 24px;
  background:
    radial-gradient(70% 60% at 50% 40%, rgba(255, 154, 60, .14), transparent 70%),
    var(--bg-2);
  border: 1px solid var(--line);
  transition: transform .2s ease, border-color .2s ease;
}
.drop:active { transform: scale(.985); }
.drop.over { border-color: var(--amber); }
.drop-frame i {
  position: absolute; width: 34px; height: 34px; border: 3px solid var(--amber); opacity: .85;
}
.drop-frame i:nth-child(1) { top: 18px; left: 18px; border-right: 0; border-bottom: 0; border-top-left-radius: 12px; }
.drop-frame i:nth-child(2) { top: 18px; right: 18px; border-left: 0; border-bottom: 0; border-top-right-radius: 12px; }
.drop-frame i:nth-child(3) { bottom: 18px; left: 18px; border-right: 0; border-top: 0; border-bottom-left-radius: 12px; }
.drop-frame i:nth-child(4) { bottom: 18px; right: 18px; border-left: 0; border-top: 0; border-bottom-right-radius: 12px; }
.drop-icon { color: var(--amber-2); margin-bottom: 6px; }
.drop-title { font-size: 22px; font-weight: 750; letter-spacing: -.01em; }
.drop-sub { color: var(--ink-2); font-size: 15px; }

.preview, .compare, .working {
  position: relative; border-radius: 24px; overflow: hidden; background: #0d0b0a;
  border: 1px solid var(--line); min-height: 220px;
}
.preview img { width: 100%; max-height: 62vh; object-fit: contain; margin: 0 auto; }
.chip-btn {
  position: absolute; right: 12px; bottom: 12px; padding: 8px 14px; border-radius: 999px; border: 0;
  background: rgba(20, 17, 15, .78); color: var(--ink); font-size: 14px; font-weight: 600;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); cursor: pointer;
}

/* до / после */
.compare { touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.compare > img { width: 100%; max-height: 66vh; object-fit: contain; margin: 0 auto; }
.compare-before { position: absolute; inset: 0; clip-path: inset(0 50% 0 0); }
.compare-before img { width: 100%; height: 100%; object-fit: contain; }
.compare-handle {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; margin-left: -1px;
  background: rgba(255, 236, 214, .9); pointer-events: none;
}
.compare-handle span {
  position: absolute; top: 50%; left: 50%; width: 36px; height: 36px; margin: -18px 0 0 -18px; border-radius: 50%;
  background: var(--amber); box-shadow: 0 4px 16px rgba(0,0,0,.45);
}
.compare-handle span::before, .compare-handle span::after {
  content: ""; position: absolute; top: 12px; border: 6px solid transparent;
}
.compare-handle span::before { left: 3px; border-right-color: #2a1503; }
.compare-handle span::after { right: 3px; border-left-color: #2a1503; }
.compare-range {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize;
  -webkit-appearance: none; appearance: none;
}
.tag {
  position: absolute; top: 12px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; background: rgba(20,17,15,.7); color: var(--ink-2); pointer-events: none;
}
.tag-l { left: 12px; } .tag-r { right: 12px; color: var(--amber-2); }
.compare.swap { cursor: pointer; }
.compare.swap .compare-before { transition: opacity .18s ease; }
.cmp-hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); padding: 6px 12px; border-radius: 999px;
  background: rgba(20,17,15,.78); color: var(--ink); font-size: 13px; font-weight: 600; white-space: nowrap;
  pointer-events: none; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}

/* проявка */
.working { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 36px 24px; min-height: 300px; aspect-ratio: 4 / 4.2; }
.working::before {
  content: ""; position: absolute; inset: 0; opacity: .35; background-size: cover; background-position: center;
  background-image: var(--ghost, none); filter: grayscale(1) blur(2px); animation: reveal 6s ease-in-out infinite alternate;
}
@keyframes reveal { from { opacity: .12; filter: grayscale(1) blur(6px); } to { opacity: .42; filter: grayscale(.2) sepia(.5) blur(1px); } }
.develop {
  position: relative; width: 64px; height: 64px; border-radius: 50%;
  border: 3px solid rgba(255, 192, 120, .2); border-top-color: var(--amber);
  animation: spin 1.1s linear infinite; margin-bottom: 18px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.working-title { position: relative; margin: 0; font-size: 21px; font-weight: 750; }
.working-sub { position: relative; margin: 6px 0 0; color: var(--ink-2); font-size: 14px; max-width: 280px; }

/* ---------- выбор обработки ---------- */
.picker { margin-top: 18px; }
.tabs { display: flex; gap: 6px; padding: 4px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; }
.tab {
  flex: 1; padding: 9px 6px; border: 0; border-radius: 10px; background: transparent; color: var(--ink-2);
  font-weight: 650; font-size: 15px; cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 0 rgba(255,255,255,.05) inset, 0 4px 12px rgba(0,0,0,.25); }
.styles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.style {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 13px 13px 12px; min-height: 86px; border-radius: 16px; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); transition: border-color .15s ease, transform .15s ease;
}
.style:active { transform: scale(.97); }
.style-emoji { font-size: 22px; line-height: 1; margin-bottom: 6px; }
.style-title { font-weight: 700; font-size: 15px; line-height: 1.2; }
.style-hint { color: var(--ink-3); font-size: 12.5px; line-height: 1.25; }
.style[aria-pressed="true"] {
  border-color: var(--amber);
  background: linear-gradient(160deg, rgba(255, 154, 60, .16), rgba(255, 154, 60, .03)), var(--card);
}
.style[aria-pressed="true"]::after {
  content: ""; position: absolute; top: 12px; right: 12px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--amber); box-shadow: 0 0 10px var(--amber);
}

.wish { margin-top: 14px; }
.wish label { display: block; font-weight: 650; margin: 0 0 6px 2px; }
.wish textarea {
  width: 100%; resize: none; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line-2);
  background: var(--bg-2); color: var(--ink); font-size: 16px; line-height: 1.4; outline: none;
}
.wish textarea:focus { border-color: var(--amber); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 12px 18px;
  border-radius: 15px; border: 1px solid var(--line-2); background: var(--card); color: var(--ink);
  font-weight: 700; font-size: 16px; cursor: pointer; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .45; cursor: default; transform: none; }
.btn-primary {
  border: 0; color: #2a1503;
  background: linear-gradient(180deg, #ffb25e, #ff8a2a);
  box-shadow: 0 10px 26px rgba(255, 120, 40, .28), 0 1px 0 rgba(255,255,255,.4) inset;
}
.btn-ghost { background: transparent; }
.btn-go { width: 100%; margin-top: 16px; min-height: 56px; font-size: 17px; }
.fineprint { color: var(--ink-3); font-size: 12.5px; text-align: center; margin: 10px 0 0; }

.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.result-actions .btn-ghost { grid-column: 1 / -1; }
.btn-del {
  grid-column: 1 / -1; justify-self: center; margin-top: 2px; padding: 10px 14px; border: 0; background: none;
  color: #e7847a; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-del[disabled] { opacity: .5; }

/* ---------- история ---------- */
.history { margin-top: 28px; }
.history h2 { font-size: 15px; color: var(--ink-2); font-weight: 650; margin: 0 0 10px 2px; letter-spacing: .02em; }
.history-row { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; }
.thumb {
  flex: 0 0 auto; width: 92px; height: 116px; border-radius: 14px; overflow: hidden; border: 1px solid var(--line);
  background: var(--card); scroll-snap-align: start; cursor: pointer; padding: 0; position: relative;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .thumb-state { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; color: var(--ink-2); text-align: center; padding: 6px; }

/* ---------- подвал ---------- */
.foot { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px 18px; padding: 8px 16px calc(24px + var(--safe-b)); }
.link { background: none; border: 0; padding: 6px 0; color: var(--ink-3); font-size: 14px; text-decoration: none; cursor: pointer; }

/* ---------- шторки ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(8, 6, 5, .62); animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; } }
.sheet-card {
  position: relative; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  padding: 22px 18px calc(22px + var(--safe-b)); border-radius: 24px 24px 0 0;
  background: var(--bg-2); border: 1px solid var(--line-2); border-bottom: 0;
  animation: rise .24s cubic-bezier(.2,.8,.2,1);
}
@keyframes rise { from { transform: translateY(30px); opacity: .4; } }
.sheet-card h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.01em; }
.sheet-x { position: absolute; top: 10px; right: 10px; width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: var(--card); color: var(--ink-2); font-size: 24px; line-height: 1; cursor: pointer; }
.sheet-lead { color: var(--ink-2); font-size: 14.5px; margin: 0 0 16px; padding-right: 30px; }
.sheet-note { color: var(--ink-3); font-size: 13px; margin: 12px 0 0; }
.packs { display: grid; gap: 10px; }
.pack {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 12px; width: 100%; text-align: left;
  padding: 15px 16px; border-radius: 16px; border: 1px solid var(--line-2); background: var(--card); cursor: pointer;
}
.pack:active { transform: scale(.985); }
.pack-title { font-weight: 750; font-size: 17px; }
.pack-note { color: var(--ink-3); font-size: 13px; grid-column: 1; }
.pack-price { grid-row: 1 / span 2; grid-column: 2; font-weight: 800; font-size: 20px; color: var(--amber-2); white-space: nowrap; }
.pack.best { border-color: var(--amber); background: linear-gradient(160deg, rgba(255,154,60,.14), transparent), var(--card); }
.pack.best .pack-title::after { content: "выгодно"; margin-left: 8px; padding: 2px 8px; border-radius: 999px; font-size: 11px;
  font-weight: 800; letter-spacing: .04em; text-transform: uppercase; vertical-align: 2px; background: var(--amber); color: #2a1503; }
.pack[disabled] { opacity: .5; }
.steps { margin: 0 0 4px; padding-left: 22px; color: var(--ink); }
.steps li { margin: 6px 0; }
#accountSheet .btn { width: 100%; margin-top: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(22px + var(--safe-b)); z-index: 60; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px; background: #2b241f; color: var(--ink);
  border: 1px solid var(--line-2); box-shadow: 0 10px 30px rgba(0,0,0,.45); font-size: 15px; text-align: center;
  animation: rise .2s ease;
}
.toast.err { border-color: rgba(226, 85, 63, .6); }
.toast.ok { border-color: rgba(127, 209, 139, .55); }

.update-bar {
  position: fixed; left: 50%; top: calc(10px + env(safe-area-inset-top, 0px)); z-index: 70; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; max-width: calc(100% - 32px); padding: 8px 8px 8px 16px;
  border-radius: 999px; background: #2b241f; color: var(--ink); border: 1px solid var(--amber-2, #e0a458);
  box-shadow: 0 10px 30px rgba(0,0,0,.45); font-size: 14px; font-weight: 600; white-space: nowrap; animation: rise .2s ease;
}
.update-go {
  border: 0; border-radius: 999px; padding: 8px 14px; background: var(--amber-2, #e0a458); color: #14110f;
  font: inherit; cursor: pointer;
}
.app-ver { text-align: center; }

@media (min-width: 620px) {
  .styles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sheet { align-items: center; }
  .sheet-card { border-radius: 24px; border-bottom: 1px solid var(--line-2); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.code-form { display: flex; gap: 8px; margin: 10px 0 0; }
.code-form input {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line-2);
  background: var(--bg-2); color: var(--ink); font-size: 18px; letter-spacing: .08em; outline: none;
  text-transform: uppercase;
}
.code-form input::placeholder { color: var(--ink-3); }
.code-form input:focus { border-color: var(--amber); }
#accountSheet .code-form .btn { flex: none; width: auto; margin-top: 0; padding: 12px 20px; }

/* 3.6: вход через MAX */
#maxLinkBox .btn { display: flex; justify-content: center; text-decoration: none; margin-top: 4px; }
.max-promo { display: block; margin: 12px auto 0; color: var(--amber); font-weight: 600; text-align: center; }
