/* Властелин скинов — мини-апп. Палитра из аватарки: тёмно-синий фон, золото, изумруд.
   Цвета поверхностей и текста берутся из темы Telegram (JS кладёт их в --c-*), ниже — запасные. */

:root {
  color-scheme: light;
  --c-page: #f3f1ea;
  --c-card: #ffffff;
  --c-text: #14202b;
  --c-hint: #6b7682;
  --c-muted: color-mix(in srgb, var(--c-text) 68%, var(--c-card));
  --c-line: color-mix(in srgb, var(--c-text) 11%, transparent);
  --c-soft: color-mix(in srgb, var(--c-text) 6%, var(--c-card));

  --gold: #e3b341;          /* заливки и акцент */
  --gold-ink: #7a5600;      /* золотой текст на светлом */
  --on-gold: #1c1503;
  --up: #0b7a45;
  --down: #c4202f;
  --up-bg: color-mix(in srgb, var(--up) 14%, var(--c-card));
  --down-bg: color-mix(in srgb, var(--down) 13%, var(--c-card));
  --warn-bg: color-mix(in srgb, var(--gold) 24%, var(--c-card));

  /* категории стратегий: первые 5 проверены validate_palette (adjacent, light), остальные — запас */
  --s0: #eda100; --s1: #2a78d6; --s2: #e87ba4; --s3: #6250d6;
  --s4: #eb6834; --s5: #1baf7a; --s6: #7b8794; --s7: #9a8f2f;

  --r-card: 18px;
  --r-in: 12px;
  --shadow: 0 1px 2px rgba(20, 32, 43, .06), 0 6px 18px rgba(20, 32, 43, .05);
  --ease: cubic-bezier(.22, 1, .36, 1);

  --safe-t: max(env(safe-area-inset-top, 0px), calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)));
  --safe-b: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --safe-l: max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px));
  --safe-r: max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px));
  --nav-h: 60px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --c-page: #0c1822;
  --c-card: #14232f;
  --c-text: #eaf0f5;
  --c-hint: #8aa0b2;
  --c-line: color-mix(in srgb, var(--c-text) 12%, transparent);
  --gold-ink: #f0c65a;
  --up: #3ddc97;
  --down: #ff7b7b;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 8px 24px rgba(0, 0, 0, .25);

  /* dark-ступени, проверено на поверхности #15222e */
  --s0: #c98500; --s1: #3987e5; --s2: #d55181; --s3: #9085e9;
  --s4: #d95926; --s5: #199e70; --s6: #8aa0b4; --s7: #b5a642;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--c-page); color: var(--c-text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  overflow-x: hidden;
  accent-color: var(--gold);
  caret-color: var(--gold);
}
::selection { background: color-mix(in srgb, var(--gold) 45%, transparent); color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 8px; }
h1, h2, h3, p { margin: 0; }
svg { display: block; }

