:root {
  color-scheme: light dark;

  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;

  --fringe: clamp(16px, 6vw, 80px);
  --radius: 12px;

  /* Light (Nord/Modus inspired) - Modern & Refined */
  --bg: #fcfcfc;
  --fringe-bg: #f0f0f0;
  --fg: #333333;
  --subtle-fg: #666666;
  --border: #e0e0e0;

  --link: #4e5969;
  --link-hover: #1d2129;

  --hl-line: #f2f3f5;
  --region: #e5e6eb;

  --code-bg: #f7f8fa;
  --code-border: #e5e6eb;
  --code-fg: #333333;

  --btn-bg: #ffffff;
  --btn-border: #d8dee9;
  --btn-hover: #eceff4;

  --mode-line-bg: #e5e9f0;
  --mode-line-fg: #2e3440;
  --mode-line-border: #ccd3de;
  --minibuffer-bg: #f0f4f8;

  --focus: #5e81ac;

  --emacs-bars-height: calc(96px + env(safe-area-inset-bottom, 0px));
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Dark (Nord/Modus inspired) */
    --bg: #1c1c1c;
    --fringe-bg: #141414;
    --fg: #dcdccc;
    --subtle-fg: #8f8f8f;
    --border: #333333;

    --link: #8faf9f;
    --link-hover: #bfebb2;

    --hl-line: #2b2b2b;
    --region: #3f3f3f;

    --code-bg: #242424;
    --code-border: #333333;
    --code-fg: #dcdccc;

    --btn-bg: #3b4252;
    --btn-border: #4c566a;
    --btn-hover: #434c5e;

    --mode-line-bg: #3b4252;
    --mode-line-fg: #eceff4;
    --mode-line-border: #4c566a;
    --minibuffer-bg: #242424;

    --focus: #88c0d0;
  }
}

html[data-theme="light"] {
  --bg: #fcfcfc;
  --fringe-bg: #f0f0f0;
  --fg: #333333;
  --subtle-fg: #666666;
  --border: #e0e0e0;

  --link: #4e5969;
  --link-hover: #1d2129;

  --hl-line: #f2f3f5;
  --region: #e5e6eb;

  --code-bg: #f7f8fa;
  --code-border: #e5e6eb;
  --code-fg: #333333;

  --btn-bg: #ffffff;
  --btn-border: #d8dee9;
  --btn-hover: #eceff4;

  --mode-line-bg: #e5e9f0;
  --mode-line-fg: #2e3440;
  --mode-line-border: #ccd3de;
  --minibuffer-bg: #f0f4f8;

  --focus: #5e81ac;
}

html[data-theme="dark"] {
  --bg: #1c1c1c;
  --fringe-bg: #141414;
  --fg: #dcdccc;
  --subtle-fg: #8f8f8f;
  --border: #333333;

  --link: #8faf9f;
  --link-hover: #bfebb2;

  --hl-line: #2b2b2b;
  --region: #3f3f3f;

  --code-bg: #242424;
  --code-border: #333333;
  --code-fg: #dcdccc;

  --btn-bg: #3b4252;
  --btn-border: #4c566a;
  --btn-hover: #434c5e;

  --mode-line-bg: #3b4252;
  --mode-line-fg: #eceff4;
  --mode-line-border: #4c566a;
  --minibuffer-bg: #242424;

  --focus: #88c0d0;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-mono);
  color: var(--fg);
  background: var(--bg);
  line-height: 1.6;
}

::selection {
  background: var(--region);
}

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

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

code,
pre,
kbd {
  font-family: var(--font-mono);
}

pre {
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid var(--code-border);
  background: var(--code-bg);
  border-radius: var(--radius);
  overflow: auto;
}

pre code {
  font-size: 0.95rem;
  color: var(--code-fg);
}

kbd {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--code-bg);
  color: var(--fg);
  font-size: 0.85em;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}

