/*
 * MiuWave docs — shared stylesheet.
 * Tokens mirror src/styles/brand-refresh.css and docs/brand-spec.md:
 * dark teal-charcoal surfaces, mint for navigation/primary action and focus,
 * coral only for audio cues, blue only as a small AI cue.
 * Light appearance follows prefers-color-scheme.
 * Pages exist per language (vi at the root, en/ ja/ ko/ zh/ subfolders); language-specific
 * rules use :lang() so every translation shares this one file.
 */

/* ---------- Tokens ---------- */
:root {
  color-scheme: dark;
  --bg: #121c1e;
  --bg-tint: #152224;
  --surface: #1b282a;
  --surface-2: #223133;
  --border: rgba(212, 239, 229, 0.14);
  --border-strong: rgba(212, 239, 229, 0.24);
  --text: #edf6f1;
  --text-2: #bdcec6;
  --text-3: #9caaa3;
  --accent: #71d4bd;
  --accent-hover: #8be2cd;
  --accent-soft: rgba(113, 212, 189, 0.14);
  --on-accent: #102722;
  --coral: #ff9b84;
  --coral-soft: rgba(255, 155, 132, 0.12);
  --blue: #aab8ff;
  --blue-soft: rgba(170, 184, 255, 0.12);
  --warn: #f3c778;
  --warn-soft: rgba(243, 199, 120, 0.12);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.32);

  --font: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.2rem;
  --step-2: 1.44rem;
  --step-3: clamp(1.75rem, 1.4rem + 1.6vw, 2.2rem);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --header-h: 60px;
  --sidebar-w: 268px;
  --content-w: 46rem;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f3f6f3;
    --bg-tint: #eaf1ed;
    --surface: #fcfdfc;
    --surface-2: #eef3f0;
    --border: rgba(42, 68, 56, 0.13);
    --border-strong: rgba(42, 68, 56, 0.24);
    --text: #24342d;
    --text-2: #4c5d54;
    --text-3: #5f6e66;
    --accent: #287b62;
    --accent-hover: #20664f;
    --accent-soft: rgba(40, 123, 98, 0.1);
    --on-accent: #ffffff;
    --coral: #9f3f2b;
    --coral-soft: rgba(159, 63, 43, 0.08);
    --blue: #344b93;
    --blue-soft: rgba(52, 75, 147, 0.08);
    --warn: #7a5300;
    --warn-soft: rgba(196, 140, 20, 0.12);
    --shadow: 0 10px 28px rgba(36, 52, 45, 0.1);
  }
}

/* CJK pages: Be Vietnam Pro has no CJK glyphs; name the native fonts so each language
   gets its own glyph forms instead of whatever the browser picks first. */
:lang(ja) { --font: "Be Vietnam Pro", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo, "Noto Sans JP", sans-serif; }
:lang(ko) { --font: "Be Vietnam Pro", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif; }
:lang(zh-Hans) { --font: "Be Vietnam Pro", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif; }
/* Korean breaks lines between words (spaces), not inside them; CJK text avoids a lone
   character on its own line. */
:lang(ko) { word-break: keep-all; overflow-wrap: anywhere; }
:lang(ja), :lang(ko), :lang(zh-Hans) { line-break: strict; }
:lang(ja) .sidebar-foot, :lang(ko) .sidebar-foot, :lang(zh-Hans) .sidebar-foot { text-wrap: balance; }

/* ---------- Base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-h) + 16px);
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 60% 40% at 100% 0%, var(--accent-soft), transparent 70%),
    radial-gradient(ellipse 40% 30% at 0% 100%, var(--coral-soft), transparent 70%);
  background-attachment: fixed;
  overflow-x: hidden;
}

img { max-width: 100%; height: auto; }

a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); text-decoration-thickness: 2px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 100;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: 10px; color: var(--on-accent); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px) saturate(125%);
  -webkit-backdrop-filter: blur(14px) saturate(125%);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.08rem;
  letter-spacing: -0.01em;
}
.brand:hover { color: var(--text); }
.brand img { width: 32px; height: 32px; border-radius: 9px; }
.brand-sub { color: var(--text-3); font-weight: 500; font-size: var(--step--1); }

.header-spacer { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: var(--step--1);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}
.btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn svg { width: 18px; height: 18px; flex: none; }

/* "Coming soon" state of the download button: no release exists yet. To restore the link,
   turn the span back into <a class="btn btn-primary header-download" href="(data-release-url)">. */
