/* Ultimate Tong Shu docs */

:root {
  --bg: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-muted: #f1f5f9;
  --text: #1f2328;
  --text-muted: #5b6472;
  --heading: #111418;
  --border: #e5e7eb;
  --accent: #0188ff;
  --accent-strong: #0070d6;
  --accent-soft: #e8f4fd;
  --on-accent: #ffffff;
  --warn-bg: #fdf0ee;
  --warn-border: #e74c3c;
  --red: #c0392b;
  --mark: #fde68a;
  --badge-bg: #dcfce7;
  --badge-text: #166534;
  --shadow: 0 1px 2px rgb(15 23 42 / 0.05), 0 6px 20px rgb(15 23 42 / 0.06);
  --radius: 10px;
  --header-h: 60px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", "PingFang TC", "Hiragino Sans", "Noto Sans TC",
    "Microsoft JhengHei", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --bg-subtle: #14171c;
    --bg-muted: #1c2027;
    --text: #e3e6ea;
    --text-muted: #9aa3ae;
    --heading: #f5f6f7;
    --border: #272c34;
    --accent: #4aa8ff;
    --accent-strong: #84c4ff;
    --accent-soft: #11263b;
    --on-accent: #06121f;
    --warn-bg: #2a1715;
    --warn-border: #ef6b5d;
    --red: #ff8273;
    --mark: #5c4a12;
    --badge-bg: #12321f;
    --badge-text: #86efac;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 6px 20px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.7 var(--font);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

kbd {
  font: 500 12px/1.5 var(--font);
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text-muted);
}

.skip-link {
  position: absolute;
  left: -9999px;
}

.skip-link:focus {
  left: 16px;
  top: 10px;
  z-index: 100;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--bg);
  box-shadow: var(--shadow);
}

/* Header */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--heading);
  font-weight: 650;
  font-size: 17px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand:hover {
  text-decoration: none;
}

.brand img {
  flex: none;
  width: 28px;
  height: 28px;
}

@media (prefers-color-scheme: dark) {
  .brand img {
    filter: invert(1);
  }
}

.brand-tag {
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--bg-muted);
}

.menu-btn {
  display: none;
}

.search-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(300px, 100%);
  height: 38px;
  margin-left: auto;
  padding: 0 8px 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.search-btn:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}

.search-btn kbd {
  margin-left: auto;
}

.app-link {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.app-link:hover {
  background: var(--accent-strong);
  text-decoration: none;
}

/* Layout */

.layout {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr) 240px;
  max-width: 1480px;
  margin: 0 auto;
}

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

.nav-heading {
  margin: 0 0 8px;
  padding: 0 10px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sidebar ul {
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
}

.sidebar a {
  display: block;
  margin: 1px 0;
  padding: 7px 10px;
  border-radius: 7px;
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.4;
}

.sidebar a:hover {
  background: var(--bg-muted);
  text-decoration: none;
}

.sidebar a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}

.scrim {
  display: none;
}

.content {
  min-width: 0;
  padding: 44px 56px 32px;
}

