/* ==========================================================================
   KEHQ theme
   --------------------------------------------------------------------------
   PALETTE: the only block to edit when changing the look. Two brand accents:
     --kinetic (electric cyan): you, your data, navigation, selection
     --energy  (molten gold):   wins, leaders, primary actions
   Neutrals are warm graphite (machined metal), deliberately NOT blue.
   Values are OKLCH: lightness (0-1), chroma (colorfulness), hue (degrees).
   To shift a color, change its hue; to mute it, lower the chroma.
   ========================================================================== */
:root {
  /* Surfaces, darkest to lightest */
  --ink-0: oklch(0.145 0.006 70);    /* page background */
  --ink-1: oklch(0.172 0.007 70);    /* sidebar / tab bar */
  --ink-2: oklch(0.195 0.008 70);    /* panels */
  --ink-3: oklch(0.235 0.009 70);    /* hover, inputs */
  --line: oklch(0.31 0.010 70);      /* borders */
  --line-soft: oklch(0.255 0.008 70);

  /* Text */
  --text: oklch(0.94 0.006 80);
  --text-dim: oklch(0.72 0.012 75);
  --text-faint: oklch(0.58 0.012 75);

  /* Brand accents */
  --kinetic: oklch(0.84 0.13 200);   /* electric cyan */
  --energy: oklch(0.84 0.145 82);    /* molten gold */

  /* Status (never gold, so warnings can't be mistaken for wins) */
  --good: oklch(0.80 0.15 155);
  --alert: oklch(0.72 0.165 32);

  /* Text on a filled gold/cyan button */
  --on-accent: oklch(0.2 0.02 75);
  /* ---------------------------------------------------------------------- */

  --kinetic-wash: oklch(from var(--kinetic) l c h / 0.12);
  --energy-wash: oklch(from var(--energy) l c h / 0.12);
  --alert-wash: oklch(from var(--alert) l c h / 0.12);
  --radius: 6px;
  --rail-w: 232px;
  color-scheme: dark;   /* native controls (date pickers, checkboxes) match */
}

* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100vh;
  background-color: var(--ink-0);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
/* Circuit traces: a faint TRON-like wire layer behind everything. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240' fill='none' stroke-width='1'%3E%3Cg stroke='%2340d4e6' stroke-opacity='.13'%3E%3Cpath d='M0 42h64l22 22h70'/%3E%3Cpath d='M22 240v-58l24-24v-44'/%3E%3Cpath d='M120 0v26l20 20h100'/%3E%3C/g%3E%3Cg stroke='%23e3b04b' stroke-opacity='.12'%3E%3Cpath d='M240 132h-46l-24 24v84'/%3E%3Cpath d='M0 196h38l18-18h40'/%3E%3C/g%3E%3Cg fill='%2340d4e6' fill-opacity='.28'%3E%3Ccircle cx='156' cy='64' r='2.2'/%3E%3Ccircle cx='46' cy='114' r='2.2'/%3E%3C/g%3E%3Cg fill='%23e3b04b' fill-opacity='.26'%3E%3Ccircle cx='96' cy='178' r='2.2'/%3E%3Ccircle cx='170' cy='156' r='2.2'/%3E%3C/g%3E%3C/svg%3E");
  -webkit-mask-image: radial-gradient(ellipse 110% 85% at 75% 0%, #000 0%, transparent 80%);
          mask-image: radial-gradient(ellipse 110% 85% at 75% 0%, #000 0%, transparent 80%);
}
a { color: var(--kinetic); text-underline-offset: 3px; }
a:hover { color: var(--text); }
:focus-visible { outline: 2px solid var(--kinetic); outline-offset: 2px; border-radius: 3px; }

/* ---------- Wordmark ---------- */
.wordmark { display: inline-flex; align-items: baseline; gap: .45em; text-decoration: none;
  font-weight: 800; letter-spacing: .16em; text-transform: uppercase; line-height: 1; }