.header-download { white-space: nowrap; }
.btn.is-soon,
.btn.is-soon:hover {
  background: transparent;
  border-style: dashed;
  border-color: var(--border-strong);
  color: var(--text-3);
  cursor: default;
}
.soon-note { margin: 12px 0 0; font-size: var(--step--1); color: var(--text-3); }

/* Language switcher: a <details> menu of plain links, so it works without JS. */
.lang-switch { position: relative; }
.lang-switch > summary { list-style: none; }
.lang-switch > summary::-webkit-details-marker { display: none; }
.lang-toggle { gap: 6px; padding: 0 14px; }
.lang-toggle::after {
  content: "";
  width: 6px;
  height: 6px;
  margin: -3px 0 0 2px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  opacity: 0.7;
}
.lang-switch[open] > .lang-toggle { background: var(--surface-2); }
.lang-code { display: none; }
.lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  min-width: 11rem;
  margin: 0;
  padding: 6px;
  list-style: none;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.lang-menu a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-size: 0.94rem;
}
.lang-menu a:hover { background: var(--accent-soft); color: var(--text); }
.lang-menu a[aria-current] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.lang-menu a[aria-current]::after { content: "✓"; }

.menu-toggle {
  display: none;
  width: 44px;
  min-width: 44px;
  padding: 0;
  border-radius: var(--radius-sm);
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  max-width: 1280px;
  margin: 0 auto;
}

.sidebar {
  position: sticky;
  top: var(--header-h);
  align-self: start;
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 24px 12px 32px 16px;
  border-right: 1px solid var(--border);
}

.nav-group + .nav-group { margin-top: 20px; }
.nav-group h2 {
  margin: 0 0 6px;
  padding: 0 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}
.nav-group ul { list-style: none; margin: 0; padding: 0; }
.nav-group a {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-size: 0.94rem;
  line-height: 1.35;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.nav-group a:hover { background: var(--accent-soft); color: var(--text); }
.nav-group a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
}

.sidebar-foot {
  margin-top: 28px;
  padding: 14px 12px 0;
  border-top: 1px solid var(--border);
  font-size: var(--step--1);
  color: var(--text-3);
}

main {
  min-width: 0;
  padding: 40px clamp(16px, 4vw, 56px) 64px;
}

.content { max-width: var(--content-w); }
/* Pages without a sidebar (404) */
main.solo { max-width: calc(var(--content-w) + 112px); margin: 0 auto; }

