/*
 * Guides section: /blog (index) and /blog/* (articles). Loaded only there.
 * Reveal-on-scroll is added by js/blog.js; without it everything is visible.
 */

/* ---------- Topic colours ---------- */
[data-topic="fix"] {
  --topic: #b54708;
  --topic-bg: #fff4e5;
  --topic-line: #fedf89;
}

[data-topic="devices"] {
  --topic: var(--sky-text);
  --topic-bg: var(--sky-50);
  --topic-line: var(--sky-100);
}

[data-topic="privacy"] {
  --topic: #027a48;
  --topic-bg: #ecfdf3;
  --topic-line: #abefc6;
}

[data-topic="inside"] {
  --topic: var(--purple-deep);
  --topic-bg: var(--purple-50);
  --topic-line: var(--purple-100);
}

.topic-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  width: fit-content;
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--topic-line, var(--border));
  border-radius: var(--r-pill);
  background: var(--topic-bg, var(--surface-2));
  color: var(--topic, var(--ink-2));
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.01em;
}

a.topic-tag {
  text-decoration: none;
}

a.topic-tag:hover {
  border-color: var(--topic, var(--purple));
}

.topic-tag .icon {
  width: 14px;
  height: 14px;
}

/* ---------- Reveal: rise from below ---------- */
/* Uses the separate `translate` property so card hover (transform) keeps its own, faster timing. */
.reveal-ready [data-reveal] {
  transition: opacity 0.7s var(--ease-out), translate 0.7s var(--ease-out);
}

.reveal-ready [data-reveal]:not(.is-revealed) {
  opacity: 0;
  translate: 0 28px;
}

@media (prefers-reduced-motion: reduce) {
  .reveal-ready [data-reveal]:not(.is-revealed) {
    opacity: 1;
    translate: none;
  }
}

/* ============================================================ INDEX */
.guides-hero {
  position: relative;
  padding-block: clamp(2rem, 1.5rem + 3vw, 4rem) clamp(1.5rem, 1rem + 2vw, 2.5rem);
  background:
    radial-gradient(50% 90% at 100% 0%, color-mix(in srgb, var(--purple) 14%, transparent), transparent 70%),
    radial-gradient(35% 60% at 0% 100%, color-mix(in srgb, var(--sky) 12%, transparent), transparent 70%);
}

.guides-hero h1 {
  max-width: 18ch;
  margin: var(--s-3) 0 var(--s-4);
  font-size: clamp(2rem, 1.3rem + 2.8vw, 3.25rem);
  line-height: 1.08;
  letter-spacing: -0.03em;
}

.guides-hero .lead {
  max-width: 620px;
}

.guides-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3) var(--s-4);
  margin-top: var(--s-6);
}

.guides-search {
  display: flex;
  flex: 1 1 320px;
  align-items: center;
  gap: var(--s-2);
  max-width: 460px;
  padding: 0 var(--s-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.guides-search:focus-within {
  border-color: var(--purple);
  box-shadow: var(--ring);
}

.guides-search .icon {
  color: var(--muted);
}

.guides-search input {
  flex: 1;
  min-width: 0;
  min-height: 2.9rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  outline: none;
}

.guides-count {
  color: var(--muted);
  font-size: var(--fs-sm);
}

.topic-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin: var(--s-4) 0 0;
  padding: 0;
  list-style: none;
}

.topic-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0 var(--s-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease-out), border-color var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out);
}

.topic-filter:hover {
  border-color: var(--purple-200);
  color: var(--ink);
}

.topic-filter[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.topic-filter:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* Filters only make sense with the script. */
html:not(.js) .guides-tools,
html:not(.js) .topic-filters {
  display: none;
}

/* ---------- Featured guide ---------- */
.guide-featured {
  display: grid;
  overflow: hidden;
  margin-bottom: var(--s-6);
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow-2);
  transition: box-shadow var(--t-base) var(--ease-out), border-color var(--t-fast) var(--ease-out), opacity 0.7s var(--ease-out), translate 0.7s var(--ease-out);
}

.guide-featured:hover {
  color: inherit;
  border-color: var(--purple-200);
  box-shadow: var(--shadow-3);
}