.wordmark .k { color: var(--kinetic); }
.wordmark .e { color: var(--energy); }
.wordmark .hq { font-size: .62em; letter-spacing: .1em; color: var(--text-faint); font-weight: 700;
  border: 1px solid var(--line); border-radius: 3px; padding: .15em .35em; align-self: center; }

/* ---------- Standalone pages (login, members-only) ---------- */
main.center { min-height: 100vh; display: grid; place-content: center; text-align: center;
  max-width: 30rem; margin: 0 auto; padding: 24px 16px; }
.gate-mark { font-size: clamp(1.7rem, 7vw, 2.6rem); }
.gate-sub { color: var(--text-dim); font-size: .8rem; letter-spacing: .32em; text-transform: uppercase; margin-top: 1.1rem; }
.trace { display: flex; align-items: center; gap: 0; margin: 1.6rem auto; width: min(18rem, 80%); }
.trace::before, .trace::after { content: ""; height: 1px; flex: 1; }
.trace::before { background: linear-gradient(90deg, transparent, var(--kinetic)); }
.trace::after { background: linear-gradient(90deg, var(--energy), transparent); }
.trace span { width: 7px; height: 7px; border-radius: 50%; border: 1px solid var(--text-dim); margin: 0 6px; }
main.center p { color: var(--text-dim); margin-bottom: 1.6rem; }
main.center h1 { font-size: 1.6rem; margin-bottom: .2rem; }
.note { color: var(--text) !important; }

/* ---------- App shell: sidebar (desktop) + tab bar (phone) ---------- */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100vh; }
.rail { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--ink-1); border-right: 1px solid var(--line-soft); padding: 22px 14px 16px; }
.rail .wordmark { font-size: .95rem; padding: 0 8px 22px; }
.navgroup { margin-bottom: 18px; }
.navgroup-label { font-size: .68rem; font-weight: 700; letter-spacing: .22em; text-transform: uppercase;
  color: var(--text-faint); padding: 0 10px 6px; }
.navlink { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius);
  color: var(--text-dim); text-decoration: none; font-size: .93rem; transition: background-color .15s ease-out, color .15s ease-out; }
.navlink::before { content: ""; width: 6px; height: 6px; border-radius: 50%; border: 1px solid var(--line); flex: none;
  transition: background-color .15s ease-out, border-color .15s ease-out, box-shadow .15s ease-out; }
.navlink:hover { background: var(--ink-3); color: var(--text); }
.navlink.active { background: var(--kinetic-wash); color: var(--text); }
.navlink.active::before { background: var(--kinetic); border-color: var(--kinetic); box-shadow: 0 0 8px var(--kinetic); }
.rail-foot { margin-top: auto; border-top: 1px solid var(--line-soft); padding: 14px 10px 0; display: grid; gap: 10px; }
.who { font-size: .85rem; color: var(--text-dim); line-height: 1.3; overflow-wrap: anywhere; }
.who strong { color: var(--text); display: block; font-weight: 600; }

.stage { min-width: 0; padding: 32px clamp(16px, 4vw, 44px) 48px; }
.stage-inner { max-width: 60rem; }
.stage.wide .stage-inner { max-width: 90rem; }

.topbar, .tabbar { display: none; }

@media (max-width: 899px) {
  .shell { display: block; }
  .rail { display: none; }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: sticky; top: 0; z-index: 5; padding: 12px 16px;
    background: oklch(from var(--ink-1) l c h / 0.94); border-bottom: 1px solid var(--line-soft); }
  .topbar .wordmark { font-size: .82rem; }
  .stage { padding: 20px 16px calc(84px + env(safe-area-inset-bottom)); }
  .tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    background: var(--ink-1); border-top: 1px solid var(--line-soft); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
  .tab { display: grid; justify-items: center; gap: 4px; padding: 6px 2px; color: var(--text-dim);
    text-decoration: none; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; border-radius: var(--radius); }
  .tab::before { content: ""; width: 18px; height: 2px; border-radius: 2px; background: var(--line); }
  .tab.active { color: var(--text); }
  .tab.active::before { background: var(--kinetic); box-shadow: 0 0 8px var(--kinetic); }
}

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; margin-bottom: 22px; }
.page-title { font-size: 1.55rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.2; }
.page-sub { color: var(--text-dim); font-size: .9rem; margin-top: 2px; }
.eyebrow { font-size: .7rem; font-weight: 700; letter-spacing: .22em; text-transform: uppercase; color: var(--energy); }

