/* Цвета интерфейса берутся из темы Telegram (светлая/тёмная у каждого своя),
   а титульный слайд — из выбранной темы презентации. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f2f5);
  --text: var(--tg-theme-text-color, #15171c);
  --hint: var(--tg-theme-hint-color, #80858f);
  --link: var(--tg-theme-link-color, #2a7ae2);
  --btn: var(--tg-theme-button-color, #2a7ae2);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d64545);
  --line: color-mix(in srgb, var(--text) 10%, transparent);

  /* тема титульного слайда — меняется из app.js */
  --th-bg: #1B2A41;
  --th-text: #ffffff;
  --th-muted: #B9C2D3;
  --th-accent: #B8873B;
  --th-font: Georgia, "Times New Roman", serif;
  --th-weight: 400;

  --r-slide: 10px;
  --r-ctl: 10px;
  --gutter: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17191d);
    --bg2: var(--tg-theme-secondary-bg-color, #22252b);
    --text: var(--tg-theme-text-color, #eceef2);
    --hint: var(--tg-theme-hint-color, #8d939d);
    --link: var(--tg-theme-link-color, #5aa2ff);
    --btn: var(--tg-theme-button-color, #3d8bef);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--btn); outline-offset: 2px; }

/* ---------------------------------------------------------------- шапка */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px var(--gutter);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; background: var(--bg2); padding: 3px; border-radius: 9px; }
.tabs a {
  padding: 5px 14px; border-radius: 7px; text-decoration: none; color: var(--hint);
  font-size: 15px; font-weight: 500;
}
.tabs a[aria-selected="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px var(--line); }
.balance {
  text-decoration: none; color: var(--text); font-size: 15px; font-weight: 500;
  padding: 5px 10px; border-radius: 8px; background: var(--bg2); white-space: nowrap;
}
.balance.zero { color: var(--btn); }

main { padding: 0 var(--gutter) 24px; max-width: 560px; margin: 0 auto; }

/* ---------------------------------------------------------------- титульный слайд */
.slide-wrap { margin: 16px 0 8px; }
.slide {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--th-bg);
  color: var(--th-text);
  border-radius: var(--r-slide);
  padding: 5.5% 6% 5%;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  font-family: var(--th-font);
  overflow: hidden;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--th-bg) 35%, transparent);
  transition: background-color .35s ease, color .35s ease;
}
/* полоса-акцент слева: у каждой темы свой цвет */
.slide::before {
  content: ""; position: absolute; left: 0; top: 18%; bottom: 18%; width: 4px;
  background: var(--th-accent); border-radius: 0 3px 3px 0;
}
.s-kicker {
  font: 700 9.5px/1.2 Arial, sans-serif; letter-spacing: .06em; text-transform: uppercase;
  color: var(--th-accent); min-height: 1.2em;
}
.s-topic {
  align-self: center;
  width: 100%; resize: none; border: 0; padding: 0; margin: 0;
  background: transparent; color: var(--th-text);
  font-family: var(--th-font); font-weight: var(--th-weight);
  font-size: clamp(19px, 6vw, 28px); line-height: 1.15;
  overflow: hidden;
}
.s-topic::placeholder { color: var(--th-muted); opacity: .85; }
.s-topic:focus { outline: none; }
.slide:focus-within { box-shadow: 0 0 0 2px var(--th-accent), 0 6px 20px color-mix(in srgb, var(--th-bg) 35%, transparent); }
.s-meta { font-family: Arial, sans-serif; font-size: 11.5px; line-height: 1.35; color: var(--th-text); }
.s-meta div:empty { display: none; }
.s-meta div + div { color: var(--th-muted); }
.s-meta .placeholder { color: var(--th-muted); font-style: italic; }
.s-foot { font-family: Arial, sans-serif; font-size: 10.5px; color: var(--th-muted); margin-top: 4px; }
.slide-note { margin: 8px 2px 0; font-size: 13px; color: var(--hint); }

/* ---------------------------------------------------------------- форма */
.group { margin-top: 22px; }
.group h2 { margin: 0 0 8px; font-size: 15px; font-weight: 600; }
.hint { margin: 6px 2px 0; font-size: 13px; color: var(--hint); }
.hint:empty { display: none; }

.field {
  display: block; width: 100%; margin-top: 8px;
  padding: 11px 12px; border-radius: var(--r-ctl);
  border: 1px solid transparent; background: var(--bg2);
  resize: vertical;
}
.field:first-of-type { margin-top: 0; }
.chips + .field { margin-top: 8px; }
.field[hidden] { display: none; }
.field:focus { outline: none; border-color: var(--btn); }
.field.invalid { border-color: var(--danger); }
.field::placeholder, textarea::placeholder { color: var(--hint); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  border: 0; padding: 7px 12px; border-radius: 16px;
  background: var(--bg2); font-size: 14.5px;
}
.chips button[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); }

.grades { display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 4px; }
.grades button {
  border: 0; aspect-ratio: 1; border-radius: 8px; background: var(--bg2);
  font-size: 15px; font-variant-numeric: tabular-nums; padding: 0;
}
.grades button[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); }
.grade-letter { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 14px; color: var(--hint); }
.grade-letter input { width: 56px; text-align: center; margin: 0; padding: 7px; }

