:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --premium: #f59e0b;
  --oss: #10b981;
  --admin: #c084fc;
  --danger: #f87171;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at top, #172554 0%, var(--bg) 52%);
  color: var(--text);
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 1rem 1.5rem;
  background: rgba(11, 17, 32, 0.9); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.75rem; font-weight: 800; font-size: 1.15rem; }
.brand img { width: 32px; height: 32px; }
.user-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 0.6rem; }

.role-pill {
  padding: 0.3rem 0.7rem; border-radius: 999px; font-size: 0.8rem; font-weight: 700;
  border: 1px solid var(--border); background: var(--surface-2);
}
.role-guest { color: var(--muted); }
.role-reader { color: var(--oss); border-color: rgba(16, 185, 129, 0.5); }
.role-admin { color: var(--admin); border-color: rgba(192, 132, 252, 0.6); }

.btn {
  cursor: pointer; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); padding: 0.48rem 0.95rem; border-radius: 0.55rem;
  font-weight: 600; font-size: 0.88rem; transition: transform 0.12s ease, border-color 0.15s ease;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn-primary { background: #0284c7; border-color: #38bdf8; }
.btn-admin { background: #6b21a8; border-color: var(--admin); }

.container { max-width: 1280px; margin: 0 auto; padding: 1.5rem; }
.search-panel {
  background: rgba(17, 24, 39, 0.86); border: 1px solid var(--border);
  border-radius: 0.9rem; padding: 1rem; margin-bottom: 1.5rem;
}
.search-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.75rem; align-items: end; }
.field label { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.3rem; text-transform: uppercase; letter-spacing: 0.05em; }
.field input, .field select {
  width: 100%; padding: 0.55rem 0.7rem; border-radius: 0.5rem;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 0.9rem;
}

.spaces-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1.15rem; }
.space-card {
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.65), rgba(17, 24, 39, 0.95));
  border: 1px solid var(--border); border-radius: 1rem; overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.space-card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 12px 30px rgba(2, 132, 199, 0.18); }

.card-media {
  position: relative; height: 150px; background: #0f172a; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.card-media img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 1rem; display: flex; flex-direction: column; gap: 0.6rem; flex: 1; }
.card-meta { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; font-size: 0.78rem; }

.pill { padding: 0.2rem 0.55rem; border-radius: 999px; font-weight: 700; font-size: 0.72rem; }
.pill-premium { background: rgba(245, 158, 11, 0.15); color: var(--premium); border: 1px solid rgba(245, 158, 11, 0.45); }
.pill-oss { background: rgba(16, 185, 129, 0.15); color: var(--oss); border: 1px solid rgba(16, 185, 129, 0.45); }
.pill-lock { background: rgba(248, 113, 113, 0.14); color: var(--danger); border: 1px solid rgba(248, 113, 113, 0.45); }

.card-title { margin: 0; font-size: 1.08rem; line-height: 1.3; }
.card-summary { margin: 0; font-size: 0.9rem; color: var(--muted); line-height: 1.45; }
.tags-row { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: auto; }
.tag-chip { font-size: 0.72rem; padding: 0.18rem 0.5rem; border-radius: 0.4rem; background: rgba(56, 189, 248, 0.1); color: var(--accent); }
.admin-note-badge { font-size: 0.75rem; padding: 0.35rem 0.55rem; border-radius: 0.45rem; background: rgba(192, 132, 252, 0.15); border: 1px solid rgba(192, 132, 252, 0.45); color: #e9d5ff; }

.story-article { max-width: 860px; margin: 0 auto; background: rgba(17, 24, 39, 0.92); border: 1px solid var(--border); border-radius: 1rem; padding: 2rem; }
.story-body { white-space: pre-wrap; line-height: 1.72; font-size: 1.02rem; color: #e2e8f0; margin: 1.5rem 0; }
.callout { padding: 1rem 1.2rem; border-radius: 0.75rem; margin: 1.25rem 0; }
.callout-premium { background: rgba(16, 185, 129, 0.12); border: 1px solid rgba(16, 185, 129, 0.45); }
.callout-paywall { background: rgba(245, 158, 11, 0.14); border: 1px solid rgba(245, 158, 11, 0.5); }
.callout-admin { background: rgba(192, 132, 252, 0.14); border: 1px solid rgba(192, 132, 252, 0.5); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 23, 0.75); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modal-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 1rem; padding: 1.5rem; }
.status-banner { margin-bottom: 1rem; padding: 0.75rem 1rem; border-radius: 0.65rem; background: rgba(56, 189, 248, 0.12); border: 1px solid rgba(56, 189, 248, 0.4); font-size: 0.9rem; }

/* === Step 3: Inner Tab Bar, 9-Card Grid, Split AGY Pane & Admin Tables === */
.inner-tabbar {
  display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap;
  padding: 0.6rem 1.5rem; background: rgba(15, 23, 42, 0.92);
  border-bottom: 1px solid var(--border);
}
.inner-tab {
  display: inline-flex; align-items: center; gap: 0.45rem;
  cursor: pointer; padding: 0.4rem 0.85rem; border-radius: 0.55rem;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); font-size: 0.84rem; font-weight: 600;
}
.inner-tab.active {
  background: rgba(56, 189, 248, 0.16); color: var(--text); border-color: var(--accent);
}
.inner-tab.tab-admin.active {
  background: rgba(192, 132, 252, 0.18); border-color: var(--admin);
}
.tab-close {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 0.15rem;
}
.tab-close:hover { color: var(--danger); }

.section-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;
}
.spaces-grid-9 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
@media (max-width: 1024px) {
  .spaces-grid-9 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .spaces-grid-9 { grid-template-columns: 1fr; }
}
.space-card { cursor: pointer; }
.card-footer-row {
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
  font-size: 0.78rem; color: var(--muted);
}
.ext-link { color: var(--accent); font-weight: 600; }
.ext-link:hover { text-decoration: underline; }