/* ---------- Panels ("machined": thin edge, faint top highlight) ---------- */
.card { position: relative; background: linear-gradient(180deg, var(--ink-2), oklch(from var(--ink-2) calc(l - 0.012) c h));
  border: 1px solid var(--line-soft); border-radius: var(--radius);
  box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.045); padding: 20px; margin-bottom: 16px; }
/* Section label with a trace running off to the right, ending in a node. */
.card-label { display: flex; align-items: center; gap: 10px; font-size: .7rem; font-weight: 700;
  letter-spacing: .22em; text-transform: uppercase; color: var(--text-dim); margin-bottom: .75rem; }
.card-label::after { content: ""; flex: 1; height: 1px; min-width: 24px;
  background: linear-gradient(90deg, var(--line), transparent 85%); }
.card-name { font-size: 1.6rem; font-weight: 700; margin: -.2rem 0 1rem; overflow-wrap: anywhere; letter-spacing: -.01em; }
.small-name { font-size: 1.2rem; margin-bottom: .35rem; }
.card-warn { border-color: oklch(from var(--alert) calc(l - 0.3) calc(c * .6) h); background: linear-gradient(180deg, oklch(from var(--alert) 0.21 0.03 h), var(--ink-2)); }
.card p { margin: .45rem 0 .85rem; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em; padding: .6rem 1.15rem;
  border-radius: var(--radius); border: 1px solid var(--energy); background: var(--energy); color: var(--on-accent);
  font: inherit; font-weight: 650; font-size: .93rem; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: filter .15s ease-out, background-color .15s ease-out, box-shadow .15s ease-out; }
.btn:hover { filter: brightness(1.08); box-shadow: 0 0 14px oklch(from var(--energy) l c h / 0.28); color: var(--on-accent); }
.btn:active { filter: brightness(.95); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: var(--ink-3); border-color: var(--text-faint); box-shadow: none; color: var(--text); filter: none; }
.btn-sm { padding: .38rem .8rem; font-size: .86rem; }
.btn-danger { color: var(--alert); border-color: oklch(from var(--alert) calc(l - 0.2) calc(c * .7) h); }
.btn-danger:hover { background: var(--alert-wash); color: var(--alert); }

/* ---------- Text helpers ---------- */
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: .85rem; }
.warn { color: var(--alert); }
.ok { color: var(--good); }
.nowrap { white-space: nowrap; }
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; margin-top: 1rem; }
.row-top { margin-top: 0; align-items: flex-start; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.crumb { color: var(--text-faint); text-decoration: none; }
.crumb:hover { color: var(--kinetic); }

/* ---------- Tags ---------- */
.tag { display: inline-block; padding: .08rem .55rem; border: 1px solid var(--line); border-radius: 99px;
  color: var(--text-dim); font-size: .8rem; line-height: 1.5; }
.tag-you { border-color: oklch(from var(--kinetic) l c h / 0.5); color: var(--kinetic); }

/* ---------- Key/value grid ---------- */
.grid { display: grid; grid-template-columns: max-content 1fr; gap: .55rem 1.6rem; }
.grid dt { color: var(--text-dim); }
.grid dd { overflow-wrap: anywhere; }

/* ---------- Dashboard readouts (instrument rows, not tiles) ---------- */
.readouts { display: grid; gap: 0; }
.readout { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 4px 16px;
  padding: 14px 0; border-top: 1px solid var(--line-soft); }
.readout:first-child { border-top: 0; padding-top: 6px; }
.readout-label { color: var(--text-dim); font-size: .88rem; }
.readout-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; letter-spacing: -.01em; }
.readout-note { grid-column: 1 / -1; color: var(--text-faint); font-size: .8rem; }
.readout-value.you { color: var(--kinetic); }
.readout-value.win { color: var(--energy); }
.readout a { text-decoration: none; }
.dash { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 899px) { .dash { grid-template-columns: 1fr; } }
.hello { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; }
.standing { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 12px 0; border-top: 1px solid var(--line-soft); text-decoration: none; color: var(--text); }
.standing:first-of-type { border-top: 0; }
.standing:hover .standing-name { color: var(--kinetic); }
.rank { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--text-dim); min-width: 2.2em; }
.rank.first { color: var(--energy); text-shadow: 0 0 10px oklch(from var(--energy) l c h / 0.45); }
.standing-name { font-weight: 600; transition: color .15s ease-out; }
.standing-val { font-variant-numeric: tabular-nums; color: var(--text-dim); text-align: right; font-size: .9rem; }