/* ---------- Typography ---------- */
.eyebrow {
  margin: 0 0 8px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

h1 {
  margin: 0;
  font-size: var(--step-3);
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 700;
  text-wrap: balance;
}

/* Signature: a coral-to-mint sound wave under every page title. */
.page-head h1::after {
  content: "";
  display: block;
  width: 132px;
  height: 14px;
  margin: 14px 0 0;
  background: linear-gradient(90deg, var(--coral), var(--accent));
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 132 14'%3E%3Cpath d='M1 7c5.5 0 5.5-5 11-5s5.5 10 11 10 5.5-10 11-10 5.5 10 11 10 5.5-10 11-10 5.5 10 11 10 5.5-10 11-10 5.5 10 11 10 5.5-10 11-10 5.5 10 11 10 5.5-5 11-5' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 132 14'%3E%3Cpath d='M1 7c5.5 0 5.5-5 11-5s5.5 10 11 10 5.5-10 11-10 5.5 10 11 10 5.5-10 11-10 5.5 10 11 10 5.5-10 11-10 5.5 10 11 10 5.5-10 11-10 5.5 10 11 10 5.5-5 11-5' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

.lede {
  margin: 12px 0 0;
  font-size: var(--step-1);
  line-height: 1.55;
  color: var(--text-2);
  max-width: 40rem;
}

.content h2 {
  margin: 48px 0 12px;
  font-size: var(--step-2);
  line-height: 1.3;
  letter-spacing: -0.01em;
  font-weight: 700;
}
.content h3 {
  margin: 28px 0 8px;
  font-size: var(--step-1);
  line-height: 1.35;
  font-weight: 600;
}
.content h2 + h3 { margin-top: 12px; }
.content p, .content li { max-width: 42rem; }
.content p { margin: 0 0 14px; }
.content ul, .content ol { margin: 0 0 16px; padding-left: 1.4em; }
.content li + li { margin-top: 6px; }
.content strong { font-weight: 600; color: var(--text); }

.heading-anchor { color: inherit; text-decoration: none; }
.heading-anchor:hover { color: inherit; text-decoration: underline; text-decoration-color: var(--accent); }

code {
  font-family: var(--mono);
  font-size: 0.88em;
  padding: 0.1em 0.38em;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow-wrap: anywhere;
}

pre {
  margin: 0 0 16px;
  padding: 14px 16px;
  overflow-x: auto;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  line-height: 1.5;
}
pre code { padding: 0; border: 0; background: none; overflow-wrap: normal; }

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0.05em 0.45em;
  font-family: var(--mono);
  font-size: 0.85em;
  line-height: 1.5;
  text-align: center;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  white-space: nowrap;
}

/* UI label as it appears in the app */
.ui {
  font-weight: 600;
  color: var(--text);
}

/* ---------- Components ---------- */

/* Numbered steps */
.steps {
  list-style: none;
  counter-reset: step;
  padding: 0 !important;
  margin: 8px 0 24px !important;
}
.steps > li {
  position: relative;
  counter-increment: step;
  padding: 2px 0 18px 52px;
  margin: 0 !important;
}
.steps > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.95rem;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}
.steps > li:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 17px;
  top: 40px;
  bottom: 4px;
  width: 1px;
  background: var(--border-strong);
}
.steps > li > strong:first-child { display: block; font-size: 1.05rem; margin-bottom: 2px; }

/* Callouts */
.callout {
  margin: 20px 0;
  padding: 14px 16px 14px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
}
.callout > :last-child { margin-bottom: 0; }
.callout-title { display: block; margin-bottom: 4px; font-weight: 700; }
.callout.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.callout.ai { border-left-color: var(--blue); background: var(--blue-soft); }
.callout.audio { border-left-color: var(--coral); background: var(--coral-soft); }
.callout.soon { border-left-color: var(--text-3); background: var(--surface-2); }

/* Tables: the wrapper scrolls on narrow screens, the page never does */
.table-scroll {
  margin: 16px 0 24px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.93rem;
  line-height: 1.45;
}
th, td {
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
thead th {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
  background: var(--surface-2);
  white-space: nowrap;
}
tbody tr:last-child > * { border-bottom: 0; }
tbody th { font-weight: 600; white-space: nowrap; }
.table-wide table { min-width: 640px; }

/* Screenshots: keep a calm frame even when the PNG is not there yet */
.shot {
  margin: 24px 0 28px;
}
.shot-frame {
  overflow: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-strong);
  background:
    linear-gradient(135deg, var(--surface), var(--bg-tint));
  box-shadow: var(--shadow);
}
.shot img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1100 / 800;
  object-fit: cover;
  color: var(--text-3);
  font-size: var(--step--1);
}
.shot.is-missing .shot-frame {
  display: grid;
  place-items: center;
  aspect-ratio: 1100 / 800;
  max-height: 340px;
  width: 100%;
  border-style: dashed;
  box-shadow: none;
}
.shot.is-missing img { display: none; }
.shot.is-missing .shot-frame::before {
  content: attr(data-alt);
  max-width: 28rem;
  padding: 20px;
  text-align: center;
  color: var(--text-3);
  font-size: var(--step--1);
}
.shot figcaption {
  margin-top: 10px;
  font-size: var(--step--1);
  color: var(--text-3);
}

