/* Castle Money Capital — castle library / royal treasury theme */
:root {
  --bg: #0b1322;
  --bg-deep: #070d18;
  --panel: #111d33;
  --panel-2: #16253f;
  --panel-3: #1c2e4d;
  --line: rgba(201, 168, 92, 0.22);
  --line-soft: rgba(233, 228, 214, 0.08);
  --gold: #c9a85c;
  --gold-bright: #e4c886;
  --gold-deep: #8a6d2f;
  --parchment: #efe4c8;
  --parchment-ink: #2b2417;
  --forest: #1f4d3a;
  --forest-bright: #2f6b4f;
  --text: #ebe6d8;
  --muted: #a9ad9f;
  --gain: #7fd3a1;
  --loss: #f19a8c;
  --warn: #e8c46a;
  --info: #9ec3e6;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 10px 30px rgba(0, 0, 0, 0.35);
  --serif: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 15% -10%, rgba(31, 77, 58, 0.35), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, rgba(201, 168, 92, 0.08), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--sans);
  display: flex;
  flex-direction: column;
}
a { color: var(--gold-bright); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--parchment); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: 0.01em; margin: 0; color: var(--parchment); }
h1 { font-size: clamp(2rem, 4.5vw, 2.9rem); line-height: 1.1; }
h2 { font-size: 1.55rem; line-height: 1.2; }
h3 { font-size: 1.2rem; }
p { margin: 0; }
.num, td.n, th.n, .stat-value { font-variant-numeric: tabular-nums lining-nums; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 8px; z-index: 50; background: var(--gold); color: var(--bg); padding: 6px 10px; border-radius: 4px; }
:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(7, 13, 24, 0.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--gold); margin-right: auto; }
.crest { width: 34px; height: 34px; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { font-family: var(--serif); font-size: 1.3rem; font-weight: 700; color: var(--parchment); }
.brand-sub { font-size: 0.68rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--gold); }
.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a { color: var(--muted); text-decoration: none; padding: 7px 10px; border-radius: var(--radius-sm); font-size: 0.86rem; white-space: nowrap; }
.nav a:hover { color: var(--parchment); background: var(--panel); }
.nav a[aria-current='page'] { color: var(--gold-bright); background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--gold); }
.menu-btn { display: none; }

@media (max-width: 900px) {
  .menu-btn { display: inline-flex; background: var(--panel-2); color: var(--parchment); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 12px; font: 500 0.9rem var(--sans); }
  .nav { display: none; width: 100%; flex-direction: column; padding-bottom: 6px; }
  .nav.open { display: flex; }
  .nav a { padding: 11px 12px; font-size: 0.95rem; }
}

