:root {
  color-scheme: dark;
  --accent: #F6821F;
  --accent-bright: #ff9b42;
  --accent-soft: rgba(246, 130, 31, 0.14);
  --accent-line: rgba(246, 130, 31, 0.42);
  --bg: #0b0e13;
  --bg-elevated: #11161f;
  --bg-soft: #151c26;
  --surface: rgba(18, 24, 34, 0.84);
  --surface-solid: #121822;
  --surface-hover: #192230;
  --text: #eef1f6;
  --text-soft: #c8ced9;
  --muted: #8e99a9;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  --header-bg: rgba(11, 14, 19, 0.82);
  --code-bg: rgba(246, 130, 31, 0.1);
  --selection: rgba(246, 130, 31, 0.32);
  --font-display: "Space Grotesk", "Noto Sans TC", sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --sidebar-width: 260px;
  --header-height: 72px;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
}

html[data-theme="light"] {
  color-scheme: light;
  --accent: #c95f08;
  --accent-bright: #e06b0d;
  --accent-soft: rgba(246, 130, 31, 0.12);
  --accent-line: rgba(201, 95, 8, 0.36);
  --bg: #f7f5f1;
  --bg-elevated: #ffffff;
  --bg-soft: #f0ece5;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-solid: #ffffff;
  --surface-hover: #f5eee5;
  --text: #171a1f;
  --text-soft: #363d47;
  --muted: #687180;
  --line: rgba(20, 25, 33, 0.1);
  --line-strong: rgba(20, 25, 33, 0.18);
  --shadow: 0 24px 70px rgba(57, 45, 29, 0.12);
  --header-bg: rgba(247, 245, 241, 0.86);
  --code-bg: rgba(246, 130, 31, 0.1);
  --selection: rgba(246, 130, 31, 0.24);
}

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

html {
  scroll-behavior: smooth;
  scrollbar-color: var(--accent-line) var(--bg);
}

body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at 77% -9%, rgba(246, 130, 31, 0.12), transparent 31rem),
    radial-gradient(circle at 8% 42%, rgba(95, 120, 190, 0.07), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.78;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 64px 64px;
  content: "";
  opacity: 0.12;
  pointer-events: none;
  mask-image: linear-gradient(to bottom, black, transparent 78%);
}

::selection {
  background: var(--selection);
  color: var(--text);
}

a {
  color: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 12px;
  z-index: 1000;
  padding: 8px 13px;
  border-radius: 8px;
  background: var(--accent);
  color: #101216;
  font-weight: 700;
  transform: translateY(-160%);
  transition: transform 160ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 clamp(20px, 4vw, 54px);
  border-bottom: 1px solid var(--line);
  background: var(--header-bg);
  backdrop-filter: blur(18px) saturate(145%);
  -webkit-backdrop-filter: blur(18px) saturate(145%);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.brand small {
  margin-left: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--accent-line);
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent);
}

