/* ============================================================================
 * UnitBot — Telegram Mini App  ·  white · iOS-native · quiet
 * Rules: system font, ONE size (hierarchy via weight + opacity only),
 * no capitals, no bordered blocks, ≤3 colours (white · ink · system blue).
 * Motion after apple-design skill: instant press feedback, critically-damped
 * springs, cross-fade on reduced-motion.
 * ==========================================================================*/

:root {
  --bg:      #ffffff;
  --blue:    #007aff;
  --blue-2:  #0063cc;

  /* one ink, four opacities — the whole hierarchy lives here */
  --ink:     rgba(0,0,0,0.92);
  --ink-2:   rgba(0,0,0,0.55);
  --ink-3:   rgba(0,0,0,0.30);
  --ink-4:   rgba(0,0,0,0.16);
  --sep:     rgba(0,0,0,0.085);
  --fill:    rgba(120,120,128,0.12);   /* iOS systemFill — controls only */
  --fill-2:  rgba(120,120,128,0.22);

  --pad: 20px;
  --spring: cubic-bezier(0.32, 0.72, 0, 1);
  --out:    cubic-bezier(0.23, 1, 0.32, 1);
  font: 400 17px/1.47 -apple-system, BlinkMacSystemFont, system-ui, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); }

body {
  color: var(--ink);
  font: inherit;
  letter-spacing: -0.012em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
b, strong { font-weight: 600; }

.app {
  max-width: 460px;
  margin: 0 auto;
  padding: 14px var(--pad) calc(120px + env(safe-area-inset-bottom, 0px));
}

/* ── top bar ──────────────────────────────────────────────────────────────*/
.top {
  display: flex; align-items: center; gap: 8px;
  height: 34px; margin-bottom: 18px;
}
.wordmark { font-weight: 600; letter-spacing: -0.02em; }
.wordmark .dot { color: var(--blue); }
.top .demo { margin-left: auto; color: var(--ink-3); }

.back {
  display: none; align-items: center; gap: 3px;
  color: var(--blue); background: none; border: none; padding: 0;
  min-height: 40px;              /* touch target ≥ 40px without growing the bar */
  font: inherit; cursor: pointer; letter-spacing: -0.012em;
  transition: opacity 120ms var(--out);
}
.back:active { opacity: 0.5; }
.back svg { width: 19px; height: 19px; margin-left: -5px; }
/* in a browser, show our own back on a result; inside Telegram, defer to its
   native BackButton and keep the wordmark instead */
body.result:not(.in-tg) .back { display: inline-flex; }
body.result:not(.in-tg) .wordmark, body.result:not(.in-tg) .top .demo { display: none; }

/* ── search head ──────────────────────────────────────────────────────────*/
.searchhead { transition: opacity 200ms var(--out); }
body.result .searchhead { display: none; }

/* segmented control — monochrome, white pill slides over a systemFill track */
.segmented {
  position: relative; display: grid; grid-template-columns: 1fr 1fr;
  background: var(--fill); border-radius: 9px; padding: 2px; height: 40px;
  margin-bottom: 14px; user-select: none;
}
.seg-pill {
  position: absolute; z-index: 1; top: 2px; left: 2px;
  width: calc(50% - 2px); height: calc(100% - 4px);
  background: #fff; border-radius: 7px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.10), 0 1px 1px rgba(0,0,0,0.04);
  transition: transform 320ms var(--spring);
  will-change: transform;
}
.segmented[data-mode='property'] .seg-pill { transform: translateX(100%); }
.seg {
  position: relative; z-index: 2; border: none; background: none; cursor: pointer;
  font: inherit; letter-spacing: -0.012em; color: var(--ink-2);
  transition: color 200ms var(--out);
}
.seg[aria-selected='true'] { color: var(--ink); font-weight: 600; }

/* search field — systemFill pill, no border */
.field {
  display: flex; align-items: center; gap: 8px;
  background: var(--fill); border-radius: 11px; padding: 0 12px; height: 44px;
  transition: background 160ms var(--out);
}
.field svg { width: 18px; height: 18px; color: var(--ink-3); flex: none; }
.field input {
  flex: 1; min-width: 0; border: none; background: none; outline: none;
  font: inherit; letter-spacing: -0.012em; color: var(--ink);
}
.field input::placeholder { color: var(--ink-3); }

/* example suggestions — plain tappable rows, hairline separated, no chips */
.suggest { margin-top: 8px; }
.suggest .s {
  display: flex; align-items: center; gap: 11px;
  padding: 12px 0; border-bottom: 0.5px solid var(--sep);
  cursor: pointer; transition: opacity 120ms var(--out);
  background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%;
  font: inherit; letter-spacing: -0.012em; color: var(--ink); text-align: left;
}
.suggest .s:active { opacity: 0.45; }
.suggest .s:last-child { border-bottom: none; }
.suggest .s svg { width: 16px; height: 16px; color: var(--ink-3); flex: none; }
.suggest .s .lab { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest .s .h { color: var(--ink-3); flex: none; }

.hint { margin-top: 26px; color: var(--ink-2); }

/* ── the resolving chain ──────────────────────────────────────────────────*/
.chain { padding: 6px 0 2px; }
.chain .cl {
  display: flex; align-items: baseline; gap: 8px; padding: 3px 0;
  color: var(--ink-2); opacity: 0; transform: translateY(5px);
}
.chain .cl.in { opacity: 1; transform: none; transition: opacity 260ms var(--out), transform 260ms var(--out); }
.chain .cl .b { color: var(--ink); }
.chain .cl.hit { color: var(--ink); font-weight: 600; }
.chain .cl.hit .b { color: var(--blue); }
.dots { display: inline-flex; gap: 3px; margin-left: 2px; align-self: center; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--ink-3); animation: pulse 1s var(--out) infinite; }
.dots i:nth-child(2){ animation-delay: .15s } .dots i:nth-child(3){ animation-delay: .3s }
@keyframes pulse { 0%,100%{ opacity:.25 } 50%{ opacity:.9 } }

/* ── result flow ──────────────────────────────────────────────────────────*/
#results { }
.blk { margin-top: 30px; }
.blk:first-child { margin-top: 8px; }

/* staggered fade-up — transform+opacity only */
.reveal { opacity: 0; transform: translateY(8px); }
.reveal.in { opacity: 1; transform: none; transition: opacity 380ms var(--out), transform 380ms var(--out); }

/* lowercase section label — recedes via opacity, same size */
.lbl { color: var(--ink-3); margin-bottom: 8px; }

/* headline block (name / punchline) — presence from weight + space, not size */
.headline { font-weight: 600; letter-spacing: -0.022em; }
.strap { color: var(--ink-2); margin-top: 4px; }

/* inline summary — key numbers bold, rest secondary */
.summary { color: var(--ink-2); margin-top: 12px; }
.summary b { color: var(--ink); }
.summary .hot { color: var(--blue); }

/* generic list rows — hairline separators, never a box */
.rows { }
.rw {
  display: flex; align-items: baseline; gap: 12px;
  padding: 11px 0; border-bottom: 0.5px solid var(--sep);
}
.rw:last-child { border-bottom: none; }
.rw .main { flex: 1; min-width: 0; }
.rw .t1 { color: var(--ink); }
.rw .t1 .u { color: var(--ink-3); }
.rw .t2 { color: var(--ink-2); margin-top: 1px; }
.rw .side { flex: none; text-align: right; }
.rw .side .v { color: var(--ink); font-weight: 600; }
.rw .st { color: var(--ink-3); }
.rw .st.vacant { color: var(--blue); }
.rw .st.listed { color: var(--blue); }
.rw.dim { opacity: 0.4; }
.rw.tap { cursor: pointer; transition: opacity 120ms var(--out); }
.rw.tap:active { opacity: 0.45; }

.more { padding: 11px 0; color: var(--blue); cursor: pointer; transition: opacity 120ms var(--out); }
.more:active { opacity: 0.5; }

.note { color: var(--ink-2); margin-top: 12px; }
.note b { color: var(--ink); }

/* phones — struck broker line via opacity */
.rw.broker .t1 { color: var(--ink-3); text-decoration: line-through; }

/* propensity — a thin line, blue on fill, plus text */
.meter { height: 3px; border-radius: 2px; background: var(--fill-2); overflow: hidden; margin: 12px 0 12px; }
.meter i { display: block; height: 100%; width: 100%; background: var(--blue); border-radius: 2px; transform: scaleX(0); transform-origin: left; transition: transform 900ms var(--out); }
.score { font-weight: 600; }
.lead-line { color: var(--ink); margin-top: 12px; }

/* tower x-ray — colour only, no text, no borders */
.stack { display: flex; flex-direction: column; gap: 5px; margin-top: 4px; }
.frow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.cell { height: 20px; border-radius: 4px; background: var(--fill); }
.cell.him { background: rgba(0,122,255,0.32); }
.cell.vac { background: var(--blue); }

/* buttons — the only filled surfaces; still no borders */
.btn {
  display: block; width: 100%; height: 50px; border: none; border-radius: 13px;
  font: inherit; font-weight: 600; letter-spacing: -0.012em; cursor: pointer;
  transition: transform 120ms var(--out), background 150ms var(--out);
}
.btn:active { transform: scale(0.975); }
.btn-blue { background: var(--blue); color: #fff; }
.btn-blue:active { background: var(--blue-2); }
.btn-plain { background: none; color: var(--blue); height: 44px; margin-top: 4px; }
.btn-plain:active { opacity: 0.5; transform: none; }
.actions { margin-top: 26px; }

/* price lines */
.price .pl { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; color: var(--ink-2); }
.price .pl .v { color: var(--ink); font-weight: 600; }
.price .pl .v .up { color: var(--blue); font-weight: 600; }

/* ── paywall sheet ────────────────────────────────────────────────────────*/
.scrim {
  position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,0.28);
  opacity: 0; pointer-events: none; transition: opacity 300ms var(--out);
  backdrop-filter: blur(0.5px);
}
.scrim.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 460px; margin: 0 auto;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 8px var(--pad) calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateY(101%);
  transition: transform 420ms var(--spring);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.14);
  will-change: transform;
}
.sheet.open { transform: none; }
.sheet .grip { width: 36px; height: 5px; border-radius: 3px; background: var(--fill-2); margin: 6px auto 18px; }
.sheet .headline { margin-bottom: 4px; }
.sheet .strap { margin-bottom: 20px; }
.sheet .rw { border-color: var(--sep); }
.sheet .rw .ck { color: var(--blue); flex: none; }
.sheet .btn-blue { margin-top: 22px; }
.sheet .roi { color: var(--ink-3); text-align: center; margin-top: 12px; }

/* ── toast ────────────────────────────────────────────────────────────────*/
.toasts {
  position: fixed; left: 0; right: 0; bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  max-width: 88%; background: rgba(255,255,255,0.86); color: var(--ink);
  border-radius: 13px; padding: 11px 16px;
  box-shadow: 0 6px 26px rgba(0,0,0,0.16), 0 0 0 0.5px rgba(0,0,0,0.05);
  backdrop-filter: blur(20px) saturate(180%);
  opacity: 0; transform: translateY(8px) scale(0.98);
  transition: opacity 240ms var(--out), transform 240ms var(--out);
}
.toast.in { opacity: 1; transform: none; }
.toast .src { color: var(--blue); }

/* ── reduced motion — cross-fade, no movement ─────────────────────────────*/
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 140ms !important; animation-duration: 0.001ms !important; }
  .reveal, .chain .cl { transform: none !important; }
  .seg-pill, .meter i { transition: none !important; }   /* snap, no travel */
  .sheet { transition-timing-function: var(--out) !important; }
}
