/* ==========================================================
   OI 训练指南 — 基础样式表
   极简 / 单主题 / 无依赖 / 全部使用相对路径
   想换配色：只改 :root 里的几个变量即可
   ========================================================== */

:root {
  --bg: #fcfcfa;
  --surface: #ffffff;
  --ink: #16181b;
  --ink-soft: #4c5158;
  --ink-faint: #8a8f97;
  --line: #e8e7e2;
  --line-strong: #d5d3ca;
  --accent: #0f6b5c;
  --accent-ink: #0b5348;
  --accent-soft: #edf5f2;

  --radius: 14px;
  --maxw: 1060px;
  --pad: clamp(18px, 4vw, 32px);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Consolas,
    "Liberation Mono", Menlo, monospace;
}

/* ---------- reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}
img,
svg {
  max-width: 100%;
}
a {
  color: var(--accent-ink);
  text-decoration: none;
  text-underline-offset: 3px;
}
a:hover {
  text-decoration: underline;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ---------- layout ---------- */
.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding-inline: var(--pad);
}
.sec {
  border-top: 1px solid var(--line);
  padding-block: clamp(44px, 6vw, 76px);
}
.skip {
  position: absolute;
  left: -9999px;
}
.skip:focus {
  left: 12px;
  top: 12px;
  z-index: 99;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 14px;
}

/* ---------- header ---------- */
.site-head {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(252, 252, 250, 0.86);
  -webkit-backdrop-filter: saturate(150%) blur(10px);
  backdrop-filter: saturate(150%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.site-head .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 20px;
  min-height: 66px;
}
.site-head.is-scrolled {
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02), 0 8px 24px -20px rgba(0, 0, 0, 0.4);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 650;
  letter-spacing: -0.01em;
}
.brand:hover {
  text-decoration: none;
}
.brand svg {
  width: 26px;
  height: 26px;
  flex: none;
}
.brand small {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  line-height: 1.2;
  text-transform: uppercase;
}
.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.nav a {
  color: var(--ink-soft);
  font-size: 14.5px;
  padding: 7px 12px;
  border-radius: 8px;
}
.nav a:hover {
  color: var(--ink);
  background: #f1f0eb;
  text-decoration: none;
}
.nav a[aria-current="page"] {
  color: var(--accent-ink);
  background: var(--accent-soft);
  font-weight: 600;
}

/* ---------- hero ---------- */
.hero {
  padding-block: clamp(38px, 6vw, 76px) clamp(40px, 6vw, 72px);
}
.hero-grid {
  display: grid;
  grid-template-columns: 1.12fr 0.88fr;
  gap: clamp(26px, 4vw, 52px);
  align-items: center;
}
.eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 14px;
}
h1 {
  margin: 0 0 18px;
  font-size: clamp(2rem, 4.6vw, 3.1rem);
  line-height: 1.22;
  letter-spacing: -0.025em;
  font-weight: 720;
}
h2 {
  margin: 0 0 14px;
  font-size: clamp(1.42rem, 2.7vw, 1.95rem);
  line-height: 1.3;
  letter-spacing: -0.015em;
  font-weight: 700;
}
h3 {
  margin: 0 0 8px;
  font-size: 1.06rem;
  line-height: 1.45;
  font-weight: 660;
}
p {
  margin: 0 0 14px;
  text-wrap: pretty; /* 支持时避免末行只剩一两个字 */
}
.lede {
  font-size: clamp(1rem, 1.5vw, 1.12rem);
  color: var(--ink-soft);
  max-width: 34em;
  margin-bottom: 26px;
}
.muted {
  color: var(--ink-soft);
}
.small {
  font-size: 14px;
  line-height: 1.7;
}
.faint {
  color: var(--ink-faint);
}

/* ---------- buttons ---------- */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 22px;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.btn:hover {
  text-decoration: none;
  transform: translateY(-1px);
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-ink);
}
.btn-ghost {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink);
}
.btn-ghost:hover {
  border-color: var(--ink-faint);
}
.meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  list-style: none;
  margin: 0;
  padding: 0;
}

/* ---------- code card ---------- */
.codecard {
  background: #14171a;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 18px 40px -24px rgba(15, 23, 42, 0.45);
}
.codecard__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
}
.codecard__name {
  margin-left: 4px;
  font-family: var(--mono);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
}
.codecard pre {
  margin: 0;
  padding: 16px 16px 20px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.6px;
  line-height: 1.85;
  color: #d8e2e0;
  tab-size: 4;
}
.codecard .k {
  color: #7fd1bd;
}
.codecard .t {
  color: #e6c07b;
}
.codecard .c {
  color: #7b858c;
}