.brand-mark svg {
  width: 29px;
  fill: currentColor;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-toggle,
.menu-toggle {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.theme-toggle:hover,
.menu-toggle:hover {
  border-color: var(--accent-line);
  background: var(--surface-hover);
  transform: translateY(-1px);
}

.theme-toggle svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

html[data-theme="dark"] .icon-moon,
html[data-theme="light"] .icon-sun {
  display: none;
}

.menu-toggle {
  display: none;
  border-radius: 11px;
}

.menu-toggle span {
  display: block;
  width: 17px;
  height: 2px;
  margin: 2px 0;
  border-radius: 2px;
  background: currentColor;
  transition: transform 180ms ease, opacity 180ms ease;
}

.menu-toggle[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.menu-toggle[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}

.menu-toggle[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: clamp(32px, 5vw, 78px);
  width: min(100% - 40px, 1280px);
  margin: 0 auto;
  padding-top: calc(var(--header-height) + 56px);
}

.sidebar {
  min-width: 0;
}

.sidebar-inner {
  position: sticky;
  top: calc(var(--header-height) + 30px);
  max-height: calc(100vh - var(--header-height) - 54px);
  overflow-y: auto;
  padding: 6px 16px 10px 0;
  scrollbar-width: thin;
}

.toc-label {
  margin: 0 0 17px 15px;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.sidebar nav {
  position: relative;
  display: grid;
  gap: 3px;
}

.sidebar nav::before {
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 0;
  width: 1px;
  background: var(--line);
  content: "";
}

.sidebar nav a {
  position: relative;
  padding: 8px 11px 8px 16px;
  border-radius: 0 8px 8px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  text-decoration: none;
  transition: color 160ms ease, background-color 160ms ease;
}

.sidebar nav a::before {
  position: absolute;
  top: 9px;
  bottom: 9px;
  left: 0;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
  content: "";
  opacity: 0;
  transform: scaleY(0.4);
  transition: opacity 160ms ease, transform 160ms ease;
}

.sidebar nav a:hover {
  background: var(--accent-soft);
  color: var(--text-soft);
}

.sidebar nav a.is-active {
  background: linear-gradient(90deg, var(--accent-soft), transparent);
  color: var(--text);
  font-weight: 700;
}

.sidebar nav a.is-active::before {
  opacity: 1;
  transform: scaleY(1);
}

main {
  min-width: 0;
  padding-bottom: 110px;
}

.section {
  position: relative;
  padding: clamp(56px, 8vw, 92px) 0;
  border-top: 1px solid var(--line);
  scroll-margin-top: calc(var(--header-height) + 26px);
}

.section:first-child {
  border-top: 0;
  padding-top: 28px;
}

.section-heading {
  position: relative;
  max-width: 74ch;
  margin-bottom: 31px;
}

.section-heading h1,
.section-heading h2,
.prose h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1.16;
  text-wrap: balance;
}

.section-heading h1 {
  max-width: 14ch;
  font-size: clamp(3.3rem, 7.5vw, 6.8rem);
  color: var(--text);
}

.section-heading h1::after {
  display: block;
  width: 80px;
  height: 8px;
  margin-top: 25px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  content: "";
}

.section-heading h2 {
  font-size: clamp(1.75rem, 3.3vw, 2.75rem);
}

.section-number {
  display: inline-block;
  margin-bottom: 13px;
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.section-kicker {
  margin: 0 0 14px;
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.prose {
  max-width: 74ch;
  min-width: 0;
  color: var(--text-soft);
  font-size: 16px;
}

.prose h2 {
  margin-bottom: 21px;
  color: var(--text);
  font-size: clamp(1.6rem, 3vw, 2.15rem);
}

.prose h3 {
  margin: 0 0 10px;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 18px;
  line-height: 1.45;
}

.prose p {
  margin: 0 0 1.35em;
}

.prose strong {
  color: var(--text);
  font-weight: 700;
}

.prose code {
  padding: 0.08em 0.38em;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--code-bg);
  color: var(--accent-bright);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.88em;
  overflow-wrap: anywhere;
}

.lede {
  max-width: 64ch;
  color: var(--text);
  font-size: clamp(1.06rem, 2vw, 1.22rem);
  line-height: 1.78;
}

.source-note {
  margin: 0 0 28px;
  padding: 12px 15px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.source-note p {
  margin: 0;
}

.callout {
  position: relative;
  margin-top: 24px !important;
  padding: 18px 20px 18px 23px;
  overflow: hidden;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-md);
  background:
    linear-gradient(135deg, var(--accent-soft), transparent 72%),
    var(--surface);
  box-shadow: var(--shadow);
}

.callout::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 3px;
  background: var(--accent);
  content: "";
}

.table-wrap {
  width: 100%;
  margin: 24px 0 30px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow);
  scrollbar-color: var(--accent-line) transparent;
}

table {
  width: 100%;
  min-width: 610px;
  border-collapse: collapse;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.65;
}

th,
td {
  padding: 14px 16px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th:last-child,
td:last-child {
  border-right: 0;
}

tbody tr:last-child td {
  border-bottom: 0;
}

thead th {
  position: relative;
  background: var(--bg-soft);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

thead th::after {
  position: absolute;
  right: 16px;
  bottom: 0;
  left: 16px;
  height: 1px;
  background: linear-gradient(90deg, var(--accent), transparent);
  content: "";
  opacity: 0.55;
}

tbody tr {
  transition: background-color 150ms ease;
}

tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.015);
}

tbody tr:hover {
  background: var(--accent-soft);
}

td:first-child {
  color: var(--text);
  font-weight: 600;
}

.numeric-table td:nth-child(n + 2),
.numeric-table th:nth-child(n + 2) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 30px;
}

.details-grid article,
.pitfall-card,
.conclusion-list article,
.reminder-grid article {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.details-grid article {
  padding: 20px;
}

.details-grid h3 {
  color: var(--accent-bright);
  font-size: 15px;
}

.details-grid p {
  margin: 0;
  font-size: 14px;
  line-height: 1.75;
}

.pitfall-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.pitfall-card {
  position: relative;
  min-height: 210px;
  padding: 26px 24px 23px;
  overflow: hidden;
  transition: border-color 180ms ease, transform 180ms ease;
}

.pitfall-card:hover {
  border-color: var(--accent-line);
  transform: translateY(-2px);
}

.pitfall-card::after {
  position: absolute;
  right: -28px;
  bottom: -42px;
  width: 138px;
  height: 138px;
  border: 1px solid var(--accent-line);
  border-radius: 50%;
  content: "";
  opacity: 0.28;
}

.pitfall-number {
  display: grid;
  width: 34px;
  height: 34px;
  margin-bottom: 25px;
  place-items: center;
  border: 1px solid var(--accent-line);
  border-radius: 50%;
  color: var(--accent-bright);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
}

.pitfall-card p {
  position: relative;
  z-index: 1;
  margin: 0;
  font-size: 14px;
  line-height: 1.8;
}

.conclusion-list {
  display: grid;
  gap: 12px;
}

.conclusion-list article {
  position: relative;
  padding: 21px 23px 20px 28px;
  overflow: hidden;
}

.conclusion-list article::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 3px;
  background: linear-gradient(var(--accent), transparent);
  content: "";
}

.conclusion-list h3 {
  color: var(--accent-bright);
  font-size: 16px;
}

.conclusion-list p {
  margin: 0;
}

.incident {
  margin-bottom: 32px;
  padding: clamp(24px, 4vw, 35px);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 84% 16%, var(--accent-soft), transparent 18rem),
    var(--surface);
  box-shadow: var(--shadow);
}