.segmented { display: flex; background: var(--bg2); border-radius: var(--r-ctl); padding: 3px; }
.segmented button {
  flex: 1; border: 0; background: transparent; padding: 8px 4px; border-radius: 8px; font-size: 15px; color: var(--hint);
}
.segmented button[aria-pressed="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px var(--line); }

.stepper { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stepper button {
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--bg2); font-size: 22px; line-height: 1;
}
.stepper button:disabled { opacity: .35; }
.stepper output { min-width: 2ch; text-align: center; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
/* маленькие прямоугольники = слайды */
.deck { display: flex; flex-wrap: wrap; gap: 3px; flex: 1; min-width: 120px; }
.deck i { width: 14px; height: 9px; border-radius: 2px; background: var(--th-bg); transition: background-color .3s; }
.deck i:first-child { background: var(--th-accent); }

.themes { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.themes button {
  border: 0; padding: 0; background: none; text-align: left; font-size: 13px; color: var(--hint);
}
.themes .mini {
  display: grid; place-items: center; aspect-ratio: 16 / 10; border-radius: 7px; margin-bottom: 5px;
  font-size: 18px; position: relative; overflow: hidden; outline: 2px solid transparent; outline-offset: 2px;
}
.themes .mini::after {
  content: ""; position: absolute; left: 0; top: 25%; bottom: 25%; width: 3px; background: var(--a);
}
.themes .mini.auto { background: conic-gradient(from 200deg, #1B2A41 0 33%, #1F3D2B 0 66%, #0E1320 0); color: #fff; font-size: 13px; }
.themes .mini.auto::after { display: none; }
.themes button[aria-pressed="true"] { color: var(--text); }
.themes button[aria-pressed="true"] .mini { outline-color: var(--btn); }

.spacer { height: 72px; }

/* кнопка внизу, если открыли не в Telegram (в Telegram — его MainButton) */
.cta-fallback {
  position: fixed; left: var(--gutter); right: var(--gutter); bottom: max(12px, env(safe-area-inset-bottom));
  max-width: 528px; margin: 0 auto;
  border: 0; border-radius: 12px; padding: 14px; font-weight: 600;
  background: var(--btn); color: var(--btn-text); z-index: 6;
}
.cta-fallback:disabled { opacity: .5; }
/* чтобы кнопка не закрывала последний блок страницы */
body:has(.cta-fallback:not([hidden])) main { padding-bottom: 88px; }

/* ---------------------------------------------------------------- заказ */
.job { padding-top: 18px; }
.job-title { margin: 0; font-size: 21px; line-height: 1.25; font-weight: 650; }
.job-sub { margin: 4px 0 0; color: var(--hint); font-size: 14px; }
.stages { list-style: none; margin: 20px 0 0; padding: 0; counter-reset: st; }
.stages:empty { display: none; }
.stages li {
  counter-increment: st; position: relative; padding: 9px 0 9px 36px; color: var(--hint);
}
.stages li::before {
  content: counter(st); position: absolute; left: 0; top: 7px;
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; background: var(--bg2); color: var(--hint);
}
.stages li.done { color: var(--text); }
.stages li.done::before { content: "✓"; background: color-mix(in srgb, var(--btn) 18%, transparent); color: var(--btn); }
.stages li.now { color: var(--text); font-weight: 600; }
.stages li.now::before { background: var(--btn); color: var(--btn-text); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--btn) 20%, transparent); } }

.previews { display: grid; gap: 10px; margin-top: 16px; }
.previews:empty { display: none; }
.previews figure { margin: 0; position: relative; }
.previews img {
  display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px;
  background: var(--bg2); border: 1px solid var(--line);
}
.previews figcaption {
  position: absolute; right: 6px; bottom: 6px; font-size: 11px; padding: 1px 6px; border-radius: 6px;
  background: rgba(0, 0, 0, .55); color: #fff; font-variant-numeric: tabular-nums;
}
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.actions[hidden] { display: none; }
.btn {
  border: 0; border-radius: 12px; padding: 13px 10px; font-weight: 600; background: var(--bg2); color: var(--text);
  text-decoration: none; text-align: center;
}
.btn.primary { background: var(--btn); color: var(--btn-text); }
.btn.wide { width: 100%; margin-top: 14px; }

/* ---------------------------------------------------------------- список */
.list { margin: 14px 0 0; padding: 0; list-style: none; }
.list li + li { border-top: 1px solid var(--line); }
.list a { display: flex; gap: 12px; align-items: center; padding: 11px 0; color: inherit; text-decoration: none; }
.thumb {
  flex: none; width: 72px; aspect-ratio: 16 / 9; border-radius: 5px; overflow: hidden; background: var(--bg2);
  display: grid; place-items: center; color: var(--hint); font-size: 12px;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.list .t { font-weight: 500; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.list .m { font-size: 13px; color: var(--hint); margin-top: 2px; }
.list .m.err { color: var(--danger); }
.empty { text-align: center; padding: 48px 12px; color: var(--hint); }
.empty .btn { display: inline-block; margin-top: 14px; padding: 12px 22px; }

/* ---------------------------------------------------------------- пополнение */
.buy h1 { font-size: 21px; margin: 18px 0 4px; }
.buy p { margin: 0; color: var(--hint); font-size: 14px; }
.packs { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.packs button {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  border: 0; padding: 15px 14px; border-radius: 12px; background: var(--bg2); text-align: left;
}
.packs .p-title { font-weight: 600; }
.packs .p-per { font-size: 13px; color: var(--hint); }
.packs .p-price { font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.packs .best { background: color-mix(in srgb, var(--btn) 14%, var(--bg2)); }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: calc(100% - 32px); transition: opacity .2s, transform .2s; pointer-events: none; z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before { transition: none !important; animation: none !important; }
}