.guide-featured__body {
  display: grid;
  align-content: center;
  gap: var(--s-4);
  padding: clamp(1.5rem, 1rem + 2vw, 2.75rem);
}

.guide-featured__label {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.guide-featured h2 {
  margin: 0;
  font-size: clamp(1.5rem, 1.1rem + 1.4vw, 2.125rem);
  line-height: 1.15;
}

.guide-featured p {
  margin: 0;
  color: var(--ink-2);
}

.guide-featured__go {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--purple-deep);
  font-weight: 700;
}

.guide-featured__go .icon {
  transition: transform var(--t-base) var(--ease-out);
}

.guide-featured:hover .guide-featured__go .icon {
  transform: translateX(4px);
}

.guide-featured__art {
  position: relative;
  display: grid;
  min-height: 220px;
  place-items: center;
  background: var(--gradient-deep);
  color: #fff;
}

.guide-featured__art::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.16) 1px, transparent 0);
  background-size: 20px 20px;
}

.guide-featured__art .icon {
  position: relative;
  width: 96px;
  height: 96px;
  stroke-width: 1.3;
  opacity: 0.95;
}

@media (min-width: 860px) {
  .guide-featured {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  }

  .guide-featured__art {
    min-height: 100%;
  }
}

/* ---------- Guide cards ---------- */
.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: var(--s-5);
}

.guide-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  height: 100%;
  padding: var(--s-5);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow-1);
  transition: transform var(--t-base) var(--ease-out), box-shadow var(--t-base) var(--ease-out), border-color var(--t-fast) var(--ease-out), opacity 0.7s var(--ease-out), translate 0.7s var(--ease-out);
}

.guide-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--topic, var(--purple));
  opacity: 0.85;
}

.guide-card:hover {
  color: inherit;
  border-color: var(--topic-line, var(--purple-200));
  box-shadow: var(--shadow-3);
  transform: translateY(-4px);
}

.guide-card:focus-visible,
.guide-featured:focus-visible {
  outline: none;
  box-shadow: var(--ring), var(--shadow-2);
}

.guide-card h2,
.guide-card h3 {
  margin: 0;
  font-size: var(--fs-md);
  line-height: 1.3;
}

.guide-card p {
  margin: 0;
  color: var(--ink-2);
  font-size: var(--fs-sm);
  line-height: 1.55;
}

.guide-card__meta {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-top: auto;
  padding-top: var(--s-3);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: var(--fs-xs);
}

.guide-card__meta .icon {
  width: 14px;
  height: 14px;
}

.guide-card__meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.guide-card__arrow {
  margin-left: auto;
  color: var(--topic, var(--purple));
  transition: transform var(--t-base) var(--ease-out);
}

.guide-card:hover .guide-card__arrow {
  transform: translateX(4px);
}

.guides-empty {
  padding: var(--s-7) var(--s-4);
  border: 1px dashed var(--border-strong);
  border-radius: 20px;
  color: var(--muted);
  text-align: center;
}

/* ============================================================ ARTICLE */
.read-progress {
  position: fixed;
  inset: 0 0 auto;
  z-index: 60;
  height: 3px;
  background: var(--gradient-brand);
  transform: scaleX(0);
  transform-origin: 0 50%;
  pointer-events: none;
}

html:not(.js) .read-progress {
  display: none;
}

.article-hero {
  padding-block: clamp(2rem, 1.5rem + 3vw, 3.75rem) clamp(1.5rem, 1rem + 2vw, 2.5rem);
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(45% 100% at 100% 0%, color-mix(in srgb, var(--topic, var(--purple)) 10%, transparent), transparent 70%),
    var(--canvas);
}

.article-hero__inner {
  max-width: 820px;
}