.btn-danger { background: rgba(248, 113, 113, 0.18); border-color: var(--danger); color: #fecaca; }
.btn-sm { padding: 0.28rem 0.6rem; font-size: 0.78rem; }

.admin-panel {
  background: rgba(17, 24, 39, 0.9); border: 1px solid var(--border);
  border-radius: 0.95rem; padding: 1.25rem;
}
.admin-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1rem;
}
.inline-editor {
  background: rgba(30, 41, 59, 0.65); border: 1px solid var(--accent);
  border-radius: 0.75rem; padding: 1rem; margin-bottom: 1rem;
}
.code-area {
  width: 100%; padding: 0.65rem; border-radius: 0.55rem;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.84rem;
}
.table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.admin-table th, .admin-table td {
  text-align: left; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--border);
}
.admin-table th { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; }

.agy-split-pane { display: flex; flex-direction: column; gap: 1.15rem; }
.log-list { display: flex; flex-direction: column; gap: 0.75rem; max-height: 440px; overflow-y: auto; }
.log-card { background: var(--bg); border: 1px solid var(--border); border-radius: 0.65rem; padding: 0.75rem; }
.log-head { font-size: 0.8rem; color: var(--accent); font-weight: 700; margin-bottom: 0.45rem; }
.log-body { margin: 0; white-space: pre-wrap; font-size: 0.78rem; color: #cbd5e1; max-height: 180px; overflow-y: auto; }

.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 0.75rem; }
.metric-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 0.75rem;
  padding: 0.85rem; display: flex; flex-direction: column; gap: 0.3rem;
}
.metric-label { font-size: 0.74rem; color: var(--muted); text-transform: uppercase; }
.metric-value { font-size: 1.1rem; color: var(--text); }

/* === Compact High-Density Viewport Layout & Executive Summary Panel === */
.topbar { padding: 0.55rem 1rem; gap: 0.65rem; }
.brand { font-size: 1.02rem; gap: 0.5rem; }
.brand img { width: 26px; height: 26px; }
.btn { padding: 0.36rem 0.75rem; font-size: 0.82rem; }
.btn-xs { padding: 0.22rem 0.55rem; font-size: 0.74rem; }
.inner-tabbar { padding: 0.38rem 1rem; gap: 0.35rem; }
.inner-tab { padding: 0.28rem 0.68rem; font-size: 0.8rem; }
.container { max-width: 1560px; padding: 0.75rem 1rem 1.5rem; }

