/**
 * Khaganate blog — Platega-like cards + article.
 * Mobile-first adaptive (phone → tablet → desktop).
 */

/* ——— Tokens ——— */
.khaganate-blog {
  --kh-gold: oklch(0.62 0.15 75);
  --kh-gold-soft: oklch(0.62 0.15 75 / 0.14);
  --kh-bg: oklch(0.98 0.005 90);
  --kh-surface: oklch(1 0 0);
  --kh-surface-2: oklch(0.96 0.008 90);
  --kh-bg-light: oklch(0.94 0.005 90);
  --kh-border: oklch(0.88 0.005 90);
  --kh-text: oklch(0.22 0.02 260);
  --kh-text-2: oklch(0.45 0.02 260);
  --kh-text-3: oklch(0.6 0.02 260);
  --kh-ink-on-gold: oklch(0.15 0.02 260);
  --kh-radius-card: 20px;
  --kh-radius-media: 16px;
  --kh-container: 1240px;
  --kh-pad: 20px;
  --kh-header-h: 64px;
  color-scheme: light dark;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--kh-bg);
  color: var(--kh-text);
  font-family: "Manrope", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-color-scheme: dark) {
  .khaganate-blog:not([data-theme="light"]) {
    --kh-gold: oklch(0.78 0.14 85);
    --kh-gold-soft: oklch(0.78 0.14 85 / 0.16);
    --kh-bg: oklch(0.16 0.02 260);
    --kh-surface: oklch(0.21 0.02 260);
    --kh-surface-2: oklch(0.25 0.02 260);
    --kh-bg-light: oklch(0.25 0.02 260);
    --kh-border: oklch(0.32 0.02 260);
    --kh-text: oklch(0.96 0.02 260);
    --kh-text-2: oklch(0.72 0.02 260);
    --kh-text-3: oklch(0.54 0.02 260);
  }
}

.khaganate-blog[data-theme="dark"] {
  --kh-gold: oklch(0.78 0.14 85);
  --kh-gold-soft: oklch(0.78 0.14 85 / 0.16);
  --kh-bg: oklch(0.16 0.02 260);
  --kh-surface: oklch(0.21 0.02 260);
  --kh-surface-2: oklch(0.25 0.02 260);
  --kh-bg-light: oklch(0.25 0.02 260);
  --kh-border: oklch(0.32 0.02 260);
  --kh-text: oklch(0.96 0.02 260);
  --kh-text-2: oklch(0.72 0.02 260);
  --kh-text-3: oklch(0.54 0.02 260);
}

.khaganate-blog[data-theme="light"] {
  --kh-gold: oklch(0.62 0.15 75);
  --kh-gold-soft: oklch(0.62 0.15 75 / 0.14);
  --kh-bg: oklch(0.98 0.005 90);
  --kh-surface: oklch(1 0 0);
  --kh-surface-2: oklch(0.96 0.008 90);
  --kh-bg-light: oklch(0.94 0.005 90);
  --kh-border: oklch(0.88 0.005 90);
  --kh-text: oklch(0.22 0.02 260);
  --kh-text-2: oklch(0.45 0.02 260);
  --kh-text-3: oklch(0.6 0.02 260);
}

@media (min-width: 820px) {
  .khaganate-blog {
    --kh-pad: 32px;
  }
}

.kh-blog-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.kh-blog-container {
  width: min(100% - (var(--kh-pad) * 2), var(--kh-container));
  margin-inline: auto;
}

/* ——— Header ——— */
.kh-blog-header {
  border-bottom: 1px solid var(--kh-border);
  background: color-mix(in oklch, var(--kh-surface) 88%, transparent);
  padding: 12px 0;
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.kh-blog-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
}

.kh-blog-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--kh-text);
  min-height: 44px;
}

.kh-blog-brand__mark {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--kh-gold);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.kh-blog-brand__mark span {
  width: 11px;
  height: 11px;
  background: var(--kh-gold);
  transform: rotate(45deg);
  border-radius: 3px;
}

.kh-blog-brand__name {
  font-family: "Sora", sans-serif;
  font-weight: 800;
  font-size: 17px;
}

.kh-blog-nav--desktop {
  display: none;
  align-items: center;
  gap: 28px;
}