.article-hero h1 {
  margin: var(--s-4) 0;
  font-size: clamp(1.875rem, 1.25rem + 2.4vw, 3rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.article-hero .lead {
  max-width: 680px;
}

.article-facts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-5);
  margin: var(--s-5) 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.article-facts li {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.article-facts .icon {
  width: 16px;
  height: 16px;
}

.article-layout {
  display: grid;
  gap: var(--s-6);
  padding-block: clamp(1.75rem, 1.25rem + 2vw, 3rem);
}

.article-main {
  min-width: 0;
}

.article-aside {
  min-width: 0;
}

@media (min-width: 1100px) {
  .article-layout {
    grid-template-columns: minmax(0, 1fr) 280px;
    column-gap: clamp(2.5rem, 1rem + 3vw, 4.5rem);
    align-items: start;
  }

  .article-aside {
    position: sticky;
    top: calc(var(--header-h, 64px) + var(--s-5));
    grid-column: 2;
    grid-row: 1;
    max-height: calc(100vh - var(--header-h, 64px) - var(--s-7));
    overflow-y: auto;
  }

  .article-main {
    grid-column: 1;
    grid-row: 1;
  }
}

/* "On this page" */
.toc-panel {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
}

.toc-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 3rem;
  padding: 0 var(--s-4);
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.toc-panel summary::-webkit-details-marker {
  display: none;
}

.toc-panel summary .icon {
  transition: transform var(--t-base) var(--ease-out);
}

.toc-panel[open] summary .icon {
  transform: rotate(180deg);
}

.toc-list {
  margin: 0;
  padding: 0 var(--s-3) var(--s-4);
  list-style: none;
  font-size: var(--fs-sm);
}

.toc-list a {
  display: block;
  padding: 0.4rem 0.75rem;
  border-left: 2px solid var(--border);
  color: var(--ink-2);
  line-height: 1.35;
  text-decoration: none;
  transition: color var(--t-fast) var(--ease-out), border-color var(--t-fast) var(--ease-out), background-color var(--t-fast) var(--ease-out);
}

.toc-list a:hover {
  color: var(--ink);
  border-left-color: var(--purple-200);
}

.toc-list a[aria-current="location"] {
  border-left-color: var(--purple);
  background: var(--purple-50);
  color: var(--purple-deep);
  font-weight: 600;
}

@media (min-width: 1100px) {
  /* Always open beside the article; the summary becomes a plain label. */
  .toc-panel summary {
    pointer-events: none;
  }

  .toc-panel summary .icon {
    display: none;
  }
}

.aside-try {
  display: none;
  margin-top: var(--s-4);
  padding: var(--s-5);
  border-radius: var(--r-lg);
  background: var(--gradient-deep);
  color: #fff;
}

.aside-try p {
  margin: var(--s-2) 0 var(--s-4);
  color: rgba(255, 255, 255, 0.85);
  font-size: var(--fs-sm);
}

.aside-try strong {
  display: block;
  font-size: var(--fs-md);
}

@media (min-width: 1100px) {
  .aside-try {
    display: block;
  }
}

/* Article body */
.article-main .answer-box {
  border-left-color: var(--topic, var(--purple));
  border-color: var(--topic-line, var(--purple-100));
  background: var(--topic-bg, var(--purple-50));
}

.article-main .answer-box__label {
  color: var(--topic, var(--purple-deep));
}

.article-main .prose {
  max-width: 720px;
  font-size: 1.075rem;
  line-height: 1.75;
}

.article-main .prose h2 {
  scroll-margin-top: calc(var(--header-h, 64px) + var(--s-5));
  margin-top: var(--s-8);
  padding-top: var(--s-2);
  font-size: clamp(1.375rem, 1.15rem + 0.8vw, 1.75rem);
  letter-spacing: -0.02em;
}

.article-main .prose h3 {
  scroll-margin-top: calc(var(--header-h, 64px) + var(--s-5));
}

.article-main .prose table {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  border-collapse: separate;
  border-spacing: 0;
}

.article-main .prose th,
.article-main .prose td {
  border: 0;
  border-bottom: 1px solid var(--border);
}

.article-main .prose tr:last-child td {
  border-bottom: 0;
}

.article-main .prose blockquote {
  border-left-color: var(--topic, var(--purple-200));
  border-radius: 0 var(--r-md) var(--r-md) 0;
  background: var(--surface-2);
}

.article-end {
  max-width: 720px;
  margin-top: var(--s-7);
  padding: var(--s-5);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
}

.article-end p {
  margin: 0 0 var(--s-4);
  color: var(--ink-2);
}

.article-end .cluster {
  gap: var(--s-3);
}

/* Related guides on an article use the same cards as the index. */
.related-guides {
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.related-guides h2 {
  margin-bottom: var(--s-5);
}
