:root {
  --bg: #f3efe6;
  --ink: #1c1915;
  --muted: #6d675e;
  --card: #fffdf8;
  --line: #e3dbcf;
  --shadow: 0 10px 30px rgba(40, 28, 16, 0.06);
  --accent: #c4552a;
  --code: #1c1915;
  --code-ink: #f6f1e7;
  --prog: #c4552a;
  --tool: #0f6e6b;
  --linux: #2d6a3a;
  --db: #3a4d9a;
  --http: #8a4b2f;
  --radius: 16px;
  --sans: "Segoe UI", "Helvetica Neue", sans-serif;
  --mono: "Cascadia Code", "JetBrains Mono", ui-monospace, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12110f;
    --ink: #f3efe6;
    --muted: #b3aa9e;
    --card: #1c1a17;
    --line: #322d27;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
    --code: #0c0b0a;
    --code-ink: #f3efe6;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 0% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}
a { color: inherit; }
button, input { font: inherit; color: inherit; }
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--ink);
  color: var(--bg);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 5;
}
.skip:focus { top: 12px; }

.top {
  position: sticky;
  top: 0;
  z-index: 4;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid transparent;
}
.bar {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
}
.top.is-scrolled { border-bottom-color: var(--line); }
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  text-decoration: none;
  min-width: 0;
}
.mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--bg);
  font-weight: 700;
  letter-spacing: -0.04em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 720; font-size: 18px; letter-spacing: -0.03em; }
.brand-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.search {
  position: relative;
  flex: 1;
  max-width: 460px;
}
.search-ico {
  position: absolute;
  left: 14px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  stroke-linecap: round;
}
.search input {
  width: 100%;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 0 42px 0 42px;
  outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: var(--line);
  cursor: pointer;
}
.clear[hidden] { display: none; }

.cats {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  padding: 4px 22px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.cats::-webkit-scrollbar { display: none; }
.cats a {
  flex: none;
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--muted);
}
.cats a[aria-current="true"] {
  color: var(--ink);
  border-color: var(--ink);
}

main { padding: 8px 22px 64px; max-width: 1120px; margin: 0 auto; }
.group { margin-top: 28px; scroll-margin-top: 118px; }
.group h2 {
  margin: 0 0 4px;
  font-size: 22px;
  letter-spacing: -0.03em;
}
.lead { margin: 0 0 14px; color: var(--muted); }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
}
.card {
  position: relative;
  display: flex;
  min-height: 132px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.card-link {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  min-height: 132px;
  padding: 14px 36px 14px 14px;
  text-decoration: none;
  color: inherit;
}
.card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--tone) 55%, var(--line)); }
.card-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius); }
.star {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.star svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
.star[aria-pressed="true"] { color: var(--accent); }
.star[aria-pressed="true"] svg { fill: currentColor; }
.star:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#cat-fav h2::before { content: "★ "; color: var(--accent); }
.ico {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--tone);
}
.ico svg { width: 20px; height: 20px; }
.sheet-head .ico.lg {
  width: 48px;
  height: 48px;
  border-radius: 14px;
}
.sheet-head .ico.lg svg { width: 26px; height: 26px; }
.card-title { font-weight: 680; letter-spacing: -0.02em; }
.card-hint { color: var(--muted); font-size: 13px; line-height: 1.35; }
.empty {
  margin-top: 48px;
  color: var(--muted);
  text-align: center;
}

.sheet-head { display: flex; gap: 14px; align-items: flex-start; margin: 12px 0 22px; }
.sheet-head h1 { margin: 0; font-size: clamp(28px, 4vw, 40px); letter-spacing: -0.04em; }
.sheet-title { display: flex; align-items: center; gap: 8px; }
.sheet-title .star { position: static; width: 36px; height: 36px; }
.sheet-title .star svg { width: 22px; height: 22px; }
.crumb {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
}
.crumb:hover { color: var(--ink); }
.blocks {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}
.block {
  scroll-margin-top: 92px;
  grid-column: span 6;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-width: 0;
}
.block.half { grid-column: span 3; }
.block.third { grid-column: span 2; }
.block h2 {
  margin: 0;
  padding: 14px 16px 0;
  font-size: 16px;
}
.note { margin: 8px 16px 0; color: var(--muted); font-size: 14px; }
.prehead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 12px 12px 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}
.copy {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 12px;
}
.copy:focus-visible { outline: 2px solid var(--accent); }
pre {
  margin: 10px 12px 12px;
  padding: 14px 16px;
  overflow: auto;
  border-radius: 12px;
  background: var(--code);
  color: var(--code-ink);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.55;
}
table { width: calc(100% - 24px); margin: 12px; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-top: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
td:first-child, th:first-child { white-space: nowrap; width: 1%; }
th { color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
code.inline {
  font-family: var(--mono);
  font-size: 0.92em;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  padding: 1px 5px;
  border-radius: 6px;
}

.toc { display: none; }
.toc-scroll {
  height: 100%;
  overflow: auto;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 4px 72px 8px;
}
.toc-scroll::-webkit-scrollbar { display: none; }
.toc-link {
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  padding: 7px 10px;
  border-radius: 10px;
  border-left: 2px solid transparent;
  cursor: pointer;
}
.toc-link:hover { color: var(--ink); }
.toc-link.is-on {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-left-color: var(--accent);
}
.toc-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.toc-fade {
  position: absolute;
  left: 0;
  right: 0;
  height: 48px;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
}
.toc-fade.top {
  top: 0;
  height: 72px;
  background: linear-gradient(to bottom, var(--bg) 0%, transparent 100%);
  backdrop-filter: blur(10px);
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 42%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 42%, transparent 100%);
}
.toc-fade.bottom {
  bottom: 0;
  height: 96px;
  background: linear-gradient(to top, var(--bg) 0%, transparent 100%);
  backdrop-filter: blur(10px);
  -webkit-mask-image: linear-gradient(to top, #000 0%, #000 46%, transparent 100%);
  mask-image: linear-gradient(to top, #000 0%, #000 46%, transparent 100%);
}
.toc.is-fade-top .toc-fade.top,
.toc.is-fade-bottom .toc-fade.bottom { opacity: 1; }
.to-top {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 6;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.to-top svg { width: 20px; height: 20px; }
.to-top[hidden] { display: none; }
.to-top:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (min-width: 1180px) {
  body.has-toc .bar,
  body.has-toc .cats,
  body.has-toc main { max-width: 1280px; }
  .sheet {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 240px;
    column-gap: 22px;
    align-items: start;
  }
  .toc {
    display: block;
    position: sticky;
    top: 84px;
    height: calc(100vh - 96px);
  }
}
@media (max-width: 980px) {
  .block.third { grid-column: span 3; }
}
@media (max-width: 720px) {
  .block.half, .block.third { grid-column: span 6; }
  .bar { flex-wrap: wrap; padding: 12px 14px; }
  .search { max-width: none; flex-basis: 100%; }
  .cats, main { padding-left: 14px; padding-right: 14px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { min-height: 124px; }
  pre { font-size: 12.5px; }
}
@media (max-width: 420px) {
  .grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .card { transition: none; }
}