.doc,
.page-meta,
.pager,
.site-footer {
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

/* Table of contents */

.toc {
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 44px 24px 40px 8px;
  font-size: 13.5px;
}

.toc-title {
  margin: 0 0 10px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.toc ul {
  margin: 0;
  padding: 0;
  list-style: none;
  border-left: 1px solid var(--border);
}

.toc a {
  display: block;
  margin-left: -1px;
  padding: 4px 0 4px 12px;
  border-left: 2px solid transparent;
  color: var(--text-muted);
  line-height: 1.45;
}

.toc .l3 a {
  padding-left: 24px;
  font-size: 13px;
}

.toc a:hover {
  color: var(--text);
  text-decoration: none;
}

.toc a.active {
  border-left-color: var(--accent);
  color: var(--accent);
}

/* Article */

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.doc h1,
.doc h2,
.doc h3,
.doc h4 {
  position: relative;
  color: var(--heading);
  line-height: 1.3;
}

.doc h1 {
  margin: 0 0 20px;
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.doc h2 {
  margin: 56px 0 14px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.doc h1 + h2 {
  margin-top: 28px;
  padding-top: 0;
  border-top: 0;
}

.doc h3 {
  margin: 40px 0 10px;
  font-size: 1.2rem;
  font-weight: 650;
}

.doc h4 {
  margin: 32px 0 8px;
  font-size: 1.05rem;
  font-weight: 600;
}

.anchor {
  position: absolute;
  left: -1.1em;
  width: 1.1em;
  color: var(--text-muted);
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.15s;
}

.anchor::before {
  content: "#";
}

.doc h2 .anchor {
  top: 28px;
}

.doc h1 + h2 .anchor {
  top: 0;
}

.doc :is(h2, h3, h4):hover .anchor {
  opacity: 1;
  text-decoration: none;
}

.doc p,
.doc ul,
.doc ol {
  margin: 0 0 16px;
}

.doc ul,
.doc ol {
  padding-left: 1.5em;
}

.doc li {
  margin: 4px 0;
}

.doc li > p {
  margin: 0 0 8px;
}

.doc li > ol,
.doc li > ul {
  margin: 4px 0 8px;
}

.doc li::marker {
  color: var(--text-muted);
}

.doc strong {
  color: var(--heading);
  font-weight: 600;
}

.lead {
  color: var(--text-muted);
  font-size: 1.125rem;
}

.doc figure {
  margin: 20px 0 28px;
}

.doc figure img {
  display: block;
  width: auto;
  max-width: min(100%, var(--w, 100%));
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
  cursor: zoom-in;
}

.ui {
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.92em;
  font-weight: 500;
  white-space: nowrap;
}

.callout {
  margin: 20px 0 24px;
  padding: 14px 18px;
  border-left: 4px solid var(--warn-border);
  border-radius: 0 8px 8px 0;
  background: var(--warn-bg);
}

.callout p:last-child {
  margin-bottom: 0;
}

.doc .pairs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0;
  list-style: none;
}

.pairs li {
  margin: 0;
  padding: 2px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--heading);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.cjk-set {
  color: var(--heading);
  font-size: 1.15em;
  font-weight: 600;
  letter-spacing: 0.2em;
}

.doc .swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 24px;
  padding: 0;
  list-style: none;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  vertical-align: -2px;
}

.swatch-green { background: #b9e4b5; }
.swatch-grey { background: #d1d5db; }
.swatch-white { background: #ffffff; }
.swatch-red { background: #e74c3c; }
.swatch-black { background: #111111; }

.text-red {
  color: var(--red);
  font-weight: 600;
}

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.75;
  text-transform: uppercase;
  vertical-align: 1px;
}

/* Page footer */

.page-meta {
  margin-top: 48px;
  color: var(--text-muted);
  font-size: 13.5px;
}

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 20px;
}

.pager a {
  display: block;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}

.pager a:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.pager .next {
  grid-column: 2;
  text-align: right;
}

.pager .label {
  display: block;
  color: var(--text-muted);
  font-size: 12.5px;
}

.pager .title {
  color: var(--heading);
  font-weight: 600;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13.5px;
}

/* Search */

.search-dialog {
  width: min(640px, calc(100vw - 32px));
  max-width: none;
  max-height: min(560px, calc(100dvh - 120px));
  margin: 10vh auto auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 24px 64px rgb(0 0 0 / 0.25);
}

.search-dialog[open] {
  display: flex;
  flex-direction: column;
}

.search-dialog::backdrop {
  background: rgb(15 23 42 / 0.45);
  backdrop-filter: blur(2px);
}

.search-field {
  display: flex;
  flex: none;
  align-items: center;
  gap: 10px;
  padding: 0 12px 0 18px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}

.search-field input {
  flex: 1;
  min-width: 0;
  height: 56px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 17px;
}

.search-field input::-webkit-search-cancel-button {
  display: none;
}

.search-close {
  padding: 4px;
  border: 0;
  background: none;
  cursor: pointer;
}

.results {
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  list-style: none;
}

.results a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
}

.results a:hover,
.results [aria-selected="true"] a {
  background: var(--accent-soft);
  text-decoration: none;
}

.result-page {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
}

.result-title {
  display: block;
  color: var(--heading);
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.4;
}

.result-snippet {
  display: -webkit-box;
  margin-top: 2px;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.results mark {
  border-radius: 3px;
  background: var(--mark);
  color: inherit;
}

.results-empty {
  padding: 28px 16px;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}

/* Image zoom */

.lightbox {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 24px;
  border: 0;
  background: transparent;
  cursor: zoom-out;
}

.lightbox[open] {
  display: grid;
  place-items: center;
}

.lightbox::backdrop {
  background: rgb(10 12 16 / 0.86);
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 64px rgb(0 0 0 / 0.4);
}

/* Responsive */

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .toc {
    display: none;
  }
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .menu-btn {
    display: grid;
    margin-left: -8px;
  }

  .sidebar {
    position: fixed;
    top: var(--header-h);
    bottom: 0;
    left: 0;
    z-index: 25;
    width: min(300px, 85vw);
    height: auto;
    background: var(--bg);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    visibility: hidden;
  }

  .nav-open .sidebar {
    transform: none;
    visibility: visible;
    box-shadow: var(--shadow);
  }

  .nav-open .scrim {
    position: fixed;
    inset: var(--header-h) 0 0;
    z-index: 20;
    display: block;
    background: rgb(15 23 42 / 0.35);
  }

  .content {
    padding: 32px 16px 24px;
  }
}

@media (max-width: 640px) {
  .topbar {
    gap: 6px;
    padding: 0 12px 0 16px;
  }

  .brand-tag,
  .search-btn span,
  .search-btn kbd {
    display: none;
  }

  .search-btn {
    justify-content: center;
    width: 38px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--text);
  }

  .app-link {
    padding: 0 12px;
  }

  .doc h1 {
    font-size: 1.75rem;
  }

  .doc h2 {
    font-size: 1.3rem;
  }

  .anchor {
    display: none;
  }

  .pager {
    grid-template-columns: 1fr;
  }

  .pager .next {
    grid-column: 1;
  }
}

@media (max-width: 400px) {
  .brand-name {
    font-size: 15px;
  }

  .app-link span {
    display: none;
  }

  .app-link {
    width: 38px;
    justify-content: center;
    padding: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}
