:root {
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #dbeafe;
  --panel-accent-soft: rgba(37, 99, 235, 0.08);
  --panel-bg: #ffffff;
  --panel-header-bg: linear-gradient(135deg, #f8fafc 0%, #eff6ff 100%);
  --sidebar-width: 280px;
  --sidebar-rail-width: 72px;
  --page-toc-width: 15.5rem;
  --content-max-width: 1600px;
  --header-height: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --panel-shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --panel-shadow-hover: 0 10px 25px -5px rgba(37, 99, 235, 0.12), 0 8px 10px -6px rgba(15, 23, 42, 0.08);
  --code-bg: #f1f5f9;
  --pre-bg: #1e293b;
  --pre-text: #e2e8f0;
  --highlight: #fef9c3;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
}

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

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

img {
  max-width: 100%;
  vertical-align: middle;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.site-header .logo {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.site-header .logo:hover {
  color: var(--accent);
  text-decoration: none;
}

.search-wrap {
  flex: 1;
  max-width: 520px;
  position: relative;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  flex-shrink: 0;
}

.subscription-header-btn {
  display: inline-flex;
  align-items: center;
  max-width: 11rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(37, 99, 235, 0.2);
  border-radius: 999px;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subscription-header-btn:hover {
  text-decoration: none;
  background: rgba(37, 99, 235, 0.14);
}

.subscription-header-btn.is-active {
  color: var(--text);
  background: var(--bg-elevated);
  border-color: var(--border);
}

.login-header-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
  white-space: nowrap;
}

.login-header-btn:hover {
  text-decoration: none;
  color: var(--accent);
  border-color: rgba(37, 99, 235, 0.3);
}

.login-header-btn.is-active {
  color: #fff;
  background: #7c3aed;
  border-color: #7c3aed;
}

html[data-admin="true"] .login-header-btn.is-active {
  background: #6d28d9;
}

.sidebar-admin-email {
  padding: 0.35rem 1rem 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  word-break: break-all;
}

.sidebar-logout-btn {
  display: block;
  width: calc(100% - 2rem);
  margin: 0.25rem 1rem 0.5rem;
  padding: 0.45rem 0.75rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.sidebar-logout-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.login-page {
  display: flex;
  justify-content: center;
  padding: 2rem 0 3rem;
}

.login-card {
  width: 100%;
  max-width: 24rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.35rem;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
}

.login-lead {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.login-field input {
  font: inherit;
  font-weight: 400;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
}

.login-field input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: var(--accent);
}

.login-error {
  margin: 0;
  font-size: 0.82rem;
  color: #dc2626;
}

.login-submit {
  margin-top: 0.25rem;
  padding: 0.6rem 1rem;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.login-submit:hover {
  background: var(--accent-hover);
}

.login-footer {
  margin: 1rem 0 0;
  font-size: 0.85rem;
}

.subscription-hidden {
  display: none !important;
}

.sidebar-subscription-panel {
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.35rem;
  margin-bottom: 0.35rem;
}

.subscribe-page {
  max-width: 56rem;
}

.subscribe-hero {
  margin-bottom: 2rem;
}

.subscribe-hero h1 {
  margin: 0 0 0.5rem;
  font-size: 1.65rem;
  letter-spacing: -0.02em;
}

.subscribe-hero p {
  margin: 0 0 0.5rem;
  color: var(--text-muted);
  max-width: 42rem;
}

.subscribe-note {
  font-size: 0.9rem;
  color: var(--text);
}

.subscribe-category {
  margin-bottom: 2rem;
}

.subscribe-category h2 {
  font-size: 1.05rem;
  margin: 0 0 0.85rem;
}

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

.subscribe-role-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 7.75rem;
  text-align: left;
  cursor: pointer;
  font: inherit;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.subscribe-role-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.12);
  transform: translateY(-1px);
}

.subscribe-card-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.subscribe-card-logo,
.subscribe-card-emoji {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--radius) - 2px);
  background: var(--bg);
  border: 1px solid var(--border);
}

.subscribe-card-logo img {
  width: 1.35rem;
  height: 1.35rem;
}

.subscribe-card-emoji {
  font-size: 1.15rem;
}

.subscribe-role-card h3 {
  margin: 0;
  font-size: 1rem;
}

.subscribe-role-card p {
  flex: 1;
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.subscribe-role-card .count {
  margin-top: auto;
  padding-top: 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
}

.subscribe-role-card-suggested {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.subscription-gate {
  max-width: 36rem;
  margin: 2rem auto 3rem;
  padding: 2rem 1.75rem;
  text-align: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.subscription-gate-icon {
  font-size: 2rem;
  margin-bottom: 0.75rem;
}

.subscription-gate h2 {
  margin: 0 0 0.75rem;
  font-size: 1.35rem;
}

.subscription-gate p {
  margin: 0 0 0.65rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.subscription-gate-hint {
  color: var(--text) !important;
  font-size: 0.92rem;
}

.subscription-gate-roles {
  margin-top: 1rem;
  text-align: left;
}

.subscription-gate-role-list {
  list-style: none;
  margin: 0.65rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.subscription-gate-role-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(37, 99, 235, 0.06);
  border: 1px solid rgba(37, 99, 235, 0.15);
  border-radius: var(--radius-sm);
  text-decoration: none;
}

.subscription-gate-role-link:hover {
  background: rgba(37, 99, 235, 0.1);
  text-decoration: none;
}

.subscription-gate-role-icon {
  flex-shrink: 0;
  font-size: 1rem;
  line-height: 1;
}

.subscription-gate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
  margin-top: 1.25rem;
}

.subscription-gate-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.55rem 1.1rem;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
}

.subscription-gate-btn:hover {
  text-decoration: none;
  border-color: var(--accent);
  color: var(--accent);
}

.subscription-gate-btn.primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.subscription-gate-btn.primary:hover {
  color: #fff;
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

html:not([data-subscription-ready]) .sidebar-topics-nav {
  visibility: hidden;
}

[data-theme="dark"] .subscription-header-btn {
  background: rgba(96, 165, 250, 0.12);
  border-color: rgba(96, 165, 250, 0.25);
}

[data-theme="dark"] .subscribe-role-card:hover {
  box-shadow: 0 4px 12px rgba(96, 165, 250, 0.15);
}

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s, border-color 0.15s, transform 0.15s;
}

.theme-toggle-btn:hover {
  background: var(--accent-soft);
  border-color: rgba(37, 99, 235, 0.3);
  color: var(--accent);
}

.theme-toggle-btn:active {
  transform: scale(0.96);
}

.theme-toggle-btn .theme-icon {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
  display: block;
}

html[data-theme="light"] {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

#search-input {
  width: 100%;
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.95rem;
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.search-results {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 420px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  z-index: 200;
}

.search-results.open {
  display: block;
}

.search-result {
  display: block;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}

.search-result:last-child {
  border-bottom: none;
}

.search-result:hover {
  background: var(--bg);
  text-decoration: none;
}

.search-result .q {
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 0.2rem;
}

.search-result .meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.search-empty {
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.menu-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 1.1rem;
}

/* Layout */
.layout {
  display: flex;
  min-height: calc(100vh - var(--header-height));
  transition: none;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  overflow-x: hidden;
  overflow-y: auto;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  padding: 0.35rem 0 1rem;
  transition: width 0.2s ease;
}

.sidebar-rail-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: calc(100% - 1rem);
  margin: 0.35rem 0.5rem 0.65rem;
  padding: 0.45rem 0;
  border: none;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sidebar-rail-toggle:hover {
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent);
}

.sidebar-rail-toggle-icon {
  font-size: 1.15rem;
  line-height: 1;
  font-weight: 700;
}

.sidebar-section {
  margin-bottom: 0.35rem;
}

.sidebar-section:not(:first-child) {
  margin-top: 0.65rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.sidebar-section-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.2rem 1rem 0.45rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: -0.01em;
  line-height: 1.35;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-section-label {
  color: var(--text-muted);
  font-weight: 600;
}

.sidebar-section-label,
.sidebar-link-label,
.toc-link-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity 0.15s ease;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 1rem;
  font-size: 0.88rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.sidebar-link:hover {
  background: var(--bg);
  text-decoration: none;
}

.sidebar-link.active {
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent);
  font-weight: 600;
  border-right: 3px solid var(--accent);
}

.sidebar-link img {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.sidebar-link-emoji {
  width: 22px;
  flex-shrink: 0;
  text-align: center;
  font-size: 1rem;
  line-height: 1;
}

.toc-section {
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
  padding-top: 0.75rem;
}

.toc-section .sidebar-section-title {
  font-size: 0.78rem;
  letter-spacing: -0.01em;
}

.toc-link {
  display: flex;
  align-items: center;
  padding: 0.3rem 1rem 0.3rem 1.35rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}

.toc-link::before {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
  margin-right: 0.55rem;
  flex-shrink: 0;
}

.layout.sidebar-collapsed .sidebar {
  width: var(--sidebar-rail-width);
}

.layout.sidebar-collapsed .sidebar-rail-toggle-icon {
  transform: rotate(180deg);
}

.layout.sidebar-collapsed .sidebar-section-label,
.layout.sidebar-collapsed .sidebar-link-label,
.layout.sidebar-collapsed .toc-link-label,
.layout.sidebar-collapsed .toc-link::before {
  opacity: 0;
  width: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.layout.sidebar-collapsed .sidebar-section-title {
  justify-content: center;
  padding-inline: 0.35rem;
  font-size: 1.05rem;
  line-height: 1;
}

.layout.sidebar-collapsed .sidebar-section-label {
  opacity: 0;
}

.layout.sidebar-collapsed .sidebar-link {
  justify-content: center;
  padding: 0.55rem 0.35rem;
  gap: 0;
}

.layout.sidebar-collapsed .sidebar-link.active {
  border-right: none;
  border-left: 3px solid var(--accent);
}

.layout.sidebar-collapsed .toc-link {
  justify-content: center;
  padding: 0.45rem 0.35rem;
}

@media (min-width: 901px) {
  .sidebar-rail-toggle {
    display: flex;
  }
}

.toc-link:hover {
  color: var(--accent);
  text-decoration: none;
}

.toc-link.active {
  color: var(--accent);
  font-weight: 600;
}

/* Main content */
.main {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 2rem 2.5rem 4rem;
  max-width: min(var(--content-max-width), calc(100vw - var(--sidebar-width) - 2rem));
}

.main.wide {
  max-width: min(var(--content-max-width), calc(100vw - var(--sidebar-width) - 2rem));
}

.main.wide .content {
  width: 100%;
  max-width: none;
}

/* Home page */
.hero {
  margin-bottom: 2.5rem;
}

.hero h1 {
  font-size: 1.65rem;
  margin: 0 0 0.5rem;
  letter-spacing: -0.02em;
}

.hero p {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin: 0;
}

.stats {
  display: flex;
  gap: 1.5rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.stat {
  flex: 1 1 0;
  min-width: 7.5rem;
  min-height: 3.75rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  box-shadow: var(--shadow);
}

.stat strong {
  display: block;
  font-size: 1.4rem;
  color: var(--accent);
}

.stat span {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.category-block {
  margin-bottom: 2.5rem;
}

.role-block {
  margin-bottom: 2.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.role-block:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.role-block-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.role-block-logo,
.role-block-emoji {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.role-block-logo img {
  width: 1.75rem;
  height: 1.75rem;
}

.role-block-emoji {
  font-size: 1.35rem;
  line-height: 1;
}

.role-block-meta h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.role-block-meta p {
  margin: 0 0 0.45rem;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.5;
  max-width: 52rem;
}

.role-block-stats {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
}

.roles-section {
  margin-top: 0.5rem;
}

.role-category-block {
  margin-bottom: 2.5rem;
  scroll-margin-top: 5rem;
}

.role-category-block:last-child {
  margin-bottom: 0;
}

.role-category-title {
  font-size: 1.15rem;
  margin: 0 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  letter-spacing: -0.01em;
}

.roles-section-title {
  font-size: 1.15rem;
  margin: 0 0 1rem;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  align-items: stretch;
}

.role-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 7.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.role-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.12);
  transform: translateY(-1px);
  text-decoration: none;
}

.role-card-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.role-card-logo,
.role-card-emoji {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--radius) - 2px);
  background: var(--bg);
  border: 1px solid var(--border);
}

.role-card-logo img {
  width: 1.35rem;
  height: 1.35rem;
}

.role-card-emoji {
  font-size: 1.15rem;
  line-height: 1;
}

.role-card-header h3 {
  margin: 0;
  font-size: 1rem;
}

.role-card p {
  flex: 1;
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.role-card .count {
  margin-top: auto;
  padding-top: 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
}

.role-page {
  max-width: 56rem;
}

.back-link {
  display: inline-block;
  margin-bottom: 1.25rem;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
}

.back-link:hover {
  color: var(--accent);
  text-decoration: none;
}

.role-page-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.role-page-logo,
.role-page-emoji {
  flex-shrink: 0;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.role-page-logo img {
  width: 2rem;
  height: 2rem;
}

.role-page-emoji {
  font-size: 1.5rem;
  line-height: 1;
}

.role-page-meta h1 {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.role-page-meta p {
  margin: 0 0 0.45rem;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.5;
  max-width: 42rem;
}

.role-page-stats {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
}

.stack-section-title {
  font-size: 1.05rem;
  margin: 0 0 1rem;
}

[data-theme="dark"] .role-card:hover {
  box-shadow: 0 4px 12px rgba(96, 165, 250, 0.15);
}

.category-block h2 {
  font-size: 1.15rem;
  margin: 0 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.category-subheading {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 1.25rem 0 0.75rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.sidebar-subcategory-label {
  margin: 0.55rem 0 0.35rem;
  padding: 0.35rem 0.75rem 0;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  align-items: stretch;
}

.topic-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 7.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.topic-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.12);
  transform: translateY(-1px);
  text-decoration: none;
}

.topic-card-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.topic-card-header img {
  width: 28px;
  height: 28px;
}

.topic-card-header h3 {
  margin: 0;
  font-size: 1rem;
}

.topic-card p {
  flex: 1;
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.topic-card .count {
  margin-top: auto;
  padding-top: 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
}

/* Topic page content */
.content > h1,
.content > h2.page-title,
.content > h2:first-of-type:not(.section-heading) {
  font-size: 1.45rem;
  margin: 0 0 1rem;
  line-height: 1.35;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding: 0;
  border: none;
  background: none;
}

.content > h1 img,
.content > h2.page-title img,
.content > h2:first-of-type:not(.section-heading) img {
  width: 2rem;
  height: 2rem;
  vertical-align: middle;
  margin-right: 0.35rem;
}

.content h1 {
  font-size: 1.45rem;
  margin: 0 0 1rem;
  line-height: 1.35;
}

.content h1 img {
  width: 2rem;
  height: 2rem;
  vertical-align: middle;
  margin-right: 0.35rem;
}

.content details.faq-section {
  margin: 2.5rem 0 0.75rem;
  border: none;
  border-radius: 0;
  overflow: visible;
  background: transparent;
  box-shadow: none;
}

.content details.faq-section > summary.faq-section-summary {
  list-style: none;
  cursor: pointer;
  display: block;
  padding: 0;
  margin: 0 0 0.75rem;
  border: none;
  background: transparent;
  scroll-margin-top: calc(var(--header-height) + 1rem);
  user-select: none;
}

.content details.faq-section > summary.faq-section-summary .faq-section-summary-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0 0.45rem 0.65rem;
  border: none;
  border-left: 3px solid var(--section-color, var(--accent));
  border-bottom: 1px solid var(--section-color, var(--border));
  border-radius: 0;
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--section-color, var(--accent)) 8%, transparent) 0%,
    transparent 72%
  );
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--section-title, var(--section-color, var(--text)));
  letter-spacing: -0.015em;
  transition: background 0.15s ease, border-bottom-color 0.15s ease;
}

.content details.faq-section:not([open]) > summary.faq-section-summary .faq-section-summary-inner {
  border-bottom-color: color-mix(in srgb, var(--section-color, var(--border)) 42%, var(--border));
}

.content details.faq-section[open] > summary.faq-section-summary .faq-section-summary-inner {
  border-bottom-color: color-mix(in srgb, var(--border) 15%, transparent);
}

.content details.faq-section > summary.faq-section-summary .faq-section-summary-text {
  flex: 1;
  min-width: 0;
  line-height: 1.3;
}

.content details.faq-section > summary.faq-section-summary .faq-section-summary-inner::before {
  content: "";
  flex-shrink: 0;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid var(--section-color, var(--text-muted));
  border-bottom: 2px solid var(--section-color, var(--text-muted));
  transform: rotate(-45deg);
  margin-right: 0.15rem;
  transition: transform 0.15s ease;
}

.content details.faq-section[open] > summary.faq-section-summary .faq-section-summary-inner::before {
  transform: rotate(45deg);
  margin-top: -0.15rem;
}

.content details.faq-section > summary.faq-section-summary:hover .faq-section-summary-inner {
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--section-color, var(--accent)) 12%, transparent) 0%,
    transparent 72%
  );
}

.content details.faq-section > summary.faq-section-summary font,
.content details.faq-section > summary.faq-section-summary big,
.content details.faq-section > summary.faq-section-summary strong {
  font-size: inherit;
  font: inherit;
  color: inherit;
}

.content details.faq-section > summary.faq-section-summary::-webkit-details-marker {
  display: none;
}

.content details.faq-section > summary.faq-section-summary::marker {
  content: "";
}

.faq-section-body {
  padding: 0;
}

.faq-section-body > :first-child {
  margin-top: 0;
}

.content h2,
.content h2.section-heading {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 2.75rem 0 1.25rem;
  padding: 0.65rem 1rem;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: var(--panel-header-bg);
  color: var(--text);
  scroll-margin-top: calc(var(--header-height) + 1rem);
  letter-spacing: -0.01em;
}

.content h2.section-heading {
  border-left: none;
}

.content h3 {
  font-size: 1.05rem;
  margin: 1.5rem 0 0.75rem;
}

.content .qa-panel-header .qa-question {
  margin: 0;
  font-size: 1rem;
}

.content p {
  margin: 0.75rem 0;
}

.content ul,
.content ol {
  margin: 0.5rem 0 1rem;
  padding-left: 1.5rem;
}

.content li {
  margin: 0.35rem 0;
}

.content li > p {
  margin: 0.25rem 0;
}

.content strong {
  font-weight: 600;
}

.content code {
  font-family: "SF Mono", SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

.content pre {
  background: var(--pre-bg);
  color: var(--pre-text);
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
  margin: 1rem 0;
  border: 1px solid var(--border);
}

.content pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}

.content th,
.content td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.content th {
  background: var(--code-bg);
  font-weight: 600;
}

.content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.35rem 0 1.25rem;
  height: 0;
}

