:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --muted: #9aa3b2;
  --accent: #7c9cff;
  --accent-soft: rgba(124, 156, 255, 0.15);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

[data-theme="light"] {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --border: #e1e4ea;
  --text: #1a1d23;
  --muted: #5b6472;
  --accent: #3b5bdb;
  --accent-soft: rgba(59, 91, 219, 0.1);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.2s, color 0.2s;
}

.hero {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 3rem 1.5rem 1.5rem;
}

.hero-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.hero h1 {
  margin: 0 0 0.25rem;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  letter-spacing: -0.02em;
}

.subtitle { margin: 0; color: var(--muted); }

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 42px;
  height: 42px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { border-color: var(--accent); }

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

#search {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.tag-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.tag-btn {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}
.tag-btn:hover { color: var(--text); border-color: var(--accent); }
.tag-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1.5rem 3rem;
}

.status { color: var(--muted); text-align: center; padding: 2rem 0; }
.status code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}

.group { margin-bottom: 2.5rem; }
.group h2 {
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 1rem;
  font-weight: 600;
}

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

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.card p { margin: 0 0 0.75rem; color: var(--muted); font-size: 0.92rem; }

.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tag {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
}

footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* ===== Viewer (Markdown) ===== */
.viewer {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}
.viewer .back {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
  display: inline-block;
  margin-bottom: 1.5rem;
}
.viewer .back:hover { text-decoration: underline; }

.markdown { font-size: 1rem; }
.markdown h1, .markdown h2, .markdown h3 { letter-spacing: -0.01em; }
.markdown h1 { font-size: 2rem; margin-top: 0; }
.markdown h2 { font-size: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; margin-top: 2rem; }
.markdown h3 { font-size: 1.2rem; margin-top: 1.5rem; }
.markdown a { color: var(--accent); }
.markdown code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.markdown pre {
  background: var(--surface-2);
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  border: 1px solid var(--border);
}
.markdown pre code { background: none; padding: 0; }
.markdown blockquote {
  border-left: 3px solid var(--accent);
  margin: 1rem 0;
  padding: 0.3rem 1rem;
  color: var(--muted);
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
}
.markdown table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
}
.markdown th, .markdown td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}
.markdown th { background: var(--surface-2); }
.markdown img { max-width: 100%; border-radius: 6px; }

@media (max-width: 600px) {
  .hero { padding: 2rem 1rem 1rem; }
  main { padding: 1rem; }
}