/* ===== Theme tokens (fed by Telegram theme params, with sane fallbacks) ===== */
:root {
  --bg: #f2f3f5;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --text: #0f1115;
  --hint: #8a8f98;
  --separator: rgba(0, 0, 0, .08);
  --accent: #2b7fff;
  --accent-text: #ffffff;
  --shadow: 0 6px 24px rgba(15, 17, 21, .10);
  --shadow-sm: 0 2px 10px rgba(15, 17, 21, .07);
  --radius: 20px;
  --radius-sm: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f12;
    --surface: #17181c;
    --surface-2: #1f2127;
    --text: #f4f5f7;
    --hint: #9aa0aa;
    --separator: rgba(255, 255, 255, .10);
    --shadow: 0 8px 28px rgba(0, 0, 0, .45);
    --shadow-sm: 0 2px 12px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { min-height: 100vh; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
img { display: block; max-width: 100%; }

/* ===== Layout ===== */
.screen {
  padding: calc(var(--safe-top) + 8px) 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
  max-width: 720px;
  margin: 0 auto;
  animation: fade-in .28s ease both;
}

.page-title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 12px 2px 16px;
}

.section-label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--hint);
  margin: 22px 4px 12px;
}

/* ===== Tab bar ===== */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: stretch;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--separator);
  z-index: 40;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--hint);
  transition: color .18s, transform .12s;
}
.tab svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab span { font-size: 11px; font-weight: 600; letter-spacing: .01em; }
.tab.active { color: var(--accent); }
.tab:active { transform: scale(.92); }