.content blockquote {
  margin: 1rem 0;
  padding: 0.5rem 1rem;
  border-left: 4px solid var(--accent);
  background: var(--bg);
  color: var(--text-muted);
}

.qa-panel {
  margin-bottom: 0.95rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--panel-shadow);
  overflow: hidden;
  scroll-margin-top: calc(var(--header-height) + 1rem);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.qa-panel:hover {
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow: var(--panel-shadow-hover);
}

.qa-panel-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  background: var(--panel-header-bg);
  border-bottom: 1px solid var(--border);
  min-height: 3rem;
}

.qa-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.65rem;
  height: 1.65rem;
  padding: 0 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(37, 99, 235, 0.2);
  border-radius: 6px;
  box-sizing: border-box;
}

.qa-question {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.65rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.qa-panel-body {
  padding: 0.75rem 1rem 0.9rem;
  background: var(--panel-bg);
}

.qa-panel-body > :first-child {
  margin-top: 0;
}

.qa-panel-body > :last-child {
  margin-bottom: 0;
}

.qa-panel-body ul,
.qa-panel-body ol {
  margin: 0.35rem 0 0.5rem;
  padding-left: 1.25rem;
}

.qa-panel-body li {
  margin: 0.25rem 0;
  padding-left: 0.1rem;
}

.qa-panel-body li::marker {
  color: var(--accent);
}

.qa-panel-body pre {
  margin: 0.5rem 0;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(15, 23, 42, 0.15);
}

.qa-panel-body table {
  display: block;
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.qa-panel-body blockquote {
  margin: 0.75rem 0;
  padding: 0.65rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--panel-accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text);
}

/* Legacy class support */
.qa-block {
  margin-bottom: 1.25rem;
}

.qa-item {
  scroll-margin-top: calc(var(--header-height) + 1rem);
}

.contents-nav {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
  padding: 1rem 1.15rem;
  line-height: 1.8;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.contents-nav strong {
  color: var(--text);
  font-weight: 600;
}

.contents-nav a {
  white-space: nowrap;
}

/* Draggable floating "On this page" menu */
.page-toc-side {
  position: fixed;
  z-index: 85;
  display: flex;
  flex-direction: column;
  width: var(--page-toc-width);
  max-height: calc(100vh - var(--header-height) - 1.5rem);
  overflow-y: auto;
  right: 1rem;
  top: calc(var(--header-height) + 1rem);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.12);
  padding: 0.75rem 0 0;
}

.page-toc-side.is-resized {
  overflow: hidden;
}

.page-toc-side.is-resized .page-toc-links {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.page-toc-header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0 0.85rem 0.65rem;
  margin-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.page-toc-side.is-positioned {
  right: auto;
}

.page-toc-side.is-dragging {
  opacity: 0.96;
  box-shadow: 0 14px 40px rgba(15, 23, 42, 0.2);
  cursor: grabbing;
}

.page-toc-header:active {
  cursor: grabbing;
}

.page-toc-grip {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1;
  letter-spacing: -0.12em;
  opacity: 0.75;
  flex-shrink: 0;
}

.page-toc-title {
  flex: 1;
  min-width: 0;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.page-toc-links {
  display: flex;
  flex-direction: column;
  padding: 0.15rem 0;
  touch-action: pan-y;
}

.page-toc-link {
  display: block;
  padding: 0.38rem 1rem 0.38rem 1.15rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.page-toc-link:hover {
  color: var(--accent);
  background: rgba(37, 99, 235, 0.06);
  text-decoration: none;
}

.page-toc-link.active {
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
  background: rgba(37, 99, 235, 0.08);
}

.page-toc-resize-handle {
  flex-shrink: 0;
  height: 0.85rem;
  margin-top: 0.15rem;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-toc-resize-handle::after {
  content: "";
  width: 2.25rem;
  height: 3px;
  border-radius: 999px;
  background: var(--border);
  transition: background 0.15s, width 0.15s;
}

.page-toc-resize-handle:hover::after,
.page-toc-side.is-resizing .page-toc-resize-handle::after {
  background: var(--accent);
  width: 2.75rem;
}

.page-toc-side.is-resizing {
  opacity: 0.98;
  box-shadow: 0 14px 40px rgba(15, 23, 42, 0.2);
}

@media (min-width: 1101px) {
  .main.wide:has(.page-toc-side) {
    padding-right: calc(var(--page-toc-width) + 2.75rem);
    max-width: min(
      var(--content-max-width),
      calc(100vw - var(--sidebar-width) - var(--page-toc-width) - 3.5rem)
    );
  }
}

@media (max-width: 1100px) {
  .page-toc-side {
    display: none !important;
  }
}

/* Footer */
.site-footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--border);
}

/* Mobile */
@media (max-width: 900px) {
  .menu-toggle {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: -100%;
    top: var(--header-height);
    width: min(var(--sidebar-width), 85vw);
    z-index: 90;
    transition: left 0.2s;
    box-shadow: 4px 0 16px rgba(15, 23, 42, 0.1);
  }

  .sidebar.open {
    left: 0;
  }

  .main {
    padding: 1.25rem 1rem 3rem;
  }

  .topic-grid {
    grid-template-columns: 1fr;
  }

  .site-header .logo {
    font-size: 0.92rem;
  }

  .theme-toggle-btn {
    width: 2.1rem;
    height: 2.1rem;
  }

  .theme-toggle-btn .theme-icon {
    width: 1rem;
    height: 1rem;
  }
}

[data-theme="dark"] {
  --bg: #0c0c0e;
  --bg-elevated: #161618;
  --text: #ededef;
  --text-muted: #a1a1aa;
  --border: #2e2e33;
  --accent: #6ea8fe;
  --accent-hover: #93c5fd;
  --accent-soft: rgba(110, 168, 254, 0.14);
  --panel-accent-soft: rgba(110, 168, 254, 0.08);
  --panel-bg: #1a1a1e;
  --panel-header-bg: #222228;
  --code-bg: #25252b;
  --pre-bg: #121216;
  --pre-text: #e4e4e7;
  --highlight: rgba(250, 204, 21, 0.18);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  --panel-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  --panel-shadow-hover: 0 10px 28px rgba(0, 0, 0, 0.42);
}

[data-theme="dark"] .qa-badge {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(110, 168, 254, 0.28);
}

[data-theme="dark"] .qa-panel:hover {
  border-color: rgba(110, 168, 254, 0.35);
}

[data-theme="dark"] .page-toc-link:hover,
[data-theme="dark"] .page-toc-link.active {
  background: rgba(110, 168, 254, 0.1);
}

[data-theme="dark"] .search-result:hover {
  background: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] #search-input {
  background: var(--bg);
  color: var(--text);
}

[data-theme="dark"] #search-input:focus {
  box-shadow: 0 0 0 3px rgba(110, 168, 254, 0.2);
}

[data-theme="dark"] .sidebar-link.active {
  background: rgba(110, 168, 254, 0.12);
}

[data-theme="dark"] .sidebar-section-label {
  color: var(--text-muted);
}

[data-theme="dark"] mark {
  background: rgba(250, 204, 21, 0.28);
  color: var(--text);
}

[data-theme="dark"] .topic-card:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}