/* ---------- Stat blocks ---------- */
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); gap: 0; margin: .9rem 0 1.2rem;
  border: 1px solid var(--line-soft); border-radius: var(--radius); overflow: hidden; }
.stat { padding: .75rem .9rem; border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); background: oklch(from var(--ink-0) l c h / 0.5); }
.stat-total { background: var(--kinetic-wash); }
.stat-label { font-size: .7rem; letter-spacing: .15em; text-transform: uppercase; color: var(--text-dim); }
.stat-val { font-size: 1.12rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-gain { color: var(--good); font-size: .82rem; font-variant-numeric: tabular-nums; }

/* ---------- Forms ---------- */
.keyform { display: flex; flex-wrap: wrap; gap: .6rem; }
.keyform input, .contest-form input[name="name"], .contest-form input[type="date"], .num-input {
  padding: .55rem .7rem; border-radius: var(--radius); border: 1px solid var(--line); background: var(--ink-0);
  color: var(--text); font: inherit; }
.keyform input { flex: 1 1 14rem; min-width: 0; letter-spacing: .06em; }
.keyform input:focus, .contest-form input:focus { outline: 2px solid var(--kinetic); outline-offset: 1px; border-color: transparent; }
.contest-form .field { display: block; border: 0; padding: 0; margin: 1.3rem 0; }
.contest-form legend, .contest-form .field > span { display: block; color: var(--text-dim); font-size: .85rem; margin-bottom: .5rem; }
.contest-form input[name="name"] { width: 100%; max-width: 28rem; }
.num-input { width: 4.5rem; }
.choice { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; margin: .45rem 0; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--kinetic); width: 1rem; height: 1rem; }
.metric-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr)); gap: 1.1rem 1.4rem; }
.metric-group-name { font-size: .7rem; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; color: var(--energy); margin-bottom: .25rem; }
.metric-group .choice { margin: .25rem 0; font-size: .92rem; }
.perms { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.2rem; }
.perms label { display: inline-flex; gap: .4rem; align-items: center; }
.steps { margin: .6rem 0 1rem 1.2rem; }
.steps li { margin: .3rem 0; }

/* ---------- Tables ---------- */
.tablewrap { overflow-x: auto; max-width: 100%; margin: 0 -.3rem; }
.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
.data th { text-align: left; color: var(--text-faint); font-weight: 600; font-size: .75rem; letter-spacing: .08em; text-transform: uppercase;
  border-bottom: 1px solid var(--line); padding: .55rem .6rem; white-space: nowrap; }