.app {
  max-width: 560px; margin: 0 auto;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 16px) calc(var(--nav-h) + var(--safe-b) + 28px) calc(var(--safe-l) + 16px);
}
.stack > * + * { margin-top: 12px; }
.sec { margin-top: 28px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.sec-head h2 { font-size: 19px; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; }
.sec-head .aside { color: var(--c-muted); font-size: 13px; }
.link { color: var(--gold-ink); font-weight: 600; font-size: 14px; padding: 6px 0; }

.muted { color: var(--c-muted); }
.sm { font-size: 13px; }
.xs { font-size: 12px; }
.up { color: var(--up); }
.down { color: var(--down); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- шапка ---------- */
.top { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.top img.logo { width: 36px; height: 36px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--gold) 70%, transparent); }
.top .brand { font-weight: 700; font-size: 16px; letter-spacing: -.01em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-paper {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  height: 32px; padding: 0 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--warn-bg); color: var(--c-text);
}
.chip-paper svg { width: 14px; height: 14px; }
.back {
  display: inline-flex; align-items: center; gap: 2px; height: 44px; margin-left: -8px; padding: 0 10px 0 4px;
  color: var(--gold-ink); font-weight: 600; font-size: 16px;
}
.back svg { width: 22px; height: 22px; }

.explain, .banner {
  margin-top: 10px; padding: 12px 14px; border-radius: var(--r-in); font-size: 14px; line-height: 1.45;
  background: var(--warn-bg);
}
.banner.err { background: var(--down-bg); }
.explain[hidden] { display: none; }

/* ---------- итог ---------- */
.verdict { padding: 20px 4px 4px; }
.verdict .state-line { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; color: var(--c-muted); }
.verdict .state-line .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c-hint); }
.verdict.pos .dot { background: var(--up); } .verdict.neg .dot { background: var(--down); }
.verdict .big { margin-top: 6px; font-size: 42px; line-height: 1.05; font-weight: 800; letter-spacing: -.03em; }
.verdict .pct-line { margin-top: 4px; font-size: 17px; font-weight: 600; }
.verdict .journey { margin-top: 14px; display: flex; align-items: center; gap: 10px; font-size: 15px; }
.verdict .journey .from { color: var(--c-muted); }
.verdict .journey .arrow { width: 18px; height: 18px; color: var(--c-hint); flex: none; }
.verdict .journey b { font-weight: 700; }
.verdict .facts { margin-top: 10px; color: var(--c-muted); font-size: 14px; line-height: 1.5; }

.pill {
  display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 13px; font-weight: 700; white-space: nowrap; background: var(--c-soft); color: var(--c-muted);
}
.pill.up { background: var(--up-bg); color: var(--up); }
.pill.down { background: var(--down-bg); color: var(--down); }
.pill.gold { background: var(--gold); color: var(--on-gold); }
.pill svg { width: 12px; height: 12px; }

/* ---------- карточки ---------- */
.card { background: var(--c-card); border-radius: var(--r-card); box-shadow: var(--shadow); }
.card.pad { padding: 14px 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card-head h3 { font-size: 16px; font-weight: 700; }

.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--c-soft); gap: 2px; }
.seg button { height: 30px; padding: 0 12px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--c-muted); transition: background .18s var(--ease), color .18s var(--ease); }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--c-card); color: var(--c-text); box-shadow: 0 1px 3px rgba(0, 0, 0, .14); }
.seg.wide { display: flex; width: 100%; }
.seg.wide button { flex: 1; height: 38px; text-align: center; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--c-muted); }
.sw { width: 10px; height: 10px; border-radius: 3px; flex: none; background: var(--sc, var(--c-hint)); }
.sw.round { border-radius: 50%; }

