:root {
  --bg: #0f1214;
  --surface: #171b1e;
  --surface-2: #1f2428;
  --border: #2c3338;
  --text: #e6e9eb;
  --muted: #95a0a8;
  --accent: #c9a24a;
  --accent-ink: #1a1405;
  --link: #8fb8de;
  --ok: #4ade80;
  --ok-bg: #12301f;
  --warn: #fbbf24;
  --warn-bg: #3a2d0c;
  --bad: #f87171;
  --bad-bg: #3b1515;
  --info: #93c5fd;
  --info-bg: #142a45;
  --bar: #c9a24a;
  --bar-2: #6d9ec9;
  --bar-3: #8fbf7a;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f2ee;
    --surface: #ffffff;
    --surface-2: #f0ede7;
    --border: #ddd8cf;
    --text: #1d2125;
    --muted: #5f6a72;
    --accent: #8a6a1f;
    --accent-ink: #ffffff;
    --link: #1f5f99;
    --ok: #15803d;
    --ok-bg: #dcfce7;
    --warn: #a16207;
    --warn-bg: #fef3c7;
    --bad: #b91c1c;
    --bad-bg: #fee2e2;
    --info: #1d4ed8;
    --info-bg: #dbeafe;
    --bar: #8a6a1f;
    --bar-2: #3b78b0;
    --bar-3: #4d7f38;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8rem; }
small, .muted { color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: .9em; }

/* Layout */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand small { font-weight: 600; letter-spacing: .08em; }
.logo { width: 38px; height: 36px; border-radius: 8px; object-fit: cover; flex: none; }
.logo.lg { width: 140px; height: 133px; border-radius: 16px; margin: 0 auto 1rem; display: block; }
.nav { display: flex; gap: .2rem; flex-wrap: wrap; flex: 1 1 auto; min-width: 0; }
.nav a { padding: .4rem .7rem; border-radius: 7px; color: var(--muted); white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.me { display: flex; align-items: center; gap: .5rem; white-space: nowrap; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 1.4rem 16px 3rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.page-head p { margin: 0; }
.grid { display: grid; gap: 1rem; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.tiles { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 1.2rem; }
.stack > * + * { margin-top: 1rem; }
.spaced { margin-top: 1rem; }

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; min-width: 0; }
.card > h2:first-child { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; }
.tile .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.tile .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: .85rem; }
.tile.alert .value { color: var(--warn); }
.tile.bad .value { color: var(--bad); }
.empty { color: var(--muted); padding: .6rem 0; }
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: currentColor; }
.flash.error { background: var(--bad-bg); color: var(--bad); border-color: currentColor; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
.group-row td { background: var(--surface-2); font-weight: 700; font-size: .85rem; letter-spacing: .03em; }

/* Badges and people */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.active, .badge.approved, .badge.accepted, .badge.passed, .badge.actioned { background: var(--ok-bg); color: var(--ok); }
.badge.loa, .badge.pending, .badge.new, .badge.acknowledged { background: var(--info-bg); color: var(--info); }
.badge.inactive, .badge.warning, .badge.incomplete, .badge.stage1 { background: var(--warn-bg); color: var(--warn); }
.badge.discharged, .badge.denied, .badge.strike, .badge.failed, .badge.stage2 { background: var(--bad-bg); color: var(--bad); }
.badge.level { background: var(--accent); color: var(--accent-ink); }
.person { display: inline-flex; align-items: center; gap: .5rem; min-width: 0; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); object-fit: cover; flex: none; }
.avatar.lg { width: 64px; height: 64px; }
.avatar-fallback { display: inline-grid; place-items: center; font-size: .75rem; font-weight: 700; color: var(--muted); }
.avatar-fallback.lg { font-size: 1.4rem; }
.profile-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.profile-head h1 { margin: 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv + h3 { margin-top: 1rem; }

/* Forms */
form.inline { display: inline; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: .5rem .6rem; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field { margin-bottom: .8rem; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 160px; }
.check { display: flex; align-items: center; gap: .4rem; color: var(--text); font-size: .9rem; }
.btn { display: inline-flex; align-items: center; gap: .3rem; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-weight: 600; white-space: nowrap; color: var(--text); }
.btn:hover { text-decoration: none; filter: brightness(1.1); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.good { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.btn.danger { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn.discord { background: #5865f2; color: #fff; border-color: transparent; padding: .7rem 1.2rem; font-size: 1rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.filters input[type=search] { max-width: 280px; }
.pills { display: flex; gap: .3rem; flex-wrap: wrap; }
.pills a { padding: .3rem .7rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); font-size: .85rem; }
.pills a.on { background: var(--surface-2); color: var(--text); border-color: var(--accent); }
details.action { border-top: 1px solid var(--border); padding-top: .6rem; margin-top: .6rem; }
details.action summary { cursor: pointer; font-weight: 600; color: var(--link); }
details.action[open] summary { margin-bottom: .6rem; }

/* Stats */
.meter { display: grid; grid-template-columns: 7.5rem 1fr 4.5rem; gap: .6rem; align-items: center; margin: .35rem 0; font-size: .9rem; }
.meter span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
progress { width: 100%; height: 10px; appearance: none; border: 0; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 99px; }
progress::-webkit-progress-value { background: var(--bar); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--bar); border-radius: 99px; }
progress.met::-webkit-progress-value { background: var(--ok); }
progress.met::-moz-progress-bar { background: var(--ok); }
.chart { width: 100%; height: 150px; display: block; margin-top: .6rem; }
.chart-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; margin-top: .3rem; }
.chart .m { fill: var(--bar); }
.chart .v { fill: var(--bar-2); }
.chart .axis { stroke: var(--border); }
.chart text { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .3rem; vertical-align: -1px; }
.legend .m { background: var(--bar); }
.legend .v { background: var(--bar-2); }
.legend .g { background: var(--bar-3); }
.chart .g { fill: var(--bar-3); }
.link-code { font-family: var(--mono); font-size: 1.6rem; font-weight: 700; letter-spacing: .08em; background: var(--surface-2); border: 1px dashed var(--accent); border-radius: 8px; padding: .5rem .9rem; display: inline-block; }
.rank-bars .meter { grid-template-columns: 9rem 1fr 2.5rem; }

/* Feedback and applications */
.quote { white-space: pre-wrap; background: var(--surface-2); border-radius: 8px; padding: .7rem .9rem; margin: .5rem 0; }
.answer + .answer { margin-top: 1rem; }
.answer h3 { color: var(--muted); font-weight: 600; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .5rem 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }

/* Sign in */
.welcome { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.welcome .card { max-width: 440px; width: 100%; text-align: center; padding: 2rem 1.6rem; }
.welcome ul { text-align: left; color: var(--muted); padding-left: 1.2rem; }

.matrix td.cell { text-align: center; }
.course-form { padding: .8rem 0; border-bottom: 1px solid var(--border); }
.course-form:last-child { border-bottom: 0; padding-bottom: 0; }
#ranks input[type=number] { width: 5.5rem; }
#ranks input[type=text] { min-width: 7rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (max-width: 640px) {
  .me .name { display: none; }
  .meter { grid-template-columns: 6rem 1fr 4rem; }
  h1 { font-size: 1.35rem; }
}