.kh-blog-nav--desktop a {
  font-size: 15px;
  font-weight: 600;
  color: var(--kh-text);
  text-decoration: none;
  transition: color 0.2s;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.kh-blog-nav--desktop a:hover,
.kh-blog-nav--desktop a.is-active {
  color: var(--kh-gold);
}

.kh-blog-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.kh-blog-lang-btn {
  font-family: "Manrope", system-ui, sans-serif;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.kh-blog-i18n-status {
  position: sticky;
  top: var(--kh-header-h, 64px);
  z-index: 40;
  margin: 0;
  padding: 8px 16px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--kh-ink-on-gold, #1a1a1a);
  background: var(--kh-gold);
}

body.kh-blog-i18n-busy .kh-article__content,
body.kh-blog-i18n-busy .kh-blog-card h2,
body.kh-blog-i18n-busy .kh-blog-card__excerpt {
  opacity: 0.55;
  transition: opacity 0.2s ease;
}

.kh-blog-icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--kh-border);
  background: transparent;
  color: var(--kh-text);
  cursor: pointer;
  font-family: "Manrope", sans-serif;
  font-size: 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.kh-blog-icon-btn[aria-expanded="true"] {
  border-color: var(--kh-gold);
  color: var(--kh-gold);
}

.kh-blog-burger span {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  position: relative;
}

.kh-blog-burger span::before,
.kh-blog-burger span::after {
  content: "";
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.kh-blog-burger span::before { top: -6px; }
.kh-blog-burger span::after { top: 6px; }

/* Mobile drawer */
.kh-blog-drawer {
  display: none;
  border-top: 1px solid var(--kh-border);
  background: var(--kh-surface);
  padding: 8px var(--kh-pad) 16px;
}

.kh-blog-drawer.is-open,
.kh-blog-drawer.is-open[hidden] {
  display: block;
}

.kh-blog-drawer a {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0 4px;
  font-size: 16px;
  font-weight: 600;
  color: var(--kh-text);
  text-decoration: none;
  border-bottom: 1px solid var(--kh-border);
}

.kh-blog-drawer a:last-child {
  border-bottom: 0;
}

.kh-blog-drawer a.is-active {
  color: var(--kh-gold);
}

@media (min-width: 820px) {
  .kh-blog-nav--desktop {
    display: flex;
    flex: 1;
    justify-content: center;
  }

  .kh-blog-burger {
    display: none;
  }

  .kh-blog-drawer,
  .kh-blog-drawer.is-open {
    display: none;
  }

  .kh-blog-header__actions {
    margin-left: 0;
  }

  .kh-blog-brand__name {
    font-size: 18px;
  }
}

/* ——— Hero ——— */
.kh-blog-hero {
  padding: 36px 0 28px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.kh-blog-hero__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--kh-gold-soft);
  color: var(--kh-gold);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.4px;
  padding: 7px 14px;
  border-radius: 100px;
  margin-bottom: 16px;
}

.kh-blog-hero__eyebrow i {
  width: 10px;
  height: 10px;
  background: var(--kh-gold);
  transform: rotate(45deg);
  border-radius: 2px;
  display: block;
}

.kh-blog-hero h1 {
  font-family: "Sora", sans-serif;
  font-weight: 800;
  font-size: clamp(1.75rem, 6.5vw, 3.25rem);
  line-height: 1.12;
  margin: 0 auto 12px;
  color: var(--kh-text);
  max-width: 18ch;
}

.kh-blog-hero p {
  margin: 0 auto;
  font-size: clamp(15px, 3.6vw, 17px);
  line-height: 1.6;
  color: var(--kh-text-2);
  max-width: 42ch;
  font-weight: 500;
}

@media (min-width: 820px) {
  .kh-blog-hero {
    padding: 64px 0 40px;
  }
}

/* ——— Grid / cards ——— */
.kh-blog-main {
  flex: 1;
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 820px) {
  .kh-blog-main {
    padding-bottom: 80px;
  }
}

.kh-blog-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 640px) {
  .kh-blog-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
  }
}

@media (min-width: 1100px) {
  .kh-blog-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px 20px;
  }
}

.kh-blog-card {
  background: var(--kh-surface);
  border: 1px solid var(--kh-border);
  border-radius: var(--kh-radius-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 10px;
  transition: box-shadow 0.25s ease, transform 0.25s ease, border-color 0.25s ease;
  text-decoration: none;
  color: inherit;
  height: 100%;
  min-width: 0;
}

@media (hover: hover) and (pointer: fine) {
  .kh-blog-card:hover {
    box-shadow: 0 16px 40px oklch(0.2 0.02 260 / 0.12);
    border-color: color-mix(in oklch, var(--kh-gold) 35%, var(--kh-border));
    transform: translateY(-2px);
  }

  .kh-blog-card:hover h2 {
    color: var(--kh-gold);
  }
}

.kh-blog-card:focus-visible {
  outline: 2px solid var(--kh-gold);
  outline-offset: 3px;
}

.kh-blog-card__media {
  position: relative;
  aspect-ratio: 2 / 1;
  border-radius: var(--kh-radius-media);
  overflow: hidden;
  background: var(--kh-surface-2);
}

.kh-blog-card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.kh-blog-card__media--empty {
  display: grid;
  place-items: center;
}

.kh-blog-card__media--empty span {
  width: 28px;
  height: 28px;
  background: var(--kh-gold);
  opacity: 0.35;
  transform: rotate(45deg);
  border-radius: 6px;
}

.kh-blog-card__body {
  padding: 14px 8px 8px;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 10px;
  min-width: 0;
}

.kh-blog-card__meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  font-weight: 600;
  color: var(--kh-text-3);
}

