:root {
  --paper: #f3ecdf;
  --paper-2: #ebe1cf;
  --card: #fbf7ef;
  --ink: #26181a;
  --ink-2: #5a4a45;
  --muted: #86766e;
  --rule: #d6c8b2;
  --wine: #6b1d2c;
  --wine-2: #8c2a3c;
  --gold: #a9853f;
  --ok: #3f6b3a;
  --warn: #9a6516;
  --bad: #9b2b2b;
  --shadow: 0 1px 0 rgba(255,255,255,.6) inset, 0 18px 40px -24px rgba(60,20,20,.35);
  --display: "PT Serif Caption", "PT Serif", "Iowan Old Style", Georgia, serif;
  --text: "PT Serif", "Iowan Old Style", Georgia, serif;
  --ui: "PT Sans Narrow", "PT Sans", "Avenir Next Condensed", "Helvetica Neue", sans-serif;
  --mono: "PT Mono", ui-monospace, Menlo, monospace;
  --gutter-l: max(16px, env(safe-area-inset-left));
  --gutter-r: max(16px, env(safe-area-inset-right));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16100f; --paper-2: #1f1715; --card: #231a18; --ink: #efe4d3; --ink-2: #cbbba6;
    --muted: #9a8a7c; --rule: #3a2d29; --wine: #d77a88; --wine-2: #e9909c; --gold: #d0ab62;
    --ok: #8fbf83; --warn: #e0a64a; --bad: #ec8b84;
    --shadow: 0 18px 40px -24px rgba(0,0,0,.8); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #16100f; --paper-2: #1f1715; --card: #231a18; --ink: #efe4d3; --ink-2: #cbbba6;
  --muted: #9a8a7c; --rule: #3a2d29; --wine: #d77a88; --wine-2: #e9909c; --gold: #d0ab62;
  --ok: #8fbf83; --warn: #e0a64a; --bad: #ec8b84;
  --shadow: 0 18px 40px -24px rgba(0,0,0,.8); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink);
  font: 17px/1.5 var(--text);
  background-image:
    radial-gradient(1200px 500px at 85% -10%, color-mix(in srgb, var(--wine) 12%, transparent), transparent 70%),
    radial-gradient(900px 600px at -10% 110%, color-mix(in srgb, var(--gold) 10%, transparent), transparent 70%);
  background-attachment: fixed;
}
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .07; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
button, .button { font: 600 15px/1 var(--ui); letter-spacing: .04em; text-transform: uppercase; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.primary, .ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em; border-radius: 999px; padding: .8em 1.3em;
  min-height: 44px; border: 1.5px solid var(--wine); white-space: nowrap;
  transition: transform .15s ease, background .15s ease, color .15s ease;
}
.primary { background: var(--wine); color: var(--card); }
.ghost { background: transparent; color: var(--wine); }
.ghost[aria-pressed="true"] { background: var(--wine); color: var(--card); }
@media (hover: hover) {
  .primary:hover { background: var(--wine-2); border-color: var(--wine-2); }
  .ghost:hover { background: var(--wine); color: var(--card); }
}
.primary:active, .ghost:active { transform: translateY(1px); }
.small { padding: .55em 1em; font-size: 13px; min-height: 36px; }
:focus-visible { outline: 2.5px solid var(--gold); outline-offset: 3px; }
[hidden] { display: none !important; }

/* input-specific affordances: camera only on touch screens, drag & drop / Esc only with a mouse */
.touch-only { display: none !important; }
@media (pointer: coarse) {
  .touch-only { display: inline-flex !important; }
  .pointer-only { display: none !important; }
}