.section-header-compact {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.65rem;
}
.section-header-left { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.6rem; }
.section-title-compact { margin: 0; font-size: 1.08rem; font-weight: 800; }
.section-hint-compact { color: var(--muted); font-size: 0.78rem; }
.density-controls { display: inline-flex; gap: 0.3rem; align-items: center; }

.spaces-grid-dense {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.7rem;
}
@media (max-width: 1280px) {
  .spaces-grid-dense { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .spaces-grid-dense { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .spaces-grid-dense { grid-template-columns: 1fr; }
}

.space-card-compact { border-radius: 0.75rem; }
.card-body-compact { padding: 0.68rem 0.78rem; gap: 0.38rem; }
.card-date-inline { color: var(--muted); font-size: 0.72rem; margin-left: auto; }
.card-title-compact {
  margin: 0; font-size: 0.93rem; line-height: 1.26; font-weight: 700;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-summary-compact {
  margin: 0; font-size: 0.79rem; color: var(--muted); line-height: 1.36;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-author-trunc {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 58%;
}
.admin-note-compact {
  font-size: 0.69rem; padding: 0.16rem 0.42rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tags-row-compact { gap: 0.25rem; margin-top: 0.15rem; }
.tags-row-compact .tag-chip { font-size: 0.67rem; padding: 0.11rem 0.38rem; }

/* Article Tab: Executive Summary Panel replacing empty 200px void */
.story-article { max-width: 960px; padding: 1.35rem 1.5rem; }
.story-headline { margin: 0.25rem 0 0.4rem; line-height: 1.22; font-size: 1.55rem; }
.story-meta-line { font-size: 0.82rem; color: var(--muted); margin-bottom: 0.9rem; }
.story-summary-box {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.72));
  border: 1px solid rgba(56, 189, 248, 0.42);
  border-radius: 0.8rem;
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}
.story-summary-header {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.55rem;
}
.summary-kicker {
  font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--accent);
}
.story-summary-lead {
  margin: 0 0 0.8rem; font-size: 0.98rem; line-height: 1.58; color: #f1f5f9;
}
.story-summary-facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.5rem; padding-top: 0.65rem; border-top: 1px solid rgba(51, 65, 85, 0.75);
}
.summary-fact { display: flex; flex-direction: column; gap: 0.12rem; }
.summary-fact-label { font-size: 0.68rem; text-transform: uppercase; color: var(--muted); }
.summary-fact-val { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.story-summary-bench { margin-top: 0.8rem; padding-top: 0.7rem; border-top: 1px solid rgba(51, 65, 85, 0.6); }

/* HTML/CSS Benchmark Bars */
.bench-chart { display: flex; flex-direction: column; gap: 0.4rem; }
.bench-caption { font-size: 0.74rem; color: var(--muted); font-weight: 600; }
.bench-rows { display: flex; flex-direction: column; gap: 0.35rem; }
.bench-row { display: grid; grid-template-columns: 110px 1fr 44px; align-items: center; gap: 0.55rem; }
.bench-label { font-size: 0.76rem; color: #cbd5e1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bench-track { height: 10px; background: #0f172a; border-radius: 999px; overflow: hidden; border: 1px solid #1e293b; }
.bench-fill { height: 100%; border-radius: 999px; }
.bench-fill-a { background: #38bdf8; }
.bench-fill-b { background: #10b981; }
.bench-fill-c { background: #f59e0b; }
.bench-score { font-size: 0.75rem; font-weight: 700; text-align: right; color: var(--text); }
.story-inline-photo { max-width: 100%; max-height: 220px; border-radius: 0.55rem; object-fit: cover; }
.story-body { margin: 0.9rem 0; font-size: 0.95rem; line-height: 1.65; }

/* === Heart Like Button & Counter on Every Article === */
.card-actions-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.like-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.16rem 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(244, 63, 94, 0.38);
  background: rgba(244, 63, 94, 0.1);
  color: #fda4af;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}
.like-btn:hover {
  background: rgba(244, 63, 94, 0.22);
  border-color: #f43f5e;
  transform: scale(1.04);
}
.like-btn.liked {
  background: rgba(244, 63, 94, 0.26);
  border-color: #fb7185;
  color: #ffe4e6;
}
.heart-icon {
  color: #f43f5e;
  font-size: 0.85rem;
  line-height: 1;
}

/* === Strict CSP (style-src 'self') Layout & Component Utilities === */
.is-hidden { display: none !important; }
.tab-pane { display: block; }
.u-m0 { margin: 0; }
.u-mt-0 { margin-top: 0; }
.u-mt-xs { margin: 0.35rem 0 0; }
.u-mt-sm { margin-top: 0.8rem; }
.u-mt-md { margin-top: 1rem; }
.u-mt-lg { margin-top: 1.25rem; }
.u-mb-xs { margin-bottom: 0.6rem; }
.u-mb-sm { margin-bottom: 0.85rem; }
.u-mb-md { margin-bottom: 1rem; }
.u-mb-lg { margin-bottom: 1.25rem; }
.u-my-sm { margin: 0.75rem 0; }
.u-my-md { margin: 1rem 0; }
.u-p-lg { padding: 1.5rem; }
.u-p-xl { padding: 2rem; }
.u-center { text-align: center; }
.u-w-full { width: 100%; justify-content: center; text-align: center; }
.u-auto-w { width: auto; }
.u-flex-1 { flex: 1; }
.u-row-gap { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.u-row-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.u-row-end { display: flex; justify-content: flex-end; gap: 0.5rem; }
.u-col-gap { display: flex; flex-direction: column; gap: 0.65rem; }
.u-nowrap-actions { white-space: nowrap; display: flex; gap: 0.35rem; }
.u-narrow-520 { max-width: 520px; margin: 1rem auto; }
.u-narrow-580 { max-width: 580px; margin: 2rem auto; }
.u-narrow-640 { max-width: 640px; margin: 1rem auto; }
.u-muted { color: #94a3b8; }
.u-muted-sm { color: #94a3b8; font-size: 0.88rem; }
.u-body-text { color: #e2e8f0; line-height: 1.55; }
.u-sub-text { color: #cbd5e1; font-size: 0.88rem; }
.u-text-sm { font-size: 0.86rem; }
.u-list-muted { color: #94a3b8; line-height: 1.8; padding-left: 1.2rem; }
.u-ok-text { color: #38bdf8; }
.u-err-text { color: #f87171; font-size: 0.85rem; }
.u-err-headline { color: #f87171; }
.u-section-h3 { margin: 1.25rem 0 0.5rem; }
.u-card-subpanel { border: 1px solid #334155; border-radius: 8px; padding: 0.85rem; margin-bottom: 0.75rem; background: rgba(15, 23, 42, 0.7); }
.u-check-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.86rem; color: #cbd5e1; margin-bottom: 0.7rem; cursor: pointer; }
.u-btn-cta { width: 100%; font-size: 0.96rem; padding: 0.7rem 1rem; justify-content: center; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 23, 0.78); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 9999; padding: 1rem; }
.modal-card { max-width: 500px; width: 100%; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65); padding: 1.5rem; }
.modal-card-ok { border: 1px solid #38bdf8; }
.modal-card-err { border: 1px solid #f87171; }
.bench-progress { width: 100%; height: 10px; border: 0; border-radius: 999px; background: #1e293b; overflow: hidden; appearance: none; }
.bench-progress::-webkit-progress-bar { background: #1e293b; border-radius: 999px; }
.bench-progress-a::-webkit-progress-value { background: #38bdf8; border-radius: 999px; }
.bench-progress-b::-webkit-progress-value { background: #a78bfa; border-radius: 999px; }
.bench-progress-c::-webkit-progress-value { background: #34d399; border-radius: 999px; }
.bench-progress-a::-moz-progress-bar { background: #38bdf8; border-radius: 999px; }
.bench-progress-b::-moz-progress-bar { background: #a78bfa; border-radius: 999px; }
.bench-progress-c::-moz-progress-bar { background: #34d399; border-radius: 999px; }