/* ===== Cards grid ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform .14s ease, box-shadow .14s ease;
  will-change: transform;
}
.card:active { transform: scale(.97); box-shadow: var(--shadow); }

.card .cover {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  overflow: hidden;
}
.card .cover img {
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .35s ease;
}
.card .cover img.loaded { opacity: 1; }
.fallback {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-weight: 800;
  color: color-mix(in srgb, var(--accent) 55%, var(--hint));
  background:
    radial-gradient(120% 90% at 15% 12%, color-mix(in srgb, var(--accent) 20%, var(--surface-2)), transparent 60%),
    linear-gradient(135deg, var(--surface-2), color-mix(in srgb, var(--accent) 10%, var(--surface-2)));
}
.fallback svg {
  width: 34%; max-width: 64px; height: auto;
  fill: none; stroke: currentColor; stroke-width: 1.4;
  stroke-linecap: round; stroke-linejoin: round;
  opacity: .8;
}
.card .body { padding: 11px 12px 13px; }
.card .name { font-size: 14.5px; font-weight: 650; letter-spacing: -0.01em; }
.card .meta { margin-top: 4px; font-size: 12px; color: var(--hint); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* list style card (guides / videos) */
.list { display: flex; flex-direction: column; gap: 12px; }
.row {
  display: flex;
  gap: 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform .14s ease;
}
.row:active { transform: scale(.985); }
.row .thumb {
  position: relative;
  flex: 0 0 116px;
  aspect-ratio: 1 / 1;
  background: var(--surface-2);
}
.row .thumb img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .35s; }
.row .thumb img.loaded { opacity: 1; }
.row .thumb .fallback { font-size: 24px; }
.row .thumb .fallback svg { width: 40%; }
.row .rbody { flex: 1; min-width: 0; padding: 12px 14px 12px 0; display: flex; flex-direction: column; justify-content: center; }
.row .rtitle { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.row .rsub { margin-top: 3px; font-size: 12.5px; color: var(--hint); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row .play {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(0, 0, 0, .5); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.row .play svg { width: 18px; height: 18px; fill: #fff; stroke: none; margin-left: 2px; }

/* ===== Search + chips ===== */
.search {
  position: relative;
  margin: 4px 2px 14px;
}
.search input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--separator);
  outline: none;
  font-size: 15px;
  box-shadow: var(--shadow-sm);
}
.search input::placeholder { color: var(--hint); }
.search svg {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; fill: none; stroke: var(--hint); stroke-width: 2; stroke-linecap: round;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 12px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--separator);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  transition: transform .12s;
}
.chip:active { transform: scale(.94); }
.chip.active { background: var(--accent); color: var(--accent-text); border-color: transparent; }

/* ===== Promo carousel ===== */
.promo-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 2px 2px 6px;
  margin: 0 -2px 6px;
  scrollbar-width: none;
}
.promo-strip::-webkit-scrollbar { display: none; }
.promo {
  flex: 0 0 82%;
  scroll-snap-align: start;
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 156px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #7a3cff));
  color: #fff;
  box-shadow: var(--shadow);
  display: flex;
}
.promo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .4s; }
.promo img.loaded { opacity: 1; }
.promo .scrim { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,.05), rgba(0,0,0,.55)); }
.promo .pbody { position: relative; align-self: flex-end; padding: 16px; }
.promo .ptitle { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }
.promo .ptext { margin-top: 4px; font-size: 13px; opacity: .92; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.promo .pcta {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 10px; padding: 7px 13px;
  background: rgba(255, 255, 255, .95); color: #111;
  border-radius: 999px; font-size: 13px; font-weight: 700;
}

/* ===== Detail screen ===== */
.detail {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 60;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .3s cubic-bezier(.32, .72, 0, 1);
}
.detail.open { transform: translateX(0); }
.detail .hero {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 11;
  background: var(--surface-2);
}
.detail .hero img { width: 100%; height: 100%; object-fit: cover; }
.detail .hero .fallback { font-size: 56px; }
.detail .back {
  position: absolute;
  top: calc(var(--safe-top) + 10px); left: 12px;
  width: 38px; height: 38px; border-radius: 50%;
  background: rgba(0, 0, 0, .42); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.detail .back svg { width: 20px; height: 20px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.detail .dcontent {
  max-width: 720px; margin: 0 auto;
  padding: 20px 18px calc(var(--safe-bottom) + 120px);
}
.detail .dcat { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.detail .dtitle { font-size: 25px; font-weight: 800; letter-spacing: -0.02em; margin: 6px 0 12px; }
.detail .dlede { font-size: 16px; color: var(--hint); margin: 0 0 16px; }
.video-btn {
  display: inline-flex; align-items: center; gap: 8px;
  margin: 4px 0 18px;
  padding: 11px 16px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  color: var(--accent);
  font-size: 14.5px; font-weight: 700;
  transition: transform .12s;
}
.video-btn:active { transform: scale(.96); }
.video-btn svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.detail .dtext { font-size: 15.5px; color: var(--text); white-space: pre-wrap; }
.detail .dtext.hint { color: var(--hint); }

/* rich article body (guide / recipe HTML) */
.rich { font-size: 16px; line-height: 1.62; color: var(--text); }
.rich > *:first-child { margin-top: 0; }
.rich p { margin: 0 0 14px; }
.rich h3 { font-size: 19px; font-weight: 750; letter-spacing: -0.01em; margin: 26px 0 10px; }
.rich h4, .rich h5 { font-size: 16.5px; font-weight: 700; margin: 20px 0 8px; }
.rich ul, .rich ol { margin: 0 0 14px; padding-left: 22px; }
.rich li { margin: 4px 0; }
.rich a { color: var(--accent); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.rich blockquote {
  margin: 16px 0; padding: 10px 14px;
  border-left: 3px solid var(--accent);
  background: var(--surface); border-radius: 0 12px 12px 0;
  color: var(--hint);
}
.rich img {
  width: 100%; height: auto; display: block;
  border-radius: 16px; margin: 16px 0;
  background: var(--surface-2);
}
.rich figure { margin: 16px 0; }
.rich figure img { margin: 0; }
.rich figcaption { margin-top: 6px; font-size: 13px; color: var(--hint); text-align: center; }
.rich hr { border: 0; height: 1px; background: var(--separator); margin: 22px 0; }

/* photo gallery under the body */
.gallery { display: flex; flex-direction: column; gap: 14px; margin-top: 22px; }
.gallery figure { margin: 0; }
.gallery img {
  width: 100%; height: auto; display: block;
  border-radius: 18px; background: var(--surface-2);
  box-shadow: var(--shadow-sm);
}
.gallery figcaption { margin-top: 8px; font-size: 13.5px; color: var(--hint); }

.cta-dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(var(--safe-bottom) + 14px);
  background: linear-gradient(180deg, transparent, var(--bg) 26%);
  z-index: 61;
}
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  max-width: 720px; margin: 0 auto;
  padding: 16px;
  border-radius: 16px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 16px; font-weight: 700;
  box-shadow: var(--shadow);
  transition: transform .12s;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ===== Review screen ===== */
.review-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.review-card .rc-hero { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; background: var(--surface-2); }
.review-card .rc-body { padding: 20px 18px 22px; }
.review-card h2 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 10px; }
.review-card p { font-size: 15.5px; color: var(--text); margin: 0; white-space: pre-wrap; }
.review-bullets { list-style: none; padding: 0; margin: 18px 0 0; display: flex; flex-direction: column; gap: 10px; }
.review-bullets li { display: flex; gap: 10px; font-size: 14.5px; color: var(--text); }
.review-bullets li svg { flex: 0 0 20px; width: 20px; height: 20px; fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; margin-top: 1px; }

/* ===== Skeletons ===== */
.skeleton { position: relative; overflow: hidden; background: var(--surface-2); }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 8%, transparent), transparent);
  animation: shimmer 1.4s infinite;
}
.sk-card { border-radius: var(--radius); height: 190px; }
.sk-row { border-radius: var(--radius-sm); height: 116px; }
.sk-line { height: 12px; border-radius: 6px; margin-top: 8px; }

/* ===== States ===== */
.empty {
  text-align: center;
  padding: 64px 24px;
  color: var(--hint);
}
.empty svg { width: 46px; height: 46px; fill: none; stroke: currentColor; stroke-width: 1.6; margin-bottom: 12px; }
.empty p { margin: 0; font-size: 15px; }

.sentinel { height: 1px; }
.loading-more { text-align: center; padding: 18px; color: var(--hint); font-size: 13px; }

/* ===== Animations ===== */
@keyframes shimmer { 100% { transform: translateX(100%); } }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

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