.masthead, .layout, .foot {
  position: relative; z-index: 1; max-width: 1440px; margin: 0 auto; padding-left: var(--gutter-l); padding-right: var(--gutter-r);
}
.masthead {
  z-index: 3; /* its status tip overlaps the layout below */
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap;
  padding-top: max(28px, env(safe-area-inset-top)); padding-bottom: 18px; border-bottom: 1px solid var(--rule);
  animation: rise .6s ease both;
}
.brand { color: inherit; text-decoration: none; border-radius: 8px; }
.brand h1 { transition: opacity .15s ease; }
@media (hover: hover) { .brand:hover h1 { opacity: .78; } }
.kicker { font: 600 13px/1 var(--ui); letter-spacing: .22em; text-transform: uppercase; color: var(--gold); }
h1 { font: 700 clamp(36px, 6vw, 60px)/.95 var(--display); margin: .2em 0 0; letter-spacing: -.01em; }
h1 em { font-style: italic; font-weight: 400; color: var(--wine); }
.status {
  display: inline-flex; align-items: center; gap: .6em; padding: .6em 1em; border-radius: 999px;
  background: var(--card); border: 1px solid var(--rule); color: var(--ink-2);
  font: 500 14px/1.2 var(--ui); letter-spacing: .02em; text-transform: none; box-shadow: var(--shadow);
}
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.status.ready .dot { background: var(--ok); animation: breathe 2.6s ease-in-out infinite; }
.status.busy .dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.status.down .dot { background: var(--bad); }
.status.dev .dot { background: var(--gold); }