.data td { padding: .6rem .6rem; border-bottom: 1px solid var(--line-soft); }
.data tbody tr:hover td { background: oklch(from var(--ink-3) l c h / 0.45); }
.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.league th a { color: var(--text-faint); text-decoration: none; }
.league th a:hover, .league th a.sorted { color: var(--kinetic); }
.league .sorted-col { font-weight: 700; }
.league td.lead { color: var(--energy); font-weight: 700; }
.league td.lead::before { content: "▲ "; font-size: .6em; vertical-align: .15em; }   /* not color-only */
.league th { white-space: nowrap; }
.roster td, .roster th { vertical-align: middle; white-space: nowrap; padding-left: .42rem; padding-right: .42rem; }
.roster { font-size: .86rem; }
.roster a { text-decoration: none; }
.stage.wide .stage-inner:has(.roster) { max-width: 90rem; }

/* ---------- Disclosure table ---------- */
.tos { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tos th { text-align: left; color: var(--text-dim); font-weight: 500; padding: .5rem 1rem .5rem 0; vertical-align: top; white-space: nowrap; }
.tos td { padding: .5rem 0; border-bottom: 1px solid var(--line-soft); }
.tos tr:last-child td { border-bottom: 0; }
@media (max-width: 34rem) { .tos th { white-space: normal; } }

/* ---------- Status bits ---------- */
.dot { display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; margin-right: .35rem; background: var(--line); }
.dot-online { background: var(--good); }
.dot-idle { background: var(--energy); }
.cd { display: block; font-variant-numeric: tabular-nums; line-height: 1.35; }
.pill { display: inline-block; padding: .05rem .55rem; border-radius: 4px; font-size: .8rem; }
.pill-yes { background: oklch(from var(--good) l c h / 0.14); color: var(--good); }
.pill-no { background: var(--alert-wash); color: var(--alert); }
.state { font-size: .7rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; padding: .15rem .55rem; border-radius: 4px; white-space: nowrap; }
.state-running { background: var(--kinetic-wash); color: var(--kinetic); }
.state-upcoming { background: var(--energy-wash); color: var(--energy); }
.state-finished { background: var(--ink-3); color: var(--text-dim); }

/* ---------- Lists of things (leagues, reports, lead tools) ---------- */
.contest-item, .tool { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .95rem 0;
  border-top: 1px solid var(--line-soft); color: var(--text); text-decoration: none; }
.contest-item:first-of-type { margin-top: .6rem; }
.tool:first-child { border-top: 0; padding-top: .2rem; }
.contest-item:hover .contest-name, .tool:hover .tool-name { color: var(--kinetic); }
.contest-name, .tool-name { font-weight: 600; transition: color .15s ease-out; }
.tool-arrow { color: var(--text-faint); }

@media (max-width: 40rem) {
  .card { padding: 16px; }
  .data { font-size: .86rem; }
  .data th, .data td { padding: .5rem .4rem; }
  .page-title { font-size: 1.3rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.readout-text { font-size: 1rem; }
.card p.flush { margin-bottom: 0; }
.roster td.status-cell { white-space: normal; min-width: 6.5rem; max-width: 8.5rem; line-height: 1.3; }
.roster th { letter-spacing: .04em; }
.stage.wide { padding-left: clamp(16px, 2.5vw, 32px); padding-right: clamp(16px, 2.5vw, 32px); }
@media (min-width: 900px) and (max-width: 1399px) { :root { --rail-w: 204px; } }
.win-name, td.lead-name { color: var(--energy); font-weight: 600; }

/* ---------- League ideas (empty Leagues page) ---------- */
.lede { font-size: 1.02rem; max-width: 60ch; }
.idea { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 0;
  border-top: 1px solid var(--line-soft); color: var(--text); text-decoration: none; }
.idea:first-of-type { margin-top: .4rem; }
.idea-main { display: grid; gap: .2rem; }
.idea-name { font-weight: 650; font-size: 1.02rem; transition: color .15s ease-out; }
.idea-blurb { color: var(--text-dim); font-size: .9rem; }
.idea-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .25rem; }
.idea-tags .tag { font-size: .74rem; }
.idea:hover .idea-name { color: var(--energy); }
.idea:hover .idea-tags .tag { border-color: oklch(from var(--energy) l c h / 0.45); }