/* ---------- layout ---------- */
.main { flex: 1; width: 100%; max-width: 1240px; margin: 0 auto; padding: 28px 16px 48px; outline: none; }
.footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 0.82rem; padding: 18px 16px 28px; text-align: center; display: grid; gap: 6px; }
.stack { display: grid; gap: 14px; }
.stack-lg { display: grid; gap: 28px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.row-end { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.grid-2 { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid-cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
.grid-stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); }

.page-head { display: grid; gap: 6px; margin-bottom: 4px; }
.eyebrow { font-size: 0.72rem; letter-spacing: 0.24em; text-transform: uppercase; color: var(--gold); font-weight: 600; }
.lede { color: var(--muted); max-width: 70ch; }

.panel { background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.panel-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-title h2 { font-size: 1.35rem; }
.rule { height: 1px; background: linear-gradient(90deg, transparent, var(--line), transparent); border: 0; margin: 4px 0; }

/* ---------- stats ---------- */
.stat { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 4px; min-width: 0; }
.stat-label { font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.stat-value { font-size: 1.45rem; font-weight: 600; color: var(--parchment); overflow-wrap: break-word; }
.stat-value > span, .kcard-return > span { white-space: nowrap; }
.stat-sub { font-size: 0.82rem; color: var(--muted); }
.stat.highlight { border-color: var(--line); background: linear-gradient(160deg, rgba(31, 77, 58, 0.45), var(--panel)); }

/* ---------- kingdom cards ---------- */
.kcard { display: grid; gap: 12px; text-decoration: none; color: inherit; background: linear-gradient(170deg, var(--panel-3), var(--panel)); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; position: relative; transition: border-color 0.15s, transform 0.15s; min-width: 0; }
.kcard:hover { border-color: var(--gold); transform: translateY(-1px); color: inherit; }
.kcard-head { display: flex; gap: 12px; align-items: center; min-width: 0; }
.kcard-head > div { min-width: 0; }
.kcard-icon { font-size: 1.6rem; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%; background: rgba(201, 168, 92, 0.1); border: 1px solid var(--line); flex: none; }
.kcard-name { font-family: var(--serif); font-size: 1.35rem; font-weight: 600; color: var(--parchment); line-height: 1.15; }
.kcard-rows { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 0.9rem; }
.kcard-rows dt { color: var(--muted); }
.kcard-rows dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.kcard-return { font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.crown { position: absolute; top: -12px; right: 14px; background: var(--gold); color: var(--bg-deep); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; padding: 4px 10px 4px 8px; border-radius: 999px; display: inline-flex; gap: 5px; align-items: center; box-shadow: 0 4px 14px rgba(201, 168, 92, 0.35); }
.crown svg { width: 15px; height: 15px; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; line-height: 1.5; }
.badge.current { color: var(--gain); }
.badge.stale { color: var(--warn); }
.badge.missing { color: var(--loss); }
.badge.manual { color: var(--info); }
.badge.planned { color: var(--warn); }
.badge.active { color: var(--gain); }
.badge.gold { color: var(--gold-bright); }
.badge.neutral { color: var(--muted); }

/* ---------- notices ---------- */
.notice { border: 1px solid var(--line); border-left: 4px solid var(--gold); background: rgba(201, 168, 92, 0.07); padding: 12px 14px; border-radius: var(--radius-sm); display: grid; gap: 4px; }
.notice.warn { border-left-color: var(--warn); background: rgba(232, 196, 106, 0.08); }
.notice.error { border-left-color: var(--loss); background: rgba(241, 154, 140, 0.08); }
.notice.ok { border-left-color: var(--gain); background: rgba(127, 211, 161, 0.07); }
.parchment { background: var(--parchment); color: var(--parchment-ink); border-radius: var(--radius); padding: 18px 20px; border: 1px solid #d8c9a3; }
.parchment h3 { color: var(--parchment-ink); }
.parchment a { color: #6b4f14; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th { font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold); font-weight: 600; background: rgba(7, 13, 24, 0.5); white-space: nowrap; }
td.n, th.n { text-align: right; white-space: nowrap; }
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
tbody tr:last-child td { border-bottom: 0; }
tr.total td { font-weight: 600; border-top: 1px solid var(--line); }
td .sub { display: block; font-size: 0.78rem; color: var(--muted); }
.sym { font-weight: 600; color: var(--gold-bright); text-decoration: none; letter-spacing: 0.02em; }

/* ---------- forms ---------- */
label { display: grid; gap: 5px; font-size: 0.82rem; color: var(--muted); font-weight: 500; }
input, select, textarea { font: 15px/1.4 var(--sans); color: var(--text); background: var(--bg-deep); border: 1px solid rgba(233, 228, 214, 0.18); border-radius: var(--radius-sm); padding: 9px 11px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); outline: none; box-shadow: 0 0 0 3px rgba(201, 168, 92, 0.18); }
textarea { min-height: 90px; resize: vertical; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
.form-error { color: var(--loss); font-size: 0.88rem; }
.hint { font-size: 0.8rem; color: var(--muted); }
fieldset { border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 12px; margin: 0; }
legend { padding: 0 6px; color: var(--gold); font-size: 0.8rem; }
.radio-row { display: flex; gap: 16px; flex-wrap: wrap; }
.radio-row label { display: inline-flex; flex-direction: row; gap: 6px; align-items: center; color: var(--text); }
.radio-row input { width: auto; }
.price-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr)); }
.price-cell { display: grid; gap: 4px; background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 10px; }
.price-cell .ps { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }

.btn { font: 600 0.9rem var(--sans); border-radius: var(--radius-sm); padding: 9px 16px; border: 1px solid var(--line); background: var(--panel-3); color: var(--parchment); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; min-height: 40px; }
.btn:hover { border-color: var(--gold); color: var(--parchment); }
.btn.gold { background: linear-gradient(180deg, var(--gold-bright), var(--gold)); color: var(--bg-deep); border-color: var(--gold); }
.btn.gold:hover { filter: brightness(1.06); color: var(--bg-deep); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--loss); border-color: rgba(241, 154, 140, 0.4); background: transparent; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- charts ---------- */
.chart-box { position: relative; height: 320px; }
.chart-box.tall { height: 380px; }
@media (max-width: 600px) { .chart-box, .chart-box.tall { height: 260px; } }
.empty { display: grid; place-items: center; text-align: center; gap: 6px; min-height: 180px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); padding: 20px; }
.empty strong { color: var(--parchment); font-family: var(--serif); font-size: 1.2rem; font-weight: 600; }

/* ---------- leaderboard ---------- */
.lb { display: grid; gap: 8px; list-style: none; margin: 0; padding: 0; }
.lb-row { display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--panel); border: 1px solid var(--line-soft); text-decoration: none; color: inherit; }
.lb-row:hover { border-color: var(--line); color: inherit; }
.lb-row.first { border-color: var(--gold); background: linear-gradient(90deg, rgba(201, 168, 92, 0.16), var(--panel)); }
.lb-rank { font-family: var(--serif); font-size: 1.35rem; font-weight: 700; color: var(--gold); text-align: center; }
.lb-crown { display: inline-grid; place-items: center; color: var(--gold-bright); }
.lb-crown svg { width: 24px; height: 24px; }
.lb-name { font-weight: 600; }
.lb-val { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- misc ---------- */
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 40px 0; justify-content: center; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } .kcard { transition: none; } }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--panel-3); border: 1px solid var(--gold); color: var(--parchment); padding: 10px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow); z-index: 60; max-width: calc(100vw - 32px); }
.toast.error { border-color: var(--loss); }
.dialog { background: var(--panel-2); color: var(--text); border: 1px solid var(--gold); border-radius: var(--radius); padding: 22px; width: min(420px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(3, 6, 12, 0.7); }
.note-card { background: var(--panel); border: 1px solid var(--line-soft); border-left: 3px solid var(--forest-bright); border-radius: var(--radius-sm); padding: 12px 14px; display: grid; gap: 6px; }
.note-card .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 0.92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.checklist { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.checklist li { display: flex; gap: 8px; align-items: baseline; }
.big-icon { font-size: 2.2rem; }
.hidden { display: none !important; }