.chart-host { position: relative; margin: 8px -4px 0; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.chart-host svg { overflow: visible; }
.chart-host .grid { stroke: var(--c-line); stroke-width: 1; }
.chart-host .base { stroke: var(--c-hint); stroke-width: 1; stroke-dasharray: 4 4; opacity: .8; }
.chart-host .tick { fill: var(--c-muted); font-size: 11px; }
.chart-host .endlab { fill: var(--c-text); font-size: 12px; font-weight: 700; }
.chart-host .ln { fill: none; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart-host .cross { stroke: var(--c-text); stroke-width: 1; opacity: .35; }
.chart-host .ring { stroke: var(--c-card); stroke-width: 2; }
.tip {
  position: absolute; top: 0; z-index: 2; pointer-events: none; min-width: 150px; max-width: 230px;
  padding: 8px 10px; border-radius: 10px; font-size: 12px; line-height: 1.35;
  background: var(--c-text); color: var(--c-card); box-shadow: 0 6px 20px rgba(0, 0, 0, .28);
}
.tip .t { opacity: .75; margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 6px; }
.tip .r i { width: 8px; height: 8px; border-radius: 2px; background: var(--sc); flex: none; }
.tip .r span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip .r b { font-weight: 700; }
.chart-empty { padding: 36px 8px; text-align: center; color: var(--c-muted); font-size: 14px; }

details.data { margin-top: 10px; border-top: 1px solid var(--c-line); padding-top: 8px; }
details.data summary { cursor: pointer; font-size: 13px; color: var(--c-muted); padding: 6px 0; list-style: none; }
details.data summary::-webkit-details-marker { display: none; }
details.data summary::after { content: " ▾"; }
details.data[open] summary::after { content: " ▴"; }
details.data table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
details.data th { text-align: right; font-weight: 600; color: var(--c-muted); padding: 4px 0 4px 8px; }
details.data td { text-align: right; padding: 5px 0 5px 8px; border-top: 1px solid var(--c-line); }
details.data th:first-child, details.data td:first-child { text-align: left; padding-left: 0; }

/* ---------- стратегии ---------- */
.strat {
  display: block; width: 100%; padding: 14px 16px 14px; transition: transform .18s var(--ease);
}
.strat:active { transform: scale(.985); }
.strat .row1 { display: flex; align-items: center; gap: 8px; }
.strat .row1 h3 { font-size: 16px; font-weight: 700; flex: 1; min-width: 0; }
.strat .chev { width: 18px; height: 18px; color: var(--c-hint); flex: none; }
.strat .desc { margin-top: 4px; color: var(--c-muted); font-size: 13px; line-height: 1.4; }
.strat .row3 { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.strat .eq { font-size: 24px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.strat .eq-sub { margin-top: 6px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.strat .spark { flex: none; }
.strat .foot { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--c-line); font-size: 13px; color: var(--c-muted); display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.strat .foot b { color: var(--c-text); font-weight: 600; }
.spark path.l { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; stroke: var(--sc); }
.spark .b { stroke: var(--c-hint); stroke-width: 1; stroke-dasharray: 3 3; opacity: .7; }

/* ---------- предметы ---------- */
.items { overflow: hidden; }
.item { display: block; width: 100%; padding: 12px 14px; }
.item + .item { border-top: 1px solid var(--c-line); }
.item .main { display: flex; gap: 12px; align-items: center; }
.pic {
  width: 64px; height: 48px; flex: none; border-radius: 10px; position: relative; overflow: hidden;
  background: linear-gradient(110deg, var(--c-soft) 30%, color-mix(in srgb, var(--c-text) 12%, var(--c-card)) 50%, var(--c-soft) 70%) 0 0 / 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity .25s ease; }
.pic.ok { animation: none; background: var(--c-soft); }
.pic.ok img { opacity: 1; }
.pic.none { animation: none; background: var(--c-soft); }
.pic.none img { display: none; }
.pic.none::after { content: ""; position: absolute; inset: 0; background: center / 26px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a96a3' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 17l5-9 4 6 3-4 6 7z'/%3E%3C/svg%3E"); }
@keyframes shimmer { to { background-position: -200% 0; } }
.item .info { flex: 1; min-width: 0; }
.item .w { font-size: 12px; color: var(--c-muted); display: flex; align-items: center; flex-wrap: wrap; gap: 2px 8px; }
.item .n { font-size: 15px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.item .wear { font-size: 12px; color: var(--c-muted); }
.item .price { text-align: right; flex: none; }
.item .price b { display: block; font-size: 15px; font-weight: 700; }
.item .price span { font-size: 12px; color: var(--c-muted); }
.tag { display: inline-block; padding: 0 6px; border-radius: 5px; font-size: 11px; font-weight: 700; background: color-mix(in srgb, var(--s5) 18%, var(--c-card)); color: var(--c-text); line-height: 17px; }
.item .meta { margin-top: 10px; display: grid; gap: 6px; font-size: 13px; }
.bar { height: 5px; border-radius: 3px; background: var(--c-soft); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; background: var(--gold); transition: width .6s var(--ease); }
.item .meta .line { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.item .more { display: none; margin-top: 4px; padding: 10px 12px; border-radius: 10px; background: var(--c-soft); font-size: 13px; line-height: 1.55; }
.item.open .more { display: block; }
.item .more div { display: flex; justify-content: space-between; gap: 12px; }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 calc(-16px - var(--safe-r)) 0 calc(-16px - var(--safe-l)); padding: 2px calc(16px + var(--safe-r)) 2px calc(16px + var(--safe-l)); scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 999px;
  background: var(--c-card); box-shadow: inset 0 0 0 1px var(--c-line); font-size: 14px; font-weight: 600; color: var(--c-muted);
  transition: background .18s var(--ease), color .18s var(--ease);
}
.chip[aria-pressed="true"] { background: var(--c-text); color: var(--c-card); box-shadow: none; }

.summary { padding: 14px 16px; display: grid; gap: 4px; }
.summary .big { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }

.empty { padding: 28px 20px; text-align: center; color: var(--c-muted); font-size: 14px; line-height: 1.5; }
.empty svg { width: 40px; height: 40px; margin: 0 auto 10px; color: var(--c-hint); }
.empty b { display: block; color: var(--c-text); font-size: 16px; margin-bottom: 4px; }

/* ---------- как работает ---------- */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: s; display: grid; gap: 12px; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 28px 1fr; gap: 12px; align-items: start; font-size: 14px; line-height: 1.45; }
.steps li::before { content: counter(s); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: color-mix(in srgb, var(--gold) 30%, var(--c-card)); color: var(--c-text); }
.steps b { display: block; font-size: 15px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--c-line); border-radius: var(--r-in); overflow: hidden; }
.kv > div { background: var(--c-card); padding: 12px 14px; }
.kv .k { font-size: 12px; color: var(--c-muted); }
.kv .v { margin-top: 2px; font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.kv .v small { font-size: 12px; color: var(--c-muted); font-weight: 500; }

.foot-note { margin-top: 28px; font-size: 12px; line-height: 1.55; color: var(--c-muted); }

/* ---------- нижняя навигация ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; height: calc(var(--nav-h) + var(--safe-b)); padding: 6px calc(var(--safe-r) + 8px) var(--safe-b) calc(var(--safe-l) + 8px);
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--c-card) 94%, transparent); border-top: 1px solid var(--c-line);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
}
.nav-in { display: flex; width: 100%; max-width: 560px; gap: 4px; }
.nav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 12px; font-size: 12px; font-weight: 600; color: var(--c-muted); min-height: 48px; }
.nav button svg { width: 24px; height: 24px; }
.nav button[aria-current="page"] { color: var(--gold-ink); }
.nav button[aria-current="page"] svg { stroke-width: 2.2; }
.nav .cnt { font-weight: 700; font-size: 11px; background: var(--gold); color: var(--on-gold); border-radius: 999px; padding: 0 6px; margin-left: 4px; line-height: 16px; }
.nav .lab { display: inline-flex; align-items: center; }

/* ---------- скелет, ошибки ---------- */
.sk { border-radius: 10px; background: linear-gradient(110deg, var(--c-soft) 30%, color-mix(in srgb, var(--c-text) 12%, var(--c-card)) 50%, var(--c-soft) 70%) 0 0 / 200% 100%; animation: shimmer 1.4s linear infinite; }
.errscreen { padding: 56px 12px; text-align: center; }
.errscreen img { width: 96px; height: 96px; border-radius: 50%; margin: 0 auto 20px; filter: grayscale(.4); opacity: .9; }
.errscreen h1 { font-size: 24px; letter-spacing: -.02em; }
.errscreen p { margin: 10px auto 22px; max-width: 320px; color: var(--c-muted); line-height: 1.5; }
.btn { display: inline-flex; align-items: center; justify-content: center; height: 46px; padding: 0 24px; border-radius: 14px; font-weight: 700; background: var(--gold); color: var(--on-gold); }
.btn:active { filter: brightness(.94); }

.view { animation: fade .28s var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (hover: hover) {
  .strat:hover, .item:hover, .chip:hover { filter: brightness(.98); }
  .seg button:hover { color: var(--c-text); }
}
@media (max-width: 359px) {
  .verdict .big { font-size: 36px; }
  .strat .eq { font-size: 21px; }
  .item .price b { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