.layout {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); grid-template-rows: auto 1fr; gap: 36px;
  padding-top: 28px; padding-bottom: 40px; align-items: start;
}
/* desktop: the photo spans both rows on the left, «Результат» and «Дополнительно» stack on the right */
.stage { grid-row: 1 / span 2; }
.extra { grid-column: 2; }
.stage, .result, .extra { min-width: 0; animation: rise .7s ease both; }
.result { animation-delay: .08s; scroll-margin-top: 12px; }
.stage-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.stage-head h2 { font: 400 26px/1.1 var(--display); margin: 0; font-style: italic; }
.step { font: 700 14px/1 var(--display); color: var(--gold); letter-spacing: .1em; }
.back-btn { margin-left: auto; align-self: center; }
.back-btn svg, .ghost .back-icon { width: 14px; height: 14px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
/* landing: before a photo is chosen the scanner itself is the first screen, without step headings */
[data-phase="idle"] .stage-head { display: none; }

/* ---------- landing / upload (the scanner's empty state) ---------- */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: 12px; min-height: 480px; padding: 36px 28px; border-radius: 22px;
  border: 2px dashed color-mix(in srgb, var(--wine) 45%, var(--rule)); background: color-mix(in srgb, var(--card) 70%, transparent);
  transition: border-color .2s ease, background .2s ease, transform .2s ease;
}
@media (pointer: fine) { .drop { cursor: pointer; } }
@media (hover: hover) { .drop:hover { border-color: var(--wine); background: var(--card); } }
.drop.over { border-color: var(--wine); background: var(--card); transform: scale(1.01); }
.hero-art { width: 96px; height: 120px; margin-bottom: 4px; overflow: visible; }
.art-bottle { fill: color-mix(in srgb, var(--wine) 14%, transparent); stroke: var(--wine); stroke-width: 2.5; }
.art-label { fill: var(--card); stroke: var(--wine); stroke-width: 2; }
.art-line { fill: none; stroke: var(--gold); stroke-width: 2; stroke-linecap: round; }
.art-corner { fill: none; stroke: var(--gold); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.art-scan { fill: var(--gold); opacity: .85; transform: translateY(98px); animation: scan 3.2s ease-in-out infinite; }
.hero-kicker { font: 600 13px/1 var(--ui); letter-spacing: .2em; text-transform: uppercase; color: var(--gold); }
.hero-title { font: 700 clamp(30px, 3.6vw, 44px)/1.08 var(--display); margin: 0; letter-spacing: -.01em; max-width: 17ch; text-wrap: balance; }
.hero-lede { font: 400 clamp(17px, 1.7vw, 19px)/1.5 var(--display); color: var(--ink-2); margin: 0; max-width: 36ch; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.hero-actions .primary { padding: .95em 1.8em; font-size: 16px; }
.drop-hint { font: 15px/1.4 var(--ui); color: var(--ink-2); }
.drop-note { color: var(--muted); font: 14px/1.4 var(--ui); max-width: 34ch; }
@media (pointer: coarse) {
  .pick-btn { background: transparent; color: var(--wine); }
}

.photo { margin: 0; }
.photo-frame {
  position: relative; border-radius: 14px; overflow: hidden; background: var(--paper-2);
  box-shadow: var(--shadow); border: 1px solid var(--rule); touch-action: pan-y;
}
.photo-frame.drawing { cursor: crosshair; touch-action: none; -webkit-user-select: none; user-select: none; }
#preview { display: block; width: 100%; height: auto; max-height: 72vh; object-fit: contain; image-orientation: from-image; -webkit-touch-callout: none; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
.overlay .box { fill: transparent; stroke: #fff; stroke-width: 3; vector-effect: non-scaling-stroke; cursor: pointer; }
.overlay .box-shadow { fill: none; stroke: rgba(0,0,0,.55); stroke-width: 6; vector-effect: non-scaling-stroke; pointer-events: none; }
.overlay .box.active { stroke: var(--gold); stroke-width: 4; }
.overlay .box:focus { outline: none; stroke: var(--gold); }
.overlay .roi { fill: color-mix(in srgb, var(--gold) 18%, transparent); stroke: var(--gold); stroke-width: 3; stroke-dasharray: 8 6; vector-effect: non-scaling-stroke; pointer-events: none; }
.badge { font-family: var(--ui); font-weight: 700; fill: #fff; pointer-events: none; }
.badge-bg { stroke: #fff; stroke-width: 2; vector-effect: non-scaling-stroke; }
.badge-bg { fill: var(--wine); pointer-events: none; }
.badge-bg.active { fill: var(--gold); }
.photo-chip {
  position: absolute; top: 12px; left: 12px; right: 12px; width: fit-content; margin: 0 auto;
  background: rgba(20,10,10,.82); color: #fff; font: 14px/1.3 var(--ui); padding: .55em 1em; border-radius: 999px; text-align: center;
  display: inline-flex; align-items: center; gap: .6em; white-space: nowrap; pointer-events: none;
}
/* frame mode: the hint sits on the photo but lets drags through; the frame itself carries its buttons */
.draw-bar {
  position: absolute; top: 12px; left: 12px; right: 12px; width: fit-content; margin: 0 auto;
  display: flex; align-items: center; gap: 10px; padding: 5px 5px 5px 14px; border-radius: 22px;
  background: rgba(20,10,10,.82); color: #fff; font: 14px/1.3 var(--ui); text-align: left; pointer-events: none;
}
.draw-bar .draw-text { min-width: 0; }
.draw-btn {
  flex: none; min-height: 36px; padding: .5em 1em; border: 0; border-radius: 999px; pointer-events: auto;
  background: rgba(255,255,255,.18); color: #fff; font: 600 13px/1 var(--ui); letter-spacing: .04em; text-transform: uppercase;
  transition: background .15s ease;
}
@media (hover: hover) { .draw-btn:hover { background: rgba(255,255,255,.3); } }

.roi-ui { position: absolute; pointer-events: none; }
.roi-ui.editing { pointer-events: auto; cursor: move; touch-action: none; }
.roi-btn {
  position: absolute; pointer-events: auto; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; background: rgba(20,10,10,.82); color: #fff;
  box-shadow: 0 6px 16px -6px rgba(0,0,0,.6); transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
  animation: pop .2s ease both;
}
.roi-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.roi-btn.go { width: 52px; height: 52px; background: var(--gold); color: #1c1210; }
.roi-btn.go svg { width: 24px; height: 24px; stroke-width: 2.4; }
.roi-btn .i-done, .roi-ui.editing .roi-btn .i-edit { display: none; }
.roi-ui.editing .roi-btn .i-done { display: block; }
.roi-ui.editing .roi-btn.edit { background: var(--gold); color: #1c1210; }
.roi-ui.editing .roi-btn.clear, .roi-ui.editing .roi-btn.go { display: none; }
.roi-handle {
  display: none; position: absolute; width: 24px; height: 24px; margin: -12px; border-radius: 50%;
  background: #fff; border: 3px solid var(--gold); box-shadow: 0 2px 8px rgba(0,0,0,.4); touch-action: none;
}
.roi-ui.editing .roi-handle { display: block; }
.roi-handle[data-handle="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.roi-handle[data-handle="ne"] { right: 0; top: 0; cursor: nesw-resize; }
.roi-handle[data-handle="sw"] { left: 0; bottom: 0; cursor: nesw-resize; }
.roi-handle[data-handle="se"] { right: 0; bottom: 0; cursor: nwse-resize; }
.overlay .roi.editing { stroke-dasharray: none; fill: color-mix(in srgb, var(--gold) 26%, transparent); }
.roi-btn::after {
  content: attr(data-tip); position: absolute; top: 50%; right: calc(100% + 10px); transform: translate(6px, -50%);
  padding: 7px 10px; border-radius: 8px; background: var(--ink); color: var(--paper); white-space: nowrap; pointer-events: none;
  font: 500 13px/1 var(--ui); letter-spacing: normal; text-transform: none; opacity: 0; transition: opacity .2s ease, transform .2s ease;
}
.roi-btn.edit::after { right: auto; left: calc(100% + 10px); transform: translate(-6px, -50%); }
@media (hover: hover) {
  .roi-btn:hover { transform: scale(1.08); box-shadow: 0 0 0 2px rgba(255,255,255,.55), 0 6px 16px -6px rgba(0,0,0,.6); }
  .roi-btn:hover::after { opacity: 1; transform: translate(0, -50%); }
}
.roi-btn:focus-visible::after { opacity: 1; transform: translate(0, -50%); }

/* icon tools on the photo: frame + new photo, with a hover label */
.photo-tools { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.photo-tool {
  position: relative; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; background: rgba(20,10,10,.72); color: #fff;
  transition: background .15s ease, transform .15s ease, box-shadow .15s ease;
}
.photo-tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.photo-tool .dash { stroke-dasharray: 2.2 2; }
.photo-tool::after {
  content: attr(data-tip); position: absolute; right: calc(100% + 10px); top: 50%; transform: translate(6px, -50%);
  padding: 7px 10px; border-radius: 8px; background: var(--ink); color: var(--paper); white-space: nowrap; pointer-events: none;
  font: 500 13px/1 var(--ui); letter-spacing: normal; text-transform: none; opacity: 0; transition: opacity .2s ease, transform .2s ease;
}
.photo-tool:active { transform: scale(.94); }
@media (hover: hover) {
  .photo-tool:hover { background: rgba(20,10,10,.92); transform: scale(1.07); box-shadow: 0 0 0 2px rgba(255,255,255,.5); }
  .photo-tool:hover::after { opacity: 1; transform: translate(0, -50%); }
}
.photo-tool:focus-visible::after { opacity: 1; transform: translate(0, -50%); }
.photo-frame { scroll-margin-top: 12px; }
.spin { width: 12px; height: 12px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; animation: spin .9s linear infinite; flex: none; }
figcaption { color: var(--muted); font: 14px/1.4 var(--ui); margin-top: 8px; overflow-wrap: anywhere; }

.panel { border-radius: 18px; padding: 26px; background: var(--card); border: 1px solid var(--rule); box-shadow: var(--shadow); }
.idle-title { font: 400 26px/1.1 var(--display); font-style: italic; margin: 0 0 14px; }
.idle-sub { font: 600 13px/1 var(--ui); letter-spacing: .18em; text-transform: uppercase; color: var(--gold); margin: 22px 0 10px; }
.howto { margin: 0; padding-left: 1.4em; color: var(--ink-2); }
.howto li { margin: .45em 0; padding-left: .2em; }
.howto li::marker { color: var(--gold); font-family: var(--display); font-weight: 700; }
.howto strong { color: var(--ink); font-weight: 700; }
.gets { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.gets li {
  display: flex; align-items: center; gap: .6em; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 55%, transparent); font: 15px/1.3 var(--ui); color: var(--ink-2);
}
.gets-mark { width: 8px; height: 8px; border-radius: 50%; background: var(--wine); flex: none; }
.muted { color: var(--muted); }

.loading { text-align: center; padding: 44px 26px; }
.pour { width: 16px; height: 120px; margin: 0 auto 18px; border: 2px solid var(--wine); border-radius: 0 0 10px 10px; position: relative; overflow: hidden; }
.pour span { position: absolute; left: 0; right: 0; bottom: 0; background: var(--wine); animation: fill 2.4s ease-in-out infinite; }
.loading-title { font: 400 24px/1.2 var(--display); margin: 0 0 4px; }

.error { border-color: color-mix(in srgb, var(--bad) 45%, var(--rule)); }
.error-title { font: 700 22px/1.2 var(--display); color: var(--bad); margin: 0 0 6px; }
.error.info { border-color: color-mix(in srgb, var(--gold) 55%, var(--rule)); }
.error.info .error-title { color: var(--ink); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

/* short-lived tip under «Результат»: same bubble as the "?" tip, folds away after a few seconds */
.result-tip { display: grid; grid-template-rows: 0fr; opacity: 0; margin-bottom: 0;
  transition: grid-template-rows .4s ease, opacity .3s ease, margin-bottom .4s ease; }
.result-tip.open { grid-template-rows: 1fr; opacity: 1; margin-bottom: 14px; transition-duration: .3s, .22s, .3s; }
.result-tip-clip { min-height: 0; overflow: hidden; padding-top: 6px; }
.result-tip-bubble {
  position: relative; margin: 0; padding: 10px 14px; border-radius: 12px; background: var(--ink); color: var(--paper);
  font: 15px/1.45 var(--ui);
}
.result-tip-bubble::before {
  content: ""; position: absolute; left: 30px; top: -6px;
  border: 6px solid transparent; border-top: 0; border-bottom-color: var(--ink);
}
.result-tip-bubble strong { font-weight: 700; }
.bottle-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.tab {
  border: 1.5px solid var(--rule); background: var(--card); color: var(--ink-2); border-radius: 999px;
  padding: .55em 1em; min-height: 40px; font-size: 14px; text-transform: none; letter-spacing: .02em;
}
.tab[aria-selected="true"] { border-color: var(--wine); background: var(--wine); color: var(--card); }
.tab .hint { font-weight: 400; opacity: .8; }

.bottle-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.bottle-head h3 { margin: 0; font: 400 20px/1.2 var(--display); font-style: italic; }
.bottle-head .actions { margin-top: 0; margin-left: auto; align-items: center; }
.verdict { font: 600 13px/1.3 var(--ui); letter-spacing: .14em; text-transform: uppercase; color: var(--gold); }

.card {
  display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 18px; background: var(--card);
  border: 1px solid var(--rule); border-radius: 18px; padding: 16px; box-shadow: var(--shadow);
  animation: rise .45s ease both;
}
.card.best { border-color: color-mix(in srgb, var(--wine) 45%, var(--rule)); padding: 20px; }
.card-ref {
  position: relative; aspect-ratio: 3 / 4; border-radius: 10px; overflow: hidden; background: #fff; display: grid;
  place-items: center; border: 1px solid var(--rule); align-self: start;
}
.card-ref img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.card-ref .no-ref { font: 13px var(--ui); color: var(--muted); display: none; padding: 8px; text-align: center; }
.card-ref.empty img { display: none; }
.card-ref.empty .no-ref { display: block; }
.card-body { min-width: 0; }
.card-tag { font: 600 12px/1.2 var(--ui); letter-spacing: .18em; text-transform: uppercase; color: var(--gold); }
.card-title { font: 700 clamp(21px, 2.6vw, 27px)/1.15 var(--display); margin: .35em 0 .2em; overflow-wrap: anywhere; }
.card-producer { margin: 0; font: italic 17px/1.35 var(--display); color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: .7em 0 0; }
.chip {
  display: inline-flex; align-items: center; gap: .4em; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--rule); background: color-mix(in srgb, var(--paper) 60%, transparent);
  font: 13px/1.3 var(--ui); color: var(--ink-2); white-space: nowrap;
}
.chip.red::before, .chip.white::before, .chip.rose::before, .chip.orange::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
}
.chip.red::before { background: #8c2a3c; }
.chip.white::before { background: #e8d58e; }
.chip.rose::before { background: #eba3ad; }
.chip.orange::before { background: #d98a3d; }
.card-link { margin-top: 14px; }
.card-link a {
  display: inline-flex; align-items: center; gap: .45em; color: var(--wine); font: 700 15px/1.2 var(--ui);
  letter-spacing: .04em; text-transform: uppercase; text-decoration: none; border-bottom: 1.5px solid currentColor; padding: 6px 0 3px;
}
.card-link .arrow { width: .8em; height: .8em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: hover) { .card-link a:hover { color: var(--wine-2); } }
.card-link .na { font: 14px var(--ui); color: var(--muted); }
.card .slug { display: block; font: 12px/1.3 var(--mono); color: var(--muted); margin-top: 10px; overflow-wrap: anywhere; }

/* your bottle vs the catalogue reference */
.card.with-compare { grid-template-columns: minmax(0, 1fr); }
.card.with-compare > .card-ref { display: none; }
.compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; border-radius: 14px; }
.pane-fig { margin: 0; display: grid; gap: 6px; min-width: 0; }
.pane {
  position: relative; aspect-ratio: 3 / 4; max-height: 320px; border-radius: 12px; overflow: hidden; background: #fff;
  border: 1px solid var(--rule); display: grid; place-items: center;
}
.pane.mine { background: var(--paper-2); }
.pane canvas, .pane img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; }
.pane .no-ref { font: 13px/1.3 var(--ui); color: var(--muted); padding: 8px; text-align: center; }
.pane-fig figcaption { font: 600 12px/1.3 var(--ui); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); text-align: center; overflow-wrap: anywhere; }
.zoomable { cursor: zoom-in; }
@media (hover: hover) { .zoomable:hover .pane, .card-ref.zoomable:hover { border-color: var(--wine); } }

.viewer {
  width: min(980px, calc(100vw - 24px)); max-width: none; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
  padding: 16px; border: 1px solid var(--rule); border-radius: 18px; background: var(--card); color: var(--ink);
  box-shadow: 0 30px 80px -30px rgba(0,0,0,.6); overflow: auto;
}
.viewer::backdrop { background: rgba(15, 8, 8, .66); }
.viewer-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.viewer-head h2 { font: 400 22px/1.2 var(--display); font-style: italic; margin: 0; }
.viewer-body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.viewer .pane { aspect-ratio: auto; height: min(66vh, 720px); height: min(66dvh, 720px); max-height: none; }

.alts-title { font: 400 19px/1.2 var(--display); font-style: italic; margin: 26px 0 10px; display: flex; align-items: baseline; gap: 10px; }
.alts-title span { font: 13px var(--ui); color: var(--muted); font-style: normal; }
.alts { display: grid; gap: 10px; }
.alts .card { grid-template-columns: 64px minmax(0, 1fr); gap: 14px; padding: 12px; border-radius: 14px; box-shadow: none; }
.alts .card-title { font-size: 18px; margin-top: .1em; }
.alts .card-producer { font-size: 15px; }
.alts .card-tag, .alts .slug { display: none; }
.alts .chips { margin-top: 6px; gap: 5px; }
.alts .chip { font-size: 12px; padding: 2px 8px; }
.alts.overview .card-tag { display: block; margin-bottom: .2em; }
.alts .card-link { margin-top: 8px; }
.alts .card-link a { font-size: 13px; }
.pickable { cursor: pointer; transition: border-color .15s ease; }
@media (hover: hover) { .pickable:hover { border-color: var(--wine); } }
.empty-card { padding: 18px; border: 1px dashed var(--rule); border-radius: 14px; color: var(--ink-2); font: 15px/1.45 var(--ui); }
.empty-card p { margin: 6px 0 0; }
.empty-title { display: block; font: 700 19px/1.25 var(--display); color: var(--ink); }
.empty-card .actions { margin-top: 14px; }

/* "?" toggletip */
.help { position: relative; display: inline-flex; align-items: center; gap: 10px; }
.help-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; border-radius: 50%;
  border: 1.5px solid var(--wine); background: transparent; color: var(--wine); font: 700 16px/1 var(--ui); text-transform: none;
}
.help-btn[aria-expanded="true"] { background: var(--wine); color: var(--card); }
@media (hover: hover) { .help-btn:hover { background: var(--wine); color: var(--card); } }
.help-tip {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 5; width: max-content; max-width: min(260px, calc(100vw - 48px));
  padding: 10px 12px; border-radius: 12px; background: var(--ink); color: var(--paper);
  font: 14px/1.4 var(--ui); letter-spacing: normal; text-transform: none; box-shadow: 0 12px 30px -12px rgba(0,0,0,.45);
  opacity: 0; transform: translateY(-6px); transition: opacity .3s ease, transform .3s ease;
}
.help-tip.open { opacity: 1; transform: none; transition-duration: .22s; }
/* with a mouse the tip follows hover on the anchor button, so no "?" */
@media (hover: hover) and (pointer: fine) {
  .help-btn { display: none; }
  .help-tip::before { right: 28px; }
}
.help-tip::before {
  content: ""; position: absolute; right: 12px; top: -6px;
  border: 6px solid transparent; border-top: 0; border-bottom-color: var(--ink);
}


/* a picked file that does not fit: a bubble next to the button that opened the picker */
.file-tip {
  position: absolute; z-index: 40; width: max-content; max-width: min(320px, calc(100vw - 32px));
  padding: 10px 14px; border-radius: 12px; background: var(--ink); color: var(--paper); font: 14px/1.4 var(--ui);
  box-shadow: 0 14px 34px -14px rgba(0,0,0,.55); opacity: 0; transform: translateY(-6px); transition: opacity .3s ease, transform .3s ease;
}
.file-tip.above { transform: translateY(6px); }
.file-tip.open { opacity: 1; transform: none; transition-duration: .22s; }
.file-tip p { margin: 0; }
.file-tip strong { font-weight: 700; }
.file-tip::before {
  content: ""; position: absolute; top: -6px; left: var(--arrow-x, 24px); margin-left: -6px;
  border: 6px solid transparent; border-top: 0; border-bottom-color: var(--ink);
}
.file-tip.above::before { top: auto; bottom: -6px; border: 6px solid transparent; border-bottom: 0; border-top-color: var(--ink); }

/* III «Дополнительно» */
.extra-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.extra .ghost { white-space: normal; text-align: center; }
#extra-downloads, .extra-actions + .extra-actions { margin-top: 10px; }
.tech { margin-top: 16px; border-top: 1px solid var(--rule); padding-top: 6px; font: 14px/1.45 var(--ui); color: var(--muted); }
.tech summary { cursor: pointer; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; font-size: 13px; padding: 8px 0; }
.tech dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; margin: 12px 0; }
.tech dt { color: var(--ink-2); }
.tech dd { margin: 0; font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }

.foot {
  display: flex; justify-content: center; text-align: center; gap: 12px; flex-wrap: wrap; padding-top: 16px;
  padding-bottom: max(28px, calc(env(safe-area-inset-bottom) + 12px));
  border-top: 1px solid var(--rule); color: var(--muted); font: 13px/1.4 var(--ui);
}
.foot #foot-profile { font-family: var(--mono); }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 2px color-mix(in srgb, var(--ok) 30%, transparent); }
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--ok) 6%, transparent); }
}
@keyframes fill { 0% { height: 0; } 60% { height: 100%; } 100% { height: 100%; opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { opacity: 0; scale: .7; } to { opacity: 1; scale: 1; } }
@keyframes scan { 0%, 100% { transform: translateY(62px); } 50% { transform: translateY(134px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* wide screens with a photo: «Дополнительно» becomes a third column that stays in view */
@media (min-width: 1200px) {
  [data-phase="photo"] .layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 264px; grid-template-rows: auto; gap: 30px; }
  [data-phase="photo"] .stage { grid-row: auto; }
  [data-phase="photo"] .extra { grid-column: 3; grid-row: 1; position: sticky; top: 16px; }
  [data-phase="photo"] .extra-actions { flex-direction: column; }
  [data-phase="photo"] .extra .ghost { width: 100%; }
}

/* ---------- tablet & phone: one column ---------- */
@media (max-width: 880px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; gap: 26px; padding-top: 20px; }
  .stage, .extra { grid-row: auto; grid-column: auto; }
  [data-phase="idle"] .layout { gap: 18px; }
  .masthead { padding-top: max(18px, env(safe-area-inset-top)); }
  .drop { min-height: 0; padding: 28px 20px 24px; }
  #preview { max-height: 56vh; max-height: 56svh; }
  .card { grid-template-columns: 96px minmax(0, 1fr); gap: 14px; padding: 14px; }
  .card.best { padding: 14px; }
  .panel { padding: 20px; }
}
@media (max-width: 520px) {
  body { font-size: 16px; }
  .masthead { gap: 10px; padding-bottom: 14px; }
  .kicker { font-size: 11px; letter-spacing: .16em; }
  h1 { font-size: 34px; }
  .status { padding: .5em .85em; font-size: 13px; }
  .hero-art { width: 72px; height: 90px; }
  .hero-title { font-size: 30px; }
  .hero-actions { flex-direction: column; align-self: stretch; }
  .hero-actions .primary { width: 100%; }
  .gets { grid-template-columns: minmax(0, 1fr); }
  .extra-actions .ghost { flex: 1 1 auto; }
  .card { grid-template-columns: 82px minmax(0, 1fr); }
  .card-link a { font-size: 14px; }
  .compare { gap: 8px; }
  .viewer { padding: 12px; }
  .viewer-body { gap: 8px; }
  .viewer .pane { height: min(58vh, 560px); height: min(58dvh, 560px); }
}