.skip-link {
  position: absolute;
  left: 10px;
  top: -64px;
  padding: 10px 16px;
  border: 1px solid var(--focus);
  border-radius: var(--radius);
  background: var(--bg);
  font-weight: 600;
  z-index: 100;
  transition: top 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.skip-link:focus {
  top: 10px;
}

.header-line {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 12px calc(var(--fringe) + 4px);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 95%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.buffer-name {
  font-weight: 750;
  letter-spacing: -0.01em;
}

.header-sep {
  opacity: 0.5;
  margin: 0 4px;
}

.header-hint {
  color: var(--subtle-fg);
  font-size: 0.95rem;
}

.header-line__right {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.header-link {
  color: var(--subtle-fg);
}

.header-link:hover {
  color: var(--fg);
}

.buffer {
  max-width: 96ch;
  padding: 32px calc(var(--fringe) + 4px)
    calc(64px + var(--emacs-bars-height));
  margin: 0 auto;
}

.hero {
  padding-top: 12px;
}

.hero__title {
  margin: 0 0 16px;
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--fg);
}

.epigraph {
  margin: 32px auto 40px;
  max-width: 60ch;
  padding: 24px;
  background: color-mix(in srgb, var(--bg) 95%, var(--hl-line));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

.epigraph__quote {
  margin: 0;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 500;
  line-height: 1.8;
  color: var(--fg);
  letter-spacing: 0.05em;
}

.epigraph__quote p {
  margin: 0;
}

.epigraph__quote p + p {
  margin-top: 12px;
}

.epigraph__caption {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--subtle-fg);
  font-size: 0.9rem;
  opacity: 0.8;
}

.epigraph__author {
  font-weight: 600;
}

.epigraph__author::before {
  content: "— ";
}

html[data-lang="zh"] .epigraph__translation {
  display: none;
}

.hero__subtitle {
  margin: 0 0 16px;
  color: var(--subtle-fg);
  font-size: 1.2rem;
  font-weight: 450;
  line-height: 1.5;
}

.hero__meta {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--subtle-fg);
  margin: 16px 0 24px;
  font-size: 0.9rem;
}

.dot {
  opacity: 0.5;
}

.hero__actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 32px;
}

.btn {
  display: inline-block;
  padding: 10px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--fg);
  font-weight: 600;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.btn:hover {
  background: var(--btn-hover);
  border-color: var(--focus);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  text-decoration: none;
}

.btn:active {
  transform: translateY(0);
}

.btn--ghost {
  background: transparent;
  box-shadow: none;
}

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

.section {
  margin-top: 64px;
  border-top: 1px solid var(--border);
  padding-top: 32px;
}

.section--intro {
  border-top: none;
  padding-top: 0;
}

h2 {
  margin: 0 0 20px;
  font-size: 1.6rem;
  letter-spacing: -0.01em;
}

h2::before {
  content: "∗ ";
  color: var(--focus);
  font-weight: bold;
  margin-right: 8px;
}

h3 {
  margin: 20px 0 10px;
  font-size: 1.1rem;
  color: var(--fg);
}

p {
  margin: 10px 0;
}

.screenshot {
  margin: 14px 0 0;
}

.screenshot img {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.screenshot figcaption {
  margin-top: 8px;
  color: var(--subtle-fg);
  font-size: 0.95rem;
}

.feature-list,
.hud-list,
.modes,
.link-list {
  padding-left: 18px;
  margin: 10px 0;
}

.callout {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg) 86%, var(--hl-line));
}

.callout__title {
  font-weight: 700;
  margin-bottom: 8px;
}

.key-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.key-table th,
.key-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.key-table th {
  text-align: left;
  background: color-mix(in srgb, var(--bg) 88%, var(--hl-line));
}

.key-table tr:hover td {
  background: color-mix(in srgb, var(--bg) 86%, var(--hl-line));
}

.emacs-bars {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08);
}

.mode-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px calc(var(--fringe) + 4px);
  background: var(--mode-line-bg);
  color: var(--mode-line-fg);
  border-top: 1px solid var(--mode-line-border);
  font-weight: 500;
  font-size: 0.95rem;
}

.mode-line a {
  color: inherit;
  transition: opacity 0.2s;
}

.mode-line a:hover {
  opacity: 0.8;
  text-decoration: underline;
}

.mode-line__left {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  min-width: 0;
}

.mode-line__right {
  display: flex;
  gap: 12px;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  text-align: right;
  min-width: 0;
}

.ml-sep {
  opacity: 0.4;
}

.ml-buffer {
  font-weight: 750;
}

.ml-major {
  color: color-mix(in srgb, var(--mode-line-fg) 70%, var(--subtle-fg));
}

.ml-zone {
  font-weight: 750;
  color: var(--focus);
  transition: all 0.3s ease;
  display: inline-block;
  min-width: 1.2ch;
  text-align: center;
}

.ml-section {
  max-width: 36ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.2s;
}

.ml-position {
  color: color-mix(in srgb, var(--mode-line-fg) 80%, var(--subtle-fg));
  font-variant-numeric: tabular-nums;
  min-width: 4ch;
  text-align: right;
}

.minibuffer {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px calc(var(--fringe) + 4px);
  background: var(--minibuffer-bg);
  border-top: 1px solid var(--mode-line-border);
  font-weight: 500;
}

.minibuffer__prompt {
  color: var(--subtle-fg);
  opacity: 0.8;
}

.minibuffer__message {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg);
}

.minibuffer__flash {
  font-weight: 600;
  color: var(--focus);
}

.minibuffer__suffix {
  color: var(--subtle-fg);
  opacity: 0.6;
}

.toggle-btn {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--subtle-fg);
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn:hover {
  color: var(--fg);
  background: var(--btn-hover);
  border-color: var(--focus);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

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

@media (max-width: 720px) {
  .header-line {
    position: static;
  }

  .buffer {
    padding-top: 18px;
  }

  .minibuffer__message {
    white-space: normal;
  }
}
