:root {
  --bg: #0f1115;
  --bg-elevated: #161a21;
  --bg-card: #1b2029;
  --border: #2a3040;
  --text: #e6e8ec;
  --text-muted: #9aa3b2;
  --accent: #7dd3fc;
  --accent-strong: #38bdf8;
  --code-bg: #0b0e13;
  --badge-bg: #22283a;
  --tip-bg: #2a2410;
  --tip-border: #6b5b1f;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --radius: 10px;
}

:root[data-theme="light"] {
  --bg: #f7f8fa;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --border: #e2e5eb;
  --text: #1c2128;
  --text-muted: #5b6472;
  --accent: #0284c7;
  --accent-strong: #0369a1;
  --code-bg: #f1f3f6;
  --badge-bg: #eef1f6;
  --tip-bg: #fff8e1;
  --tip-border: #f0d98c;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f7f8fa;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --border: #e2e5eb;
    --text: #1c2128;
    --text-muted: #5b6472;
    --accent: #0284c7;
    --accent-strong: #0369a1;
    --code-bg: #f1f3f6;
    --badge-bg: #eef1f6;
    --tip-bg: #fff8e1;
    --tip-border: #f0d98c;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 76px; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #0b0e13;
  padding: .5em 1em;
  z-index: 200;
}
.skip-link:focus { left: 0; }

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: .92em;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: .8rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.logo {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
}
.logo:hover { color: var(--accent); }

.header-controls {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex: 1;
  justify-content: flex-end;
}
.search-wrap { flex: 1; max-width: 320px; }
#search {
  width: 100%;
  padding: .5em .8em;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: .9rem;
}
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

#theme-toggle, .nav-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 2.2em;
  height: 2.2em;
  cursor: pointer;
  font-size: 1rem;
}
#theme-toggle:hover, .nav-toggle:hover { border-color: var(--accent); }
.nav-toggle { display: none; }

/* Visitor counter (retro-style, intentionally fixed dark look in both themes) */
.counter-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: .5em;
  background: #000;
  color: #cbd5e1;
  font-size: .82rem;
  padding: .55em 1em;
  border-bottom: 1px solid var(--border);
}
.counter-digits {
  display: inline-flex;
  gap: 2px;
}
.counter-digit {
  background: #111;
  color: #39ff6a;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
  padding: .25em .35em;
  border-radius: 3px;
  border: 1px solid #222;
  box-shadow: inset 0 0 4px rgba(57, 255, 106, .45);
  min-width: 1ch;
  text-align: center;
}

/* Layout */
.layout {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 2rem;
  padding: 1.5rem 1.2rem 3rem;
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 76px;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a {
  display: block;
  padding: .45em .6em;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 6px;
  font-size: .92rem;
}
.sidebar a:hover { color: var(--text); background: var(--bg-card); }
.sidebar a.active { color: var(--accent-strong); background: var(--bg-card); font-weight: 600; }

/* Intro */
.intro h1 { margin: 0 0 .3em; font-size: 1.8rem; }
.intro p { color: var(--text-muted); margin: 0 0 .4em; max-width: 640px; }
.meta-count { font-size: .82rem; color: var(--text-muted); }

/* Categories */
.category { margin-top: 2.4rem; scroll-margin-top: 76px; }
.category h2 {
  font-size: 1.25rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: .5em;
  margin-bottom: 1rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.tag-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.card-head h3 { margin: 0; font-size: 1rem; }
.badge {
  font-size: .7rem;
  background: var(--badge-bg);
  color: var(--text-muted);
  padding: .2em .6em;
  border-radius: 999px;
  white-space: nowrap;
}
.tip-badge { color: #b98900; }
:root[data-theme="dark"] .tip-badge,
:root:not([data-theme="light"]) .tip-badge { color: #e8c14a; }

.desc { margin: 0; font-size: .9rem; color: var(--text-muted); }

.demo {
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: .8rem;
  font-size: .9rem;
}
.demo-table { border-collapse: collapse; width: 100%; font-size: .85rem; }
.demo-table th, .demo-table td { border: 1px solid var(--border); padding: .3em .6em; text-align: left; }

.code-block { position: relative; }
.code-block pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .8rem;
  margin: 0;
  overflow-x: auto;
  font-size: .82rem;
}
.copy-btn {
  position: absolute;
  top: .4rem;
  right: .4rem;
  font-size: .72rem;
  padding: .25em .6em;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.copy-btn.copied { color: #4ade80; border-color: #4ade80; }

.tip {
  margin: 0;
  font-size: .82rem;
  background: var(--tip-bg);
  border: 1px solid var(--tip-border);
  border-radius: 8px;
  padding: .5em .7em;
}

.no-results {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 0;
}

/* Responsive */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    display: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .6rem;
    background: var(--bg-card);
    margin-bottom: 1rem;
  }
  .sidebar.open { display: block; }
  .nav-toggle { display: inline-block; }
  .search-wrap { max-width: none; }
  .header-controls { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .header-inner { flex-wrap: wrap; }
  .search-wrap { order: 3; flex-basis: 100%; }
}