.kh-blog-card h2 {
  font-family: "Sora", sans-serif;
  font-size: clamp(1rem, 2.8vw, 1.05rem);
  font-weight: 700;
  line-height: 1.35;
  margin: 0;
  color: var(--kh-text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.kh-blog-card__excerpt {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--kh-text-2);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.kh-blog-card__cta {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--kh-text);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 0.6px;
}

.kh-blog-empty {
  padding: 40px 20px;
  text-align: center;
  border: 1px dashed var(--kh-border);
  border-radius: var(--kh-radius-card);
  background: var(--kh-surface);
  color: var(--kh-text-2);
  font-size: 15px;
  line-height: 1.5;
}

.kh-blog-pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 32px;
  flex-wrap: wrap;
}

.kh-blog-pagination a,
.kh-blog-pagination span {
  min-width: 44px;
  height: 44px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--kh-border);
  background: var(--kh-surface);
  color: var(--kh-text);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

.kh-blog-pagination .current {
  background: var(--kh-gold);
  border-color: var(--kh-gold);
  color: var(--kh-ink-on-gold);
}

/* ——— Single article ——— */
/* Reading column: keep ~760–820px and center it. Blog index still uses 1240px grid. */
.kh-article.kh-blog-container {
  width: min(100% - (var(--kh-pad) * 2), 820px);
}

.kh-article {
  padding: 28px 0 64px;
}

.kh-article__back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--kh-text-2);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 22px;
  min-height: 44px;
}

.kh-article__back:hover {
  color: var(--kh-gold);
}

.kh-article__header {
  margin-bottom: 22px;
}

.kh-article__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--kh-text-3);
  margin-bottom: 12px;
}

.kh-article__header h1 {
  font-family: "Sora", sans-serif;
  font-weight: 800;
  font-size: clamp(1.55rem, 5.5vw, 2.75rem);
  line-height: 1.15;
  margin: 0 0 12px;
  color: var(--kh-text);
  overflow-wrap: anywhere;
}

.kh-article__lead {
  margin: 0;
  font-size: clamp(16px, 3.8vw, 18px);
  line-height: 1.6;
  color: var(--kh-text-2);
}

.kh-article__cover {
  margin: 0 0 28px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--kh-border);
  background: var(--kh-surface-2);
  max-height: 280px;
}

.kh-article__cover img {
  width: 100%;
  height: 100%;
  max-height: 280px;
  object-fit: cover;
  display: block;
}

@media (min-width: 820px) {
  .kh-article {
    padding: 40px 0 80px;
  }

  .kh-article__cover {
    border-radius: 24px;
    max-height: 480px;
    margin-bottom: 36px;
  }

  .kh-article__cover img {
    max-height: 480px;
  }

  .kh-article__meta {
    font-size: 13px;
  }
}

.kh-article__content {
  font-size: clamp(16px, 3.5vw, 17px);
  line-height: 1.75;
  color: var(--kh-text);
  overflow-wrap: anywhere;
}

.kh-article__content > *:first-child {
  margin-top: 0;
}

.kh-article__content h2,
.kh-article__content h3 {
  font-family: "Sora", sans-serif;
  font-weight: 700;
  line-height: 1.25;
  margin: 1.75em 0 0.55em;
  color: var(--kh-text);
}

.kh-article__content h2 { font-size: clamp(1.25rem, 4vw, 1.45rem); }
.kh-article__content h3 { font-size: clamp(1.1rem, 3.4vw, 1.2rem); }

.kh-article__content p,
.kh-article__content ul,
.kh-article__content ol {
  margin: 0 0 1.1em;
}

.kh-article__content ul,
.kh-article__content ol {
  padding-left: 1.25em;
}

.kh-article__content a {
  color: var(--kh-gold);
  font-weight: 600;
}

.kh-article__content img,
.kh-article__content video,
.kh-article__content iframe {
  max-width: 100%;
  height: auto;
  border-radius: 14px;
}

.kh-article__content pre,
.kh-article__content code {
  max-width: 100%;
  overflow-x: auto;
  font-size: 0.92em;
}