.incident-meta {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 18px;
  color: var(--accent-bright);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.incident p {
  margin: 0;
}

.reminder-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px;
}

.reminder-grid article {
  padding: 22px;
}

.reminder-grid p {
  margin: 0;
  font-size: 14px;
}

.sources-table table {
  min-width: 690px;
}

.sources-table td:nth-child(2) {
  color: var(--text-soft);
}

.sources-table td:last-child {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: min(100% - 40px, 1280px);
  margin: 0 auto;
  padding: 26px 0 38px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: var(--text-soft);
  font-weight: 700;
  text-decoration-color: var(--accent);
  text-underline-offset: 5px;
}

.error-main {
  display: grid;
  min-height: 100svh;
  padding: calc(var(--header-height) + 46px) 20px 46px;
  place-items: center;
}

.error-panel {
  position: relative;
  width: min(100%, 790px);
  padding: clamp(35px, 8vw, 82px);
  overflow: hidden;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 90% 10%, var(--accent-soft), transparent 22rem),
    var(--surface);
  box-shadow: var(--shadow);
}

.error-panel h1 {
  max-width: 8ch;
  margin: 0 0 24px;
  color: var(--text);
  font-family: var(--font-display);
  font-size: clamp(3.5rem, 10vw, 7rem);
  letter-spacing: -0.06em;
  line-height: 1.05;
}

.error-panel > p:not(.section-kicker) {
  max-width: 48ch;
  margin: 0 0 34px;
  color: var(--text-soft);
}

.error-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 17px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: #101216;
  font-weight: 700;
  text-decoration: none;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.error-link:hover {
  box-shadow: 0 12px 30px var(--accent-soft);
  transform: translateY(-2px);
}