/* ---------- section head ---------- */
.sec-head {
  max-width: 42em;
  margin-bottom: clamp(22px, 3vw, 34px);
}

/* ---------- grids & cards ---------- */
.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 244px), 1fr));
}
.grid-2 {
  display: grid;
  gap: clamp(18px, 3vw, 30px);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
}
/* 正好 4 项时用 2×2，避免出现「3+1」的孤儿卡片 */
.grid-2x2 {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
/* 问答：两列，行内自动对齐 */
.faq {
  display: grid;
  gap: 30px 44px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
}
.faq h3 {
  margin-bottom: 6px;
}
.faq p {
  margin: 0;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  transition: border-color 0.2s ease, transform 0.2s ease;
}
.card:hover {
  border-color: var(--line-strong);
  transform: translateY(-2px);
}
.card p:last-child {
  margin-bottom: 0;
}
.card .num {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.08em;
  display: block;
  margin-bottom: 10px;
}

/* ---------- timeline ---------- */
.steps {
  list-style: none;
  margin: 0;
  padding: 0 0 0 26px;
  border-left: 1px solid var(--line-strong);
}
.steps > li {
  position: relative;
  padding: 0 0 30px 0;
}
.steps > li:last-child {
  padding-bottom: 0;
}
.steps > li::before {
  content: "";
  position: absolute;
  left: -32px;
  top: 7px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent);
}
.steps h3 {
  margin-bottom: 4px;
}
.steps .when {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  text-transform: uppercase;
  display: block;
  margin-bottom: 6px;
}
.steps p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 15px;
}

/* ---------- callout ---------- */
.callout {
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--surface);
  padding: 18px 20px;
  margin: 0;
  font-size: 15.5px;
  color: var(--ink-soft);
}
.callout strong {
  color: var(--ink);
}

/* ---------- chips ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}
.chips li {
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 8px;
}
.chips.neutral li {
  color: var(--ink-soft);
  background: #f2f1ec;
}

/* ---------- checklist ---------- */
.check {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.check li {
  position: relative;
  padding-left: 26px;
  font-size: 15px;
  color: var(--ink-soft);
}
.check li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
}

/* ---------- table ---------- */
.tbl-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
  min-width: 540px;
}
th,
td {
  text-align: left;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
thead th {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
/* 速查表：整行可点，跳到对应模板 */
.tbl-idx tbody tr {
  cursor: pointer;
}
.tbl-idx tbody tr:hover td {
  background: #f7f7f1;
}
.tbl-idx tbody td a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.tbl-idx tbody tr:hover td a,
.tbl-idx tbody td a:focus-visible {
  color: var(--accent-ink);
  border-bottom-color: currentColor;
  text-decoration: none;
}
/* 跳到模板后落点不要被吸顶栏盖住 */
.tpl {
  scroll-margin-top: 86px;
}
.tpl.is-flash {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 107, 92, 0.12);
}

/* 速查表：最后一列只放跳转箭头，别占宽度 */
.tbl-idx th:last-child,
.tbl-idx td:last-child {
  width: 56px;
  text-align: right;
  white-space: nowrap;
}
.tbl-idx td:last-child a {
  color: var(--accent);
  font-weight: 600;
}
/* 第一列通常是短标签（CSP-J 二等、OI 赛制…），不要被挤成两行 */
tbody td:first-child {
  white-space: nowrap;
}
tbody tr:last-child td {
  border-bottom: 0;
}
td code,
p code,
li code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: #f2f1ec;
  border-radius: 5px;
  padding: 1px 6px;
}

/* ---------- stage block ---------- */
.stage {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 12px clamp(16px, 3vw, 34px);
  padding-block: clamp(22px, 3vw, 30px);
  border-top: 1px solid var(--line);
}
.stage:first-of-type {
  border-top: 0;
  padding-top: 0;
}
.stage__side h3 {
  margin-bottom: 6px;
}
.stage__side .mono-label {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: var(--accent);
  display: block;
  margin-bottom: 6px;
}
.stage__body p:last-child {
  margin-bottom: 0;
}
.stage__body .check {
  margin-top: 12px;
}

/* ---------- footer ---------- */
.site-foot {
  border-top: 1px solid var(--line);
  padding-block: 34px 44px;
  font-size: 14px;
  color: var(--ink-faint);
}
.site-foot .wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 28px;
  justify-content: space-between;
  align-items: flex-start;
}
.site-foot nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
}

/* ---------- light code block ---------- */pre.term {
  margin: 0 0 14px;
  padding: 14px 16px;
  background: #f4f4f0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.6px;
  line-height: 1.95;
  color: #2b2f33;
}
pre.term .cm {
  color: #8a8f97;
}

