:root {
  color-scheme: light;
  --paper: #fbf5ed;
  --ink: #342021;
  --muted: #745855;
  --accent: #c32147;
  --accent-dark: #a0193a;
  --blush: #f8e1e0;
  --cream: #fffaf4;
  --line: #ecd8d0;
  --serif: "Playfair Display", Georgia, serif;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --stage-gap: clamp(12px, 3vh, 30px);
  --app-width: 428px;
  --app-height: min(802px, calc(100vh - var(--stage-gap) * 2));
  --shell-radius: 34px;
  --screen-gutter: 16px;
  --frame-shadow: 0 25px 75px #5c252a24, 0 4px 16px #5c252a15;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding: var(--stage-gap);
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 57% 43%, #f6d3d2 0, #f9e5dc 36%, transparent 68%),
    var(--paper);
}

body:has(dialog[open]) { overflow: hidden; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, [tabindex="0"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.icon-library, .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.app-shell, .conversation {
  width: min(100%, var(--app-width));
  border: 1px solid #ead4ca;
  border-radius: var(--shell-radius);
  background: var(--cream);
  box-shadow: var(--frame-shadow);
}

.app-shell {
  min-height: 510px;
  height: var(--app-height);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overflow: clip;
}

.site-header, .site-footer {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-inline: var(--screen-gutter);
}

.site-header {
  padding-top: max(9px, env(safe-area-inset-top));
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
}

.wordmark { display: flex; align-items: center; gap: 7px; font-size: clamp(18px, 5.6vw, 22px); font-weight: 800; letter-spacing: -.053em; }
.wordmark img { display: block; width: 33px; height: 33px; }
.wordmark-accent { color: var(--accent); }

.matches-button {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 8px 0 10px;
  border: 1px solid var(--line);
  border-radius: 100px;
  color: var(--ink);
  background: #fff;
  font-size: 13px;
  font-weight: 750;
}

.matches-button:hover { border-color: #dca9a8; }
.matches-button .icon { width: 18px; height: 18px; color: var(--accent); }
#match-count { min-width: 23px; padding: 3px 6px; border-radius: 50px; color: var(--accent-dark); background: var(--blush); font-variant-numeric: tabular-nums; text-align: center; }

.main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  flex: 1;
  min-height: 0;
  padding: 12px var(--screen-gutter) 10px;
}

.intro { text-align: center; }
.intro h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(20px, 5.8vw, 24px);
  line-height: 1.12;
  letter-spacing: -.045em;
  font-weight: 600;
  text-wrap: balance;
}
.intro h1 em { color: var(--accent); }
.intro-body { max-width: 345px; margin: 5px auto 0; color: var(--muted); font-size: 12px; line-height: 1.38; text-wrap: pretty; }
.intro-cta { color: var(--ink); font-weight: 750; }

.swipes {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  min-width: 0;
  min-height: 0;
}

.deck {
  position: relative;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  isolation: isolate;
  margin: 0 4px;
  min-width: 0;
  min-height: 0;
}

.deck::before, .deck::after {
  position: absolute;
  inset: 5px 2px 0;
  z-index: -1;
  border: 1px solid #e7b9b4;
  border-radius: 24px;
  transform: translate(4px, 3px) rotate(1.6deg);
  background: #edc2bb;
  content: "";
}

.deck::after { transform: translate(-4px, 3px) rotate(-1.6deg); background: var(--blush); }

.card, .deck-end, .deck-noscript {
  position: relative;
  grid-area: 1 / 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  border: 1px solid #34202126;
  border-radius: 24px;
  box-shadow: 0 7px 20px #5630302b;
}

.card {
  display: flex;
  align-items: flex-end;
  color: white;
  background: #593338;
  user-select: none;
  touch-action: pan-y pinch-zoom;
  cursor: grab;
}

.card.is-dragging { cursor: grabbing; }
.portrait, .card-gradient { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.portrait { object-fit: cover; object-position: center 34%; }
.card-gradient { background: linear-gradient(180deg, transparent 36%, #1b0d111c 53%, #1b0d11b3 77%, #1b0d11f0 100%); }
.portrait-status { position: absolute; top: 42%; width: 100%; padding: 0 12px; color: #fffaf4; font-size: 13px; text-align: center; pointer-events: none; }
.card[data-portrait-state="loading"] .portrait-status::before { content: "Загружаем портрет…"; animation: portrait-status-in .14s .18s both; }
.card[data-portrait-state="unavailable"] .portrait-status::before { content: "Портрет временно недоступен"; }
@keyframes portrait-status-in { from { opacity: 0; } }
.card-caption { position: relative; width: 100%; padding: 16px 18px 18px; text-shadow: 0 1px 7px #1e0a0caa; }
.role { display: inline-block; padding: 4px 10px; border: 1px solid #ffffff63; border-radius: 50px; color: #fffaf4; background: #2b171bc9; font-size: 12px; font-weight: 700; line-height: 1.3; }
.card-caption h2 { margin: 3px 0 0; font: 700 48px/.96 var(--serif); letter-spacing: -.055em; }
.card-caption p { margin: 7px 0 0; color: #fffaf4; font-size: 14px; line-height: 1.36; }

.stamp {
  position: absolute;
  z-index: 1;
  top: 22px;
  left: 17px;
  padding: 5px 10px;
  border: 3px solid currentColor;
  border-radius: 8px;
  color: #d9ffd4;
  background: #232728c9;
  font-size: 25px;
  font-weight: 850;
  letter-spacing: .05em;
  opacity: 0;
  transform: rotate(-10deg);
  pointer-events: none;
}

.stamp[data-decision="pass"] { inset-inline: auto 17px; color: #ffd5d1; transform: rotate(10deg); }

.deck-actions {
  width: min(100%, 282px);
  margin: 14px auto 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: start;
  justify-items: center;
}

.swipe-button {
  display: grid;
  gap: 3px;
  justify-items: center;
  min-width: 84px;
  padding: 0 2px 2px;
  border: 0;
  border-radius: 18px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  font-weight: 750;
  -webkit-tap-highlight-color: transparent;
}

.swipe-button .icon {
  width: 54px;
  height: 54px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--accent-dark);
  background: #fff;
  box-shadow: 0 3px 7px #5c252a13;
  transition: background .15s, transform .15s;
}
.swipe-button:active:not(:disabled) .icon, .solid-button:active { transform: scale(.94); }
.pass-button:hover .icon { background: var(--blush); }
.like-button { color: var(--accent-dark); }
.like-button .icon { fill: currentColor; stroke-width: 1; color: #fff; border-color: transparent; background: var(--accent); box-shadow: 0 4px 10px #a0193a39; }
.like-button:hover .icon, .solid-button:hover, .send-button:hover { background: var(--accent-dark); }
.deck-count { align-self: start; margin-top: 20px; color: var(--muted); white-space: nowrap; font-size: 12px; font-weight: 750; font-variant-numeric: tabular-nums; }
.deck-hint { margin: 4px 0 0; color: var(--muted); font-size: 11px; text-align: center; }

.deck-end, .deck-noscript { display: grid; gap: 12px; align-content: center; justify-items: center; padding: 16px; text-align: center; background: var(--cream); }
.deck-end img { width: clamp(44px, 8vh, 68px); height: auto; }
.deck-end h2 { margin: 0; font: 500 clamp(26px, 5vh, 44px)/.99 var(--serif); letter-spacing: -.055em; }
.deck-end p { margin: 0; line-height: 1.4; color: var(--muted); }
.solid-button { display: inline-flex; align-items: center; gap: 7px; min-height: 48px; padding: 0 15px; border: 0; border-radius: 100px; color: white; background: var(--accent); font-weight: 700; }
.solid-button .icon { width: 18px; height: 18px; }
.deck-noscript { margin: 0; }

.site-footer { min-height: 34px; padding-block: 3px max(3px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.site-footer small { font-size: inherit; }
.site-footer a { display: flex; align-items: center; gap: 2px; min-height: 26px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.site-footer a:hover { text-decoration: underline; }

.conversation {
  position: fixed;
  inset: 0;
  width: min(calc(100% - var(--stage-gap) * 2), var(--app-width));
  height: min(100%, var(--app-height));
  max-width: none;
  max-height: none;
  margin: auto;
  padding: 0;
  overflow: hidden;
  color: var(--ink);
}

.conversation[open] { animation: appear .17s ease-out; }
.conversation::backdrop { background: #30172525; }
@keyframes appear { from { opacity: 0; transform: translateY(6px); } }
.conversation-shell { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100%; }
.conversation-header { display: flex; align-items: center; gap: 9px; padding: max(10px, env(safe-area-inset-top)) var(--screen-gutter) 10px; border-bottom: 1px solid var(--line); }
.conversation-heading { flex: 1; min-width: 0; }
.conversation-heading h2 { margin: 0; font: 600 27px/1 var(--serif); letter-spacing: -.043em; }
.conversation-heading h2:focus { outline: none; }
.conversation-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.avatar { flex: none; display: block; object-fit: cover; object-position: center 27%; border-radius: 50%; background: var(--blush); }
.icon-button, .send-button { flex: none; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; color: var(--ink); background: var(--blush); }
.icon-button:hover { color: var(--accent-dark); background: #f3d6d3; }

.conversation-body { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 0; }
.transcript { display: flex; flex-direction: column; align-items: flex-start; gap: 9px; min-height: 0; padding: 17px var(--screen-gutter); overflow: auto; overscroll-behavior: contain; scrollbar-color: #d7aeaa transparent; }
.transcript:focus-visible { outline-offset: -3px; }
.bubble { flex: none; max-width: 88%; padding: 10px 13px; border-radius: 15px 15px 15px 4px; color: var(--ink); background: #f5e4de; line-height: 1.45; font-size: 15px; }
.bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.is-visitor { align-self: flex-end; background: var(--accent); color: white; border-radius: 15px 15px 4px 15px; }
.prompt-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 9px; }
.bubble .prompt-draft { margin-top: 9px; padding: 9px 10px; border-radius: 8px; background: var(--cream); font-size: 14px; }
.chat-projects { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 119px), 1fr)); gap: 5px; margin: 9px 0 0; padding: 0; list-style: none; }
.chat-projects a { display: grid; gap: 2px; min-height: 45px; height: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; color: var(--accent-dark); background: var(--cream); text-decoration: none; line-height: 1.25; }
.chat-projects a:hover { background: var(--blush); }
.chat-projects strong { font-size: 13px; }
.chat-projects span { font-size: 11px; }
.chat-suggestions { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { width: fit-content; min-height: 36px; padding: 4px 10px; border: 1px solid #e3bab8; border-radius: 100px; background: var(--cream); color: var(--accent-dark); font-size: 13px; font-weight: 700; }
.chip:hover { background: var(--blush); }
.chat-input-area { display: grid; gap: 7px; padding: 10px var(--screen-gutter) max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.composer { display: flex; align-items: center; gap: 8px; }
.composer input { width: 100%; min-width: 0; min-height: 44px; padding: 8px 13px; border: 1px solid #e7cdc6; border-radius: 100px; font-size: 16px; color: var(--ink); background: white; }
.composer input::placeholder { color: var(--muted); }
.send-button { background: var(--accent); color: white; }
.continue-button { min-height: 44px; padding: 5px 8px; border: 0; border-radius: 10px; background: transparent; color: var(--accent-dark); font-size: 14px; font-weight: 750; }
.continue-button:hover { background: var(--blush); }

.match-view { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 8px; min-height: 0; padding: 12px var(--screen-gutter) max(8px, env(safe-area-inset-bottom)); }
.empty-matches { grid-row: 1; margin: 4px 0; padding: 14px 12px; color: var(--muted); background: #f7eae3; border-radius: 13px; }
.match-list { grid-row: 2; margin: 0; padding: 3px 4px; overflow: auto; overscroll-behavior: contain; list-style: none; }
.match-list li + li { margin-top: 7px; }
.match-view .continue-button { grid-row: 3; }
.match-row { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 13px; text-align: left; background: white; color: var(--ink); }
.match-row:hover { background: var(--blush); }
.match-row span { flex: 1; font-size: 14px; font-weight: 700; }
.match-row > .icon { color: var(--accent); margin-right: 7px; }

@media (max-width: 540px) {
  :root {
    --stage-gap: 0px;
    --app-width: 100%;
    --app-height: 100vh;
    --shell-radius: 0px;
  }

  .app-shell, .conversation { border: 0; box-shadow: none; }
}

@supports (height: 100dvh) {
  :root { --app-height: min(802px, calc(100dvh - var(--stage-gap) * 2)); }

  @media (max-width: 540px) {
    :root { --app-height: 100dvh; }
  }
}

@media (max-width: 360px), (max-height: 660px) {
  :root { --screen-gutter: 12px; }

  .site-header { padding-top: max(5px, env(safe-area-inset-top)); padding-bottom: 5px; }
  .main { gap: 8px; padding-block: 8px 6px; }
  .intro h1 { font-size: 20px; }
  .card-caption { padding: 12px 14px 14px; }
  .card-caption h2 { font-size: 40px; }
  .card-caption p { font-size: 13px; }
  .deck-actions { margin-top: 11px; }
  .swipe-button .icon { width: 46px; height: 46px; padding: 10px; }
  .deck-count { margin-top: 16px; }
}

@media (pointer: coarse) {
  .deck-hint .keyboard-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