/* Card grid */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
  gap: 12px;
  margin: 16px 0 28px;
}
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color 0.18s ease, transform 0.18s ease;
}
.card h3 { margin: 0 !important; font-size: 1.05rem !important; }
.card p { margin: 0; color: var(--text-2); font-size: 0.93rem; }
.card .meta { color: var(--text-3); font-size: 0.85rem; }
a.card { color: inherit; text-decoration: none; }
a.card:hover { border-color: color-mix(in srgb, var(--accent) 55%, transparent); color: inherit; }
a.card:hover h3 { color: var(--accent); }

.tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
}
.tag.audio { background: var(--coral-soft); color: var(--coral); }
.tag.ai { background: var(--blue-soft); color: var(--blue); }

/* Hero (index) */
.hero {
  display: grid;
  gap: 24px;
  align-items: center;
  margin-bottom: 8px;
}
.hero-banner {
  overflow: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  background: #13322f;
}
.hero-banner img { display: block; width: 100%; height: auto; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }

/* Download chooser */
.downloads {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 13.5rem), 1fr));
  gap: 12px;
  margin: 16px 0 12px;
}
.download {
  padding: 16px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
}
.download h3 { margin: 0 0 4px !important; font-size: 1rem !important; }
.download p { margin: 0 0 8px; font-size: 0.9rem; color: var(--text-2); }
.download code { font-size: 0.84rem; }

/* Pager */
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.pager a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 44px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}
.pager a:hover { border-color: color-mix(in srgb, var(--accent) 55%, transparent); color: var(--accent); }
.pager span { font-size: 0.8rem; font-weight: 500; color: var(--text-3); }
.pager .next { grid-column: 2; text-align: right; }

.site-footer {
  margin-top: 40px;
  font-size: var(--step--1);
  color: var(--text-3);
}
.site-footer p { margin: 0 0 6px; }

/* ---------- Responsive ---------- */
@media (max-width: 959px) {
  .menu-toggle { display: inline-flex; }
  .brand-sub { display: none; }
  .layout { display: block; }

  /* Without JS the nav stays visible in the flow; with JS it becomes a drop-down panel. */
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .js .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    height: auto;
    align-self: stretch; /* fill top-to-bottom; align-self also applies to fixed boxes */
    padding: 16px 16px 40px;
    background: var(--bg);
    border-bottom: 0;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.18s ease, visibility 0s linear 0.18s;
  }
  .js.nav-open .sidebar {
    visibility: visible;
    opacity: 1;
    transition: opacity 0.18s ease;
  }
  .js.nav-open body { overflow: hidden; }
  .nav-group a { min-height: 44px; }
  main { padding-top: 28px; }
}

@media (max-width: 520px) {
  .site-header { padding: 0 10px; gap: 6px; }
  .header-download { padding: 0 10px; }
  .header-download svg { display: none; }
  .lang-toggle { padding: 0 10px; }
  .lang-toggle::after { display: none; }
  .lang-toggle .lang-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .lang-code { display: inline; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
  th, td { padding: 9px 11px; }
  .steps > li { padding-left: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .site-header { background: var(--bg); backdrop-filter: none; -webkit-backdrop-filter: none; }
}

@media print {
  .site-header, .sidebar, .pager { display: none; }
  .layout { display: block; }
  body { background: #fff; color: #000; }
}

/* Secondary inline note, e.g. the Vietnamese name of a macOS permission */
.meta { color: var(--text-3); font-weight: 400; font-size: 0.85rem; }

/* Keep key combos on one line inside table cells */
.nowrap { white-space: nowrap; }
