/* ==========================================================================
   KUBIQX — вміст, який формує сама платформа: текст статей (Markdown), блоки коду
   з підсвічуванням Prism, відео, таблиці та блок прошивки ESP Web Flasher.

   Спільний для всіх шаблонів оформлення. Кольори беруться зі змінних теми
   (--text, --muted, --line, --raised, --surface, --accent, --code-* …), тому шаблону
   достатньо задати змінні; за потреби правила можна перевизначити у стилях теми.
   ========================================================================== */

/* Текст і код ---------------------------------------------------------------- */

.prose { line-height: 1.7; overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose h2, .prose h3, .prose h4, .prose h5 { margin: 2.25rem 0 0.75rem; }
.prose h2 { font-size: 1.625rem; }
.prose h3 { font-size: 1.375rem; }
.prose h4 { font-size: 1.125rem; }
.prose h5 { font-size: 1rem; }
.prose ul, .prose ol { margin: 0 0 1rem; padding-left: 1.5rem; }
.prose li { margin-bottom: 0.25rem; }
.prose li::marker { color: var(--muted); }
.prose li.task { list-style: none; margin-left: -1.375rem; }
.prose li.task input { accent-color: var(--accent); }
.prose blockquote { margin: 0 0 1rem; padding-left: 1rem; border-left: 3px solid var(--line); color: var(--muted); }
.prose hr { margin: 2rem 0; border: 0; border-top: 1px solid var(--line); }
.prose figure { margin: 1.5rem 0; }
.prose figcaption { margin-top: 0.5rem; color: var(--muted); font-size: 0.875rem; line-height: 1.4; }
.prose img, .prose video { display: block; border-radius: var(--radius); background: var(--raised); }
.prose video { width: 100%; }
.prose :not(pre) > code { padding: 0.1em 0.35em; background: var(--raised); border-radius: 3px; font-size: 0.875em; overflow-wrap: anywhere; }

.callout { margin: 1.5rem 0; padding: 0.875rem 1rem; border-left: 3px solid var(--accent); background: var(--raised); border-radius: 0 var(--radius) var(--radius) 0; }
.callout > :last-child { margin-bottom: 0; }
.callout-tip { border-color: var(--success); }
.callout-important { border-color: var(--accent-strong); }
.callout-warning { border-color: var(--warning); }

.table-wrap { overflow-x: auto; margin: 0 0 1rem; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
th, td { padding: 0.5625rem 0.875rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
thead th { color: var(--muted); font-size: 0.8125rem; font-weight: 500; white-space: nowrap; }
tbody tr:last-child > * { border-bottom: 0; }
tbody th { width: 40%; color: var(--muted); font-weight: 400; }
.ta-right { text-align: right; }
.ta-center { text-align: center; }
.hash { color: var(--muted); font-size: 0.75rem; overflow-wrap: anywhere; }

/* Блок коду: назва файлу, мова, кнопка копіювання, нумерація рядків */
.code-block { margin: 1.5rem 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.code-block__bar { display: flex; align-items: center; gap: 0.75rem; min-height: 2.25rem; margin: 0; padding: 0.25rem 0.5rem 0.25rem 1rem; border-bottom: 1px solid var(--line); background: var(--raised); color: var(--muted); font-family: var(--mono); font-size: 0.75rem; }
.code-block__file { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-block__lang { margin-left: auto; }
.code-block__copy { margin-left: auto; padding: 0.25rem 0.625rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); font: 500 0.75rem var(--font); cursor: pointer; }
.code-block__lang + .code-block__copy { margin-left: 0; }
.code-block__copy:hover { border-color: var(--muted); }

pre { margin: 0; padding: 0.875rem 1rem; overflow-x: auto; font-size: 0.875rem; line-height: 1.65; tab-size: 2; color: var(--text); -webkit-overflow-scrolling: touch; }
pre code { font-size: inherit; white-space: pre; }
pre.line-numbers { position: relative; padding-left: 3.5rem; counter-reset: linenumber; }
pre.line-numbers > code { position: relative; white-space: inherit; }
.line-numbers-rows { position: absolute; top: 0; left: -3.5rem; width: 2.75rem; pointer-events: none; user-select: none; -webkit-user-select: none; }
.line-numbers-rows > span { display: block; counter-increment: linenumber; }
.line-numbers-rows > span::before { content: counter(linenumber); display: block; padding-right: 0.75rem; text-align: right; color: var(--muted); opacity: 0.7; }

/* Кольори синтаксису Prism беруться з поточної теми */
.token.comment, .token.prolog, .token.doctype, .token.cdata { color: var(--code-comment); font-style: italic; }
.token.punctuation, .token.operator { color: var(--muted); }
.token.property, .token.tag, .token.key, .token.atrule, .token.attr-name, .token.selector { color: var(--code-key); }
.token.string, .token.char, .token.attr-value, .token.inserted { color: var(--code-string); }
.token.number, .token.boolean, .token.constant, .token.symbol, .token.important { color: var(--code-number); }
.token.keyword, .token.directive, .token.builtin, .token.deleted { color: var(--code-keyword); }
.token.function, .token.class-name, .token.variable { color: var(--code-function); }

/* YouTube: до кліку — лише картинка, плеєр завантажується після */
.yt-embed { position: relative; aspect-ratio: 16 / 9; overflow: hidden; border-radius: var(--radius); background: #000; }
.yt-embed__link { display: block; width: 100%; height: 100%; }
.yt-embed__link img { width: 100%; height: 100%; object-fit: cover; border-radius: 0; opacity: 0.85; }
.yt-embed__play { position: absolute; inset: 0; margin: auto; width: 5rem; height: 3.1rem; background: var(--accent); clip-path: var(--tile); }
.yt-embed__link:hover .yt-embed__play { background: var(--accent-strong); }
.yt-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Прошивка ------------------------------------------------------------------- */

.field { display: grid; gap: 0.3125rem; }
.field > span { color: var(--muted); font-size: 0.875rem; }
.flasher__pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 1rem; max-width: 34rem; margin-bottom: 1.5rem; }
.flasher__pick select { width: 100%; min-height: 2.75rem; }

.firmware { padding: 1.25rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.firmware__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem 2rem; margin-bottom: 1rem; }
.firmware__name { margin: 0; font-size: 1.1875rem; font-weight: 600; }
.firmware__name code { font-size: 0.9375rem; font-weight: 400; color: var(--accent-strong); }
.firmware__chips { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.9375rem; }
.firmware__blocked { margin: 0; max-width: 28rem; padding: 0.625rem 0.875rem; border-left: 3px solid var(--warning); background: var(--raised); font-size: 0.9375rem; }
.firmware__details { margin-top: 0.75rem; }
.firmware__details summary { cursor: pointer; color: var(--accent-strong); }
.firmware__details[open] summary { margin-bottom: 0.75rem; }
.firmware__link { margin: 1rem 0 0; }

/* Встановлювач із перевіркою плати */
.vflash { display: grid; gap: 0.875rem; margin-bottom: 0.75rem; padding: 1rem; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius); background: var(--raised); }
.vflash > * { margin: 0; }
.vflash__only { max-width: 46rem; font-size: 0.9375rem; }
.vflash__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1rem; }
.vflash__hint { max-width: 46rem; color: var(--muted); font-size: 0.875rem; }
.vflash__confirm { display: grid; gap: 0.625rem; max-width: 46rem; padding: 1rem; border: 1px solid var(--danger); border-radius: var(--radius); }
.vflash__confirm > * { margin: 0; }
.vflash__confirm[hidden] { display: none; }
.vflash__info { display: grid; gap: 0.25rem; padding: 0; list-style: none; font-size: 0.9375rem; }
.vflash__info[hidden] { display: none; }
.vflash__steps { display: grid; gap: 0.5rem; max-width: 46rem; margin: 0.75rem 0 0; padding-left: 1.25rem; font-size: 0.9375rem; }
.vflash [data-vflash-copy] { margin-top: 0.625rem; }
.vflash__status { min-height: 1.5em; font-weight: 600; }
.vflash__status:empty { display: none; }
.vflash__status.is-ok { color: var(--success); }
.vflash__status.is-bad { color: var(--danger); }
.vflash__progress { width: 100%; height: 0.625rem; accent-color: var(--accent); }
.vflash__table th[scope="row"] { font-weight: 600; text-align: left; }
.vflash__table .is-ok td[data-verdict] { color: var(--success); font-weight: 600; }
.vflash__table .is-bad td[data-verdict], .vflash__table .is-bad td[data-found] { color: var(--danger); font-weight: 600; }
.vflash__table .is-ok td[data-verdict]::before { content: "✓ "; }
.vflash__table .is-bad td[data-verdict]::before { content: "✗ "; }
.vflash__log { max-height: 16rem; margin: 0; padding: 0.75rem; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); font: 0.8125rem/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }

esp-web-install-button { display: block; }
esp-web-install-button[install-unsupported] { flex-basis: 100%; }

.how { max-width: 46rem; margin-top: 3rem; }
.how h2 { margin-bottom: 1rem; }
.how__steps { display: grid; gap: 0.625rem; margin: 0 0 1.25rem; padding-left: 1.5rem; }
.how__steps li::marker { color: var(--accent); font-weight: 600; }
.how__safety { color: var(--muted); font-size: 0.9375rem; }

/* ==========================================================================
   Сторінка продукту й розділи його документації (спільне для всіх тем)
   ========================================================================== */

.product-hero { display: grid; gap: 2.5rem; align-items: center; padding-block: clamp(2.5rem, 6vw, 5rem) clamp(1.5rem, 4vw, 3rem); }
.product-hero h1 { max-width: 14ch; overflow-wrap: break-word; }
.product-hero__lead { max-width: 36rem; margin: 1.25rem 0 0; color: var(--muted); font-size: clamp(1.0625rem, 1rem + 0.4vw, 1.3125rem); line-height: 1.5; }
.product-hero__actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.75rem; }
@media (min-width: 56rem) {
    .product-hero { grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr); }
}