.kh-article__content table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

.kh-article__content blockquote {
  margin: 1.4em 0;
  padding: 14px 16px;
  border-left: 3px solid var(--kh-gold);
  background: var(--kh-gold-soft);
  border-radius: 0 12px 12px 0;
  color: var(--kh-text);
}

.kh-article__footer {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--kh-border);
}

.kh-article__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.kh-article__tags a {
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 100px;
  background: var(--kh-gold-soft);
  color: var(--kh-gold);
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}

.kh-article__pager {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--kh-border);
}

.kh-article__pager-link {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  border: 1px solid var(--kh-border);
  border-radius: 12px;
  text-decoration: none;
  transition: border-color 0.15s ease;
}

.kh-article__pager-link:hover {
  border-color: var(--kh-gold);
}

.kh-article__pager-link--next {
  text-align: right;
}

.kh-article__pager-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--kh-gold);
}

.kh-article__pager-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--kh-text);
  line-height: 1.4;
}

@media (min-width: 640px) {
  .kh-article__pager {
    grid-template-columns: 1fr 1fr;
  }
}

/* ——— Footer ——— */
.kh-blog-footer {
  border-top: 1px solid var(--kh-border);
  background: var(--kh-surface);
  padding: 40px var(--kh-pad) calc(24px + env(safe-area-inset-bottom, 0px));
  margin-top: 16px;
}

.kh-blog-footer__inner {
  width: min(100%, var(--kh-container));
  margin-inline: auto;
}

.kh-blog-footer__grid {
  display: grid;
  gap: 32px;
  grid-template-columns: 1fr;
  margin-bottom: 32px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--kh-border);
  text-align: center;
  justify-items: center;
}

@media (min-width: 920px) {
  .kh-blog-footer__grid {
    grid-template-columns: 2fr 1fr 1fr;
    text-align: left;
    justify-items: start;
  }
}

.kh-blog-footer__brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--kh-text);
  margin-bottom: 14px;
}

.kh-blog-footer__brand .kh-blog-brand__name {
  font-family: "Sora", sans-serif;
  font-weight: 800;
  font-size: 19px;
}

.kh-blog-footer__legal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
}

@media (min-width: 920px) {
  .kh-blog-footer__legal {
    align-items: flex-start;
  }
}

.kh-blog-footer__legal a {
  color: var(--kh-text-2);
  text-decoration: none;
}

.kh-blog-footer__legal a:hover {
  color: var(--kh-gold);
}

.kh-blog-footer__heading {
  font-family: "Sora", sans-serif;
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 14px;
  color: var(--kh-text);
}

.kh-blog-footer__links {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

@media (min-width: 920px) {
  .kh-blog-footer__links {
    align-items: flex-start;
  }
}

.kh-blog-footer__links--support {
  gap: 10px;
}

.kh-blog-footer__links a {
  font-size: 13px;
  color: var(--kh-text-2);
  text-decoration: none;
  transition: color 0.2s;
}

.kh-blog-footer__links a:hover {
  color: var(--kh-gold);
}

.kh-blog-footer__api {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.kh-blog-soon {
  background: var(--kh-gold-soft);
  color: var(--kh-gold);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.3px;
  padding: 2px 7px;
  border-radius: 100px;
}

.kh-blog-footer__social {
  display: flex;
  gap: 10px;
  margin-top: 4px;
  justify-content: center;
}

@media (min-width: 920px) {
  .kh-blog-footer__social {
    justify-content: flex-start;
  }
}

.kh-blog-footer__tg {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--kh-bg-light);
  color: var(--kh-text-2);
  text-decoration: none;
  transition: color 0.2s;
}

.kh-blog-footer__tg:hover {
  color: var(--kh-gold);
}

.kh-blog-footer__copy {
  text-align: center;
  font-size: 12px;
  color: var(--kh-text-3);
  line-height: 1.4;
}

@media (max-width: 419px) {
  .khaganate-blog {
    --kh-pad: 16px;
  }

  .kh-blog-brand__name {
    font-size: 16px;
  }

  .kh-blog-card {
    padding: 8px;
  }

  .kh-blog-card__body {
    padding: 12px 6px 6px;
  }

  .kh-article__cover {
    border-radius: 12px;
    max-height: 200px;
  }

  .kh-article__cover img {
    max-height: 200px;
  }

  .kh-blog-header__inner {
    gap: 8px;
  }
}

/* Avoid sticky header covering anchors on small screens */
@media (max-width: 819px) {
  .kh-article__content h2,
  .kh-article__content h3 {
    scroll-margin-top: 72px;
  }
}