.error-link svg {
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.error-orbit {
  position: absolute;
  top: -96px;
  right: -82px;
  width: 310px;
  height: 310px;
  border: 1px solid var(--accent-line);
  border-radius: 50%;
  opacity: 0.6;
}

.error-orbit span {
  position: absolute;
  border: 1px solid var(--accent-line);
  border-radius: 50%;
}

.error-orbit span:nth-child(1) {
  inset: 38px;
}

.error-orbit span:nth-child(2) {
  inset: 79px;
}

.error-orbit span:nth-child(3) {
  inset: 122px;
  border-color: var(--accent);
  background: var(--accent-soft);
}

@media (prefers-reduced-motion: no-preference) {
  .section {
    animation: section-reveal 600ms both;
    animation-timeline: view();
    animation-range: entry 5% cover 22%;
  }

  @keyframes section-reveal {
    from {
      opacity: 0.3;
      transform: translateY(16px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

@media (max-width: 1050px) {
  .details-grid {
    grid-template-columns: 1fr;
  }

  .details-grid article {
    display: grid;
    grid-template-columns: 142px minmax(0, 1fr);
    gap: 16px;
  }
}

@media (max-width: 899px) {
  :root {
    --header-height: 64px;
  }

  .site-header {
    padding: 0 18px;
  }

  .brand small {
    display: none;
  }

  .menu-toggle {
    display: grid;
  }

  .layout {
    display: block;
    width: min(100% - 32px, 760px);
    padding-top: calc(var(--header-height) + 30px);
  }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    right: 0;
    left: 0;
    z-index: 90;
    padding: 0 16px;
    visibility: hidden;
    pointer-events: none;
  }

  .sidebar::before {
    position: fixed;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(4, 6, 9, 0.62);
    content: "";
    opacity: 0;
    transition: opacity 180ms ease;
    backdrop-filter: blur(4px);
  }

  .sidebar.is-open {
    visibility: visible;
    pointer-events: auto;
  }

  .sidebar.is-open::before {
    opacity: 1;
  }

  .sidebar-inner {
    position: relative;
    top: 0;
    max-height: calc(100vh - var(--header-height) - 30px);
    margin-top: 8px;
    padding: 19px;
    overflow-y: auto;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-md);
    background: var(--surface-solid);
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 180ms ease, transform 180ms ease;
  }

  .sidebar.is-open .sidebar-inner {
    opacity: 1;
    transform: translateY(0);
  }

  .sidebar nav {
    gap: 4px;
  }

  .sidebar nav a {
    padding: 10px 12px 10px 16px;
    font-size: 14px;
  }

  .toc-label {
    margin-bottom: 10px;
  }

  .section:first-child {
    padding-top: 10px;
  }

  .section-heading h1 {
    max-width: 13ch;
  }

  .pitfall-grid,
  .reminder-grid {
    grid-template-columns: 1fr;
  }

  .pitfall-card {
    min-height: 0;
  }
}

@media (max-width: 560px) {
  body {
    font-size: 15px;
  }

  .brand {
    gap: 9px;
    font-size: 14px;
  }

  .brand-mark {
    width: 36px;
    height: 31px;
  }

  .theme-toggle,
  .menu-toggle {
    width: 38px;
    height: 38px;
  }

  .layout {
    width: min(100% - 28px, 760px);
    padding-top: calc(var(--header-height) + 24px);
  }

  .section {
    padding: 58px 0;
  }

  .section-heading {
    margin-bottom: 24px;
  }

  .section-heading h1 {
    font-size: clamp(3rem, 16vw, 4.5rem);
  }

  .section-heading h2 {
    font-size: clamp(1.55rem, 8vw, 2rem);
  }

  .prose {
    font-size: 15px;
  }

  .prose h3 {
    font-size: 16px;
  }

  .callout {
    padding: 16px 17px 16px 20px;
  }

  .table-wrap {
    margin-right: -4px;
    border-radius: 12px;
  }

  th,
  td {
    padding: 12px 13px;
  }

  .details-grid article {
    display: block;
  }

  .details-grid h3 {
    margin-bottom: 7px;
  }

  .pitfall-card {
    padding: 21px 19px;
  }

  .pitfall-number {
    margin-bottom: 19px;
  }

  .incident {
    padding: 22px 19px;
  }

  .site-footer {
    display: block;
    width: min(100% - 28px, 760px);
  }

  .site-footer a {
    display: inline-block;
    margin-top: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  :root {
    color-scheme: light;
  }

  body {
    background: #fff;
    color: #111;
    font-size: 12pt;
  }

  body::before,
  .site-header,
  .sidebar,
  .site-footer,
  .skip-link {
    display: none;
  }

  .layout {
    display: block;
    width: 100%;
    padding: 0;
  }

  .section {
    padding: 24pt 0;
    break-inside: avoid-page;
  }

  .table-wrap,
  .details-grid article,
  .pitfall-card,
  .conclusion-list article,
  .reminder-grid article,
  .incident {
    box-shadow: none;
    break-inside: avoid;
  }

  table {
    min-width: 0;
    font-size: 9pt;
  }
}
