:root {
  --ink: #17242c;
  --muted: #5d6b73;
  --navy: #102433;
  --navy-2: #1b3442;
  --paper: #f3f0e8;
  --card: #fffcf7;
  --line: #e4daca;
  --teal: #1f7a72;
  --teal-soft: #e7f3f1;
  --gold: #a97820;
  --gold-soft: #f8f1e4;
  --good: #1d7a4e;
  --good-soft: #e5f5ec;
  --warn: #8a5a10;
  --warn-soft: #fbf3e2;
  --bad: #9c3b32;
  --bad-soft: #fbeceb;
  --info: #1d5f8a;
  --info-soft: #e7f1f8;
  --shadow: 0 16px 40px rgba(16, 36, 51, 0.08);
  --serif: Newsreader, Georgia, serif;
  --sans: Outfit, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
img { max-width: 100%; display: block; }
button { cursor: pointer; }

.icon { display: inline-flex; width: 20px; height: 20px; }
.icon svg { width: 20px; height: 20px; }

.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--navy);
  color: #f6f1e6;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand, .brand-lockup {
  display: flex;
  gap: 12px;
  align-items: center;
  text-decoration: none;
}
.brand img, .brand-lockup img { width: 42px; height: 42px; }
.brand strong, .display { font-family: var(--serif); font-weight: 650; letter-spacing: -0.03em; }
.brand small, .eyebrow {
  display: block;
  color: #c9b89a;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar a, .text-link {
  text-decoration: none;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #d9e2e6;
}
.sidebar nav a.active, .sidebar nav a:hover { background: rgba(255, 255, 255, 0.08); color: white; }
.side-foot { margin-top: auto; padding: 12px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 13px; color: #c9d5db; }
.side-foot strong { display: block; color: white; }

.main { min-width: 0; }
.content, .card, .table-wrap, .section-head { min-width: 0; max-width: 100%; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 252, 247, 0.86);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(10px);
}
.topbar h1 { margin: 0; font-size: 26px; font-family: var(--serif); font-weight: 650; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.top-actions, .row-actions, .filters, .cluster { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.content { padding: 28px; display: grid; gap: 18px; }

.kpis, .split, .card-grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.split { grid-template-columns: 1.4fr 0.8fr; }
.split.even { grid-template-columns: 1fr 1fr; }
.card-grid { grid-template-columns: repeat(3, 1fr); }

.card, .reward, .entry-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.card { padding: 18px; }
.card:has(table) { overflow-x: auto; }
.card h2, .card h3 { margin: 0 0 8px; font-size: 18px; }
.muted { color: var(--muted); }
.kpi strong { display: block; margin-top: 8px; font-size: 30px; font-family: var(--serif); }
.kpi span { color: var(--muted); font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; }
.gold { color: var(--gold); }

.note {
  background: var(--gold-soft);
  border: 1px solid #ead7ae;
  border-radius: 14px;
  padding: 14px 16px;
  color: #5c4516;
}
.note strong { color: var(--ink); }

.table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #faf7f1; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--bad); }
.pos { color: var(--good); }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.tone-good { background: var(--good-soft); color: var(--good); }
.tone-warn { background: var(--warn-soft); color: var(--warn); }
.tone-bad { background: var(--bad-soft); color: var(--bad); }
.tone-info { background: var(--info-soft); color: var(--info); }
.tone-neutral { background: #eef1f2; color: #44545d; }
.tone-gold { background: var(--gold-soft); color: #7a5410; }

.btn, .btn-ghost, .btn-danger {
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 9px 14px;
  background: var(--navy);
  color: white;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn:hover { background: var(--navy-2); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: white; }
.btn-danger { background: var(--bad); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.btn.small, .btn-ghost.small { padding: 6px 10px; font-size: 13px; }

.field { display: grid; gap: 6px; font-size: 14px; }
.field.grow { flex: 1; min-width: 180px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 12px;
  padding: 10px 12px;
}
textarea { min-height: 90px; resize: vertical; }
.checks { display: flex; gap: 12px; flex-wrap: wrap; }
.checks label { display: flex; gap: 6px; align-items: center; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }

.reward { overflow: hidden; display: flex; flex-direction: column; }
.reward img { height: 132px; width: 100%; object-fit: cover; }
.reward .body, .entry-card { padding: 16px; }
.reward h3 { margin: 8px 0; font-size: 20px; font-family: var(--serif); }
.price { font-size: 22px; font-family: var(--serif); color: var(--gold); }
.meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }

.modal-back, .drawer-back {
  position: fixed;
  inset: 0;
  background: rgba(16, 36, 51, 0.46);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 20;
}
.modal, .drawer {
  background: var(--card);
  border-radius: 20px;
  width: min(760px, 100%);
  max-height: min(860px, calc(100vh - 48px));
  overflow: auto;
  padding: 22px;
  box-shadow: var(--shadow);
}
.drawer-back { justify-content: end; }
.drawer { width: min(560px, 100%); height: 100%; max-height: none; border-radius: 0; }
.modal-head, .section-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.catalog-list { display: grid; gap: 12px; }
.catalog-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px 18px; align-items: start; }
.catalog-item h3 { margin: 0 0 6px; font-size: 18px; }
.modal-head h2, .section-head h2 { margin: 0; font-family: var(--serif); }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--navy);
  color: white;
  padding: 14px 16px;
  border-radius: 14px;
  z-index: 30;
  box-shadow: var(--shadow);
}

.home { min-height: 100vh; }
.home-bar, .hero, .home-section { width: min(1120px, calc(100% - 40px)); margin: 0 auto; }
.home-bar { display: flex; justify-content: space-between; align-items: center; padding: 22px 0; }
.hero { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 32px; align-items: center; padding-bottom: 28px; }
.hero h1 { font-family: var(--serif); font-size: 62px; line-height: 0.95; margin: 8px 0 12px; letter-spacing: -0.04em; }
.lead { font-size: 18px; color: var(--muted); max-width: 58ch; }
.entry-grid, .principle-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.entry-card h2 { margin: 8px 0; font-family: var(--serif); font-size: 32px; }
.institution-list { display: grid; gap: 8px; margin-top: 14px; }
.institution-list a {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f7f4ee;
}
.institution-list a:hover { background: var(--teal-soft); }
.home-section { padding: 10px 0 48px; }
.principle { padding: 16px; border-top: 3px solid var(--gold); background: white; border-radius: 16px; }

.chart-box { position: relative; height: 280px; }
.person { display: flex; gap: 12px; align-items: center; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--navy); color: #f6f1e6; font-weight: 650;
}
.stack { display: grid; gap: 10px; }
.formula {
  font-family: ui-monospace, "Cascadia Code", monospace;
  background: var(--navy);
  color: #f6f1e6;
  border-radius: 12px;
  padding: 12px 14px;
  overflow-wrap: anywhere;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sidebar-head .brand { min-width: 0; }
.nav-toggle {
  display: none;
  background: transparent;
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 10px;
  padding: 8px;
}
.top-title { min-width: 0; flex: 1; }
.top-aside { display: none; min-width: 0; }
.topbar h1, .topbar p { overflow-wrap: anywhere; }
.mono, .token-secret { font-family: ui-monospace, "Cascadia Code", monospace; }
.token-secret {
  background: #f7f4ee;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 8px 0;
  overflow-wrap: anywhere;
}
.token-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: start; }
.token-reveal .token-secret { background: var(--navy); color: #f6f1e6; }

@media (max-width: 1100px) {
  .kpis, .card-grid { grid-template-columns: 1fr 1fr; }
  .split, .split.even { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 8; padding: 12px 16px; gap: 0; }
  .nav-toggle { display: inline-flex; }
  .sidebar nav { display: none; }
  .shell.nav-open .sidebar nav {
    display: flex;
    flex-direction: column;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    background: var(--navy);
    padding: 8px 16px 16px;
    box-shadow: var(--shadow);
    max-height: calc(100vh - 72px);
    overflow: auto;
  }
  .side-foot { display: none; }
  .topbar { flex-direction: column; align-items: stretch; }
  .top-aside { display: block; width: 100%; }
  .catalog-item, .token-card { grid-template-columns: 1fr; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
  .hero, .entry-grid, .principle-grid, .form-grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 44px; }
}

@media (max-width: 720px) {
  .kpis, .card-grid { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 22px; }
  .content { padding: 16px; }
  .kpi strong { font-size: 26px; }
  .filters, .cluster { align-items: stretch; }
  .filters .field, .filters .field.grow, .filters .btn, .cluster .btn { width: 100%; }
  .chart-box { height: 220px; }
  .modal-back, .drawer-back { padding: 0; }
  .drawer, .modal { width: 100%; max-height: 100vh; border-radius: 0; }
  .toast { left: 12px; right: 12px; bottom: 12px; }
  .person { align-items: flex-start; }
}