/* Рамка пристрою: білий корпус із трьома кнопками згори, на екрані по черзі — обкладинки розділів */
.device { position: relative; justify-self: center; width: min(100%, 24rem); padding: 4.5%; border-radius: 15%; background: linear-gradient(145deg, #ffffff, #dfe3e8); box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08), 0 2rem 4rem -1.5rem rgb(0 0 0 / 0.55); }
.device__keys { position: absolute; left: 22%; right: 22%; top: -1.6%; display: flex; justify-content: space-between; }
.device__keys i { width: 16%; height: 0.5rem; border-radius: 0.3rem 0.3rem 0 0; background: #e9ecf0; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08); }
.device__screen { position: relative; aspect-ratio: 1; overflow: hidden; border-radius: 11%; background: #000; }
.device__screen img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; }
.device__screen img:first-child { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
    .device-2 img, .device-3 img, .device-4 img { opacity: 0; animation: device-show 12s infinite; }
    .device-2 img { animation-name: device-show-2; animation-duration: 8s; }
    .device-3 img { animation-name: device-show-3; animation-duration: 12s; }
    .device-4 img { animation-name: device-show-4; animation-duration: 16s; }
    .device__screen img:nth-child(2) { animation-delay: 4s; }
    .device__screen img:nth-child(3) { animation-delay: 8s; }
    .device__screen img:nth-child(4) { animation-delay: 12s; }
}
@keyframes device-show-2 { 0%, 45% { opacity: 1; } 55%, 95% { opacity: 0; } 100% { opacity: 1; } }
@keyframes device-show-3 { 0%, 30% { opacity: 1; } 36%, 97% { opacity: 0; } 100% { opacity: 1; } }
@keyframes device-show-4 { 0%, 22% { opacity: 1; } 27%, 98% { opacity: 0; } 100% { opacity: 1; } }

/* Вкладки розділів: на вузькому екрані гортаються вбік */
.product-nav { margin-block: 1rem 2rem; }
.product-nav ul { display: flex; gap: 0.375rem; margin: 0; padding: 0.375rem; overflow-x: auto; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); list-style: none; scrollbar-width: none; }
.product-nav ul::-webkit-scrollbar { display: none; }
.product-nav a { display: block; padding: 0.5rem 0.9375rem; border-radius: 999px; color: var(--muted); font-size: 0.9375rem; font-weight: 500; text-decoration: none; white-space: nowrap; }
.product-nav a:hover { color: var(--text); }
.product-nav a[aria-current="page"] { background: var(--accent); color: var(--on-accent); }
.product-overview { margin-bottom: clamp(2.5rem, 6vw, 4.5rem); }
.product-overview .prose { max-width: 46rem; }
.product-firmware .firmware + .firmware { margin-top: 1.25rem; }
.product-pager { display: grid; gap: 1rem; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-block: 2.5rem; }
.product-pager a { display: grid; gap: 0.25rem; padding: 1rem 1.25rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); text-decoration: none; }
.product-pager a:hover { border-color: var(--accent); }
.product-pager small { color: var(--muted); font-size: 0.8125rem; }
.product-pager span { font-weight: 600; }
.product-pager__next { grid-column: 2; text-align: right; }
@media (max-width: 36rem) {
    .product-pager { grid-template-columns: minmax(0, 1fr); }
    .product-pager__next { grid-column: 1; text-align: left; }
}

/* Галерея: кілька зображень поспіль */
.prose .media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 11rem), 1fr)); gap: 1rem; margin-block: 1.5rem; }
.prose .media-grid .media-image { margin: 0; }
.prose .media-grid img { width: 100%; height: auto; border-radius: 1rem; }
.prose .media-grid figcaption { margin-top: 0.375rem; font-size: 0.8125rem; text-align: center; }


/* Словесний знак KUBIQX (templates/brand-name.php): висота задається від розміру шрифту, ширина — за пропорціями */
/* !important: деякі теми задають розмір усім svg у шапці (під квадратний знак) — словесний знак має зберегти пропорції */
.logo-word { display: inline-block; width: auto !important; height: 0.92em !important; aspect-ratio: 480 / 79; max-width: none !important; flex: none; vertical-align: -0.08em; overflow: visible; }
.brand__name:has(.logo-word), .site-footer__brand:has(.logo-word) { letter-spacing: 0; }