/* ---------- misc ---------- */
.center-note {
  text-align: center;
  max-width: 44em;
  margin-inline: auto;
}
.center-note .actions {
  justify-content: center;
}
.foot-name {
  color: var(--ink);
}
.foot-note {
  margin: 6px 0 0;
}
.mt-s {
  margin-top: 12px;
}
.mt-m {
  margin-top: 26px;
}

/* 内容始终可见：不做依赖 JS 的入场动画 */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  .btn:hover,
  .card:hover {
    transform: none;
  }
}

/* ---------- 题目搜索 ---------- */
.search-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(16px, 3vw, 26px);
}
.sform {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.sform input[type="text"] {
  flex: 1 1 260px;
  min-width: 0;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.sform input[type="text"]::placeholder {
  color: #b3b6bb;
}
.sform input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 107, 92, 0.14);
}
.sform .btn {
  flex: 0 0 auto;
}
.sopts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  margin-top: 12px;
  font-size: 13.5px;
  color: var(--ink-faint);
}
.sopts label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-soft);
  cursor: pointer;
}
.sopts input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
}
.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
  padding: 0;
  list-style: none;
}
.examples button {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 9px;
  cursor: pointer;
}
.examples button:hover {
  border-color: var(--accent);
}
kbd {
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 5px;
}

.hits {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}
.hit {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 13px 16px;
}
.hit__main {
  min-width: 0;
}
.hit__kind {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 1px 7px;
  margin-right: 8px;
  vertical-align: 1px;
}
.hit__id {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 650;
}
.hit__note {
  display: block;
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--ink-faint);
}
.hit__links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.hit__links a {
  font-size: 13.5px;
  line-height: 1.5;
  padding: 5px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink-soft);
  background: #fff;
}
.hit__links a:hover {
  border-color: var(--ink-faint);
  color: var(--ink);
  text-decoration: none;
}
.hit__links a[data-primary] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.hit__links a[data-primary]:hover {
  background: var(--accent-ink);
}
.histhead {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 20px;
  font-size: 13px;
  color: var(--ink-faint);
}
.histhead button {
  font: inherit;
  font-size: 12.5px;
  color: var(--ink-faint);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.histhead[hidden] {
  display: none;
}
.shistory {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.shistory button {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
  background: #f4f3ee;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 9px;
  cursor: pointer;
}
.shistory button:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

@media (max-width: 620px) {
  .sform .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
  /* 手机端：速查表只留两列，去掉横向滚动 */
  .tbl-idx {
    min-width: 0;
  }
  .tbl-idx th:nth-child(3),
  .tbl-idx td:nth-child(3) {
    display: none;
  }
  .hit {
    align-items: flex-start;
  }
  .hit__links {
    width: 100%;
  }
}

/* ---------- 算法模板 ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}
.fbtn {
  font: inherit;
  font-size: 13.5px;
  color: var(--ink-soft);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 6px 15px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.fbtn:hover {
  border-color: var(--ink-faint);
  color: var(--ink);
}
.fbtn.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.tpls {
  display: grid;
  gap: 18px;
}
.tpl {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 18px 20px 20px;
}
.tpl[hidden] {
  display: none;
}
.tpl__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 4px;
}
.tpl__head h3 {
  margin: 0;
  font-size: 1.02rem;
}
.tpl__meta {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 1px 7px;
}
.tpl__use {
  margin: 6px 0 12px;
  font-size: 14px;
  color: var(--ink-soft);
}
.tpl__code {
  position: relative;
}
.tpl__code pre {
  margin: 0;
  padding: 14px 16px;
  background: #f4f4f0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.8px;
  line-height: 1.8;
  color: #23282d;
  tab-size: 4;
}
.tpl__code .copy {
  position: absolute;
  top: 8px;
  right: 8px;
  font: inherit;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-soft);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 3px 9px;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.tpl__code .copy:hover {
  opacity: 1;
  color: var(--ink);
  border-color: var(--ink-faint);
}
.tpl__code .copy.is-done {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  opacity: 1;
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .hero-grid {
    grid-template-columns: 1fr;
  }
  .codecard {
    max-width: 560px;
  }
}
@media (max-width: 620px) {
  .grid-2x2 {
    grid-template-columns: 1fr;
  }
  .site-head .wrap {
    min-height: 58px;
  }
  .nav {
    width: 100%;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 2px;
    padding-bottom: 8px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar {
    display: none;
  }
  .nav a {
    flex: 0 0 auto;
  }
  .nav a {
    padding: 6px 8px;
    font-size: 13.5px;
  }
  .stage {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .steps {
    padding-left: 20px;
  }
  .steps > li::before {
    left: -26px;
  }
}

@media print {
  .site-head,
  .codecard {
    display: none;
  }
  body {
    background: #fff;
  }
}
