/* Mastan Me. Dark, phone-first, system fonts, no inline styles. */
:root {
  --bg: #05060b;
  --bg2: #0b0d17;
  --card: #10131f;
  --card2: #161a29;
  --line: #232840;
  --ink: #e8eaf2;
  --muted: #9aa0b8;
  --faint: #6b718a;
  --accent: #7cc4ff;
  --accent2: #b48cff;
  --good: #5ee37d;
  --warn: #ffc94d;
  --bad: #ff6b6b;
  --radius: 14px;
  --gutter: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 8px; letter-spacing: -0.01em; }
h1 { font-size: 24px; } h2 { font-size: 19px; } h3 { font-size: 16px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* buttons and inputs */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card2); color: var(--ink);
  font: inherit; font-size: 15px; font-weight: 600; border-radius: 10px; padding: 0 14px; min-height: 44px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; touch-action: manipulation;
}
.btn:hover { border-color: #39406a; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: linear-gradient(135deg, #3d7bff, #8a5cff); border-color: transparent; color: #fff; }
.btn.good { color: var(--good); }
.btn.bad { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; font-size: 14px; padding: 0 10px; }
.btn.big { min-height: 52px; font-size: 17px; padding: 0 22px; width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
textarea, input[type="text"], select {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--bg2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
select { min-height: 44px; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }

/* chips */
.chip {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; border: 1px solid var(--line); background: var(--card);
  color: var(--muted); border-radius: 999px; padding: 4px 10px; font-size: 13px; line-height: 1.3;
}
.chip b { color: var(--ink); font-weight: 650; }
button.chip { font: inherit; font-size: 13px; cursor: pointer; min-height: 32px; }
button.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--ink); background: #14223a; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
.chips.scroll::-webkit-scrollbar { display: none; }
.badge { display: inline-block; font-size: 12px; font-weight: 650; border-radius: 6px; padding: 1px 7px; border: 1px solid var(--line); color: var(--muted); }
.badge.active { color: var(--good); border-color: #23503a; }
.badge.needs_confirmation { color: var(--warn); border-color: #5a4a1d; }
.badge.superseded { color: var(--faint); }
.badge.needs-you { color: #1b1300; background: var(--warn); border-color: var(--warn); }
.badge.priority-high { color: var(--bad); border-color: #5a2525; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; padding: calc(var(--safe-top) + 8px) var(--gutter) 0;
  background: rgba(5, 6, 11, 0.82); -webkit-backdrop-filter: blur(14px) saturate(140%); backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid rgba(35, 40, 64, 0.7);
}
.topbar-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 700; font-size: 15px; flex: none; }
.brand:hover { text-decoration: none; }
.stats { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; flex: 1; }
.stats > :first-child { margin-left: auto; }
.stats::-webkit-scrollbar { display: none; }
.stats .chip { padding: 3px 9px; font-size: 12px; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin: 8px calc(var(--gutter) * -1) 0; padding: 0 calc(var(--gutter) - 6px); }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: var(--muted); padding: 9px 10px 11px; font-size: 15px; font-weight: 600; white-space: nowrap; border-bottom: 2px solid transparent; }
.nav a:hover { text-decoration: none; color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.operator-banner { margin: 0; padding: 6px var(--gutter); background: #2a2008; color: var(--warn); font-size: 13px; }

/* layout */
.main { padding: 16px var(--gutter) calc(32px + var(--safe-bottom)); max-width: 880px; margin: 0 auto; outline: none; }
.loading { color: var(--muted); }
.loading::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.section { margin: 22px 0 10px; display: flex; align-items: baseline; gap: 8px; }
.section h2 { margin: 0; }
.section .count { color: var(--muted); font-size: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.card.flag { border-color: #5a4a1d; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }
.unavailable { border: 1px dashed #5a2525; color: var(--muted); border-radius: var(--radius); padding: 18px; text-align: center; margin: 16px 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 6px 0 10px; }
.toolbar .grow { flex: 1; }

/* stats row (Question Panel) */
.stat-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.stat-tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 8px; text-align: center; min-width: 0; }
.stat-tile b { display: block; font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-tile span { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 420px) { .stat-tile b { font-size: 19px; } .stat-tile span { font-size: 10px; } .stat-row { gap: 6px; } }

/* question cards */
.q-card { position: relative; padding-left: 52px; }
.q-num { position: absolute; left: 14px; top: 14px; width: 28px; height: 28px; border-radius: 50%; background: var(--card2); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.q-text { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.q-why { color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.q-why b { color: var(--ink); font-weight: 600; }
.q-meta { font-size: 13px; color: var(--faint); margin-bottom: 8px; }
.q-meta.waiting { color: var(--warn); }
.q-card textarea { min-height: 84px; }
.q-card .filing { color: var(--accent); font-size: 14px; margin-top: 8px; }
.q-card.done { border-color: #23503a; }
.q-result { margin-top: 8px; font-size: 14px; color: var(--muted); }
.q-group-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
details.later { margin-top: 26px; }
details summary { cursor: pointer; color: var(--muted); font-weight: 600; min-height: 36px; display: flex; align-items: center; }

/* positions */
.p-statement { font-size: 16px; margin-bottom: 8px; }
.p-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.conf { display: inline-flex; align-items: center; gap: 6px; }
.conf-bar { width: 56px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; display: inline-block; }
.conf-bar i { display: block; height: 100%; background: linear-gradient(90deg, #3d7bff, #5ee37d); }
.sources { margin-top: 8px; font-size: 13px; color: var(--muted); }
.sources li { margin: 4px 0; }
.sources q { color: var(--ink); }
ul.plain { list-style: none; padding: 0; margin: 0; }

/* board */
.lanes { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 10px; overflow-x: auto; scrollbar-width: none; }
.lanes button { appearance: none; background: none; border: 0; color: var(--muted); font: inherit; font-weight: 600; padding: 10px 10px 11px; min-height: 44px;
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.lanes button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent2); }
.lanes .n { color: var(--faint); font-weight: 500; margin-left: 4px; }
.b-title { font-weight: 650; font-size: 16px; margin-bottom: 4px; display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.b-note { color: var(--ink); font-size: 14px; white-space: pre-wrap; margin: 4px 0; }
.b-next { color: var(--muted); font-size: 14px; margin: 4px 0; }
.b-next b { color: var(--accent); font-weight: 600; }
.b-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; color: var(--faint); margin-top: 6px; }
.b-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.b-actions select { width: auto; min-width: 140px; min-height: 36px; font-size: 14px; padding: 4px 30px 4px 10px; }
.add-form { display: grid; gap: 4px; }
.add-form .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); margin: 10px 0 0; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--warn); }

/* dumps */
.d-meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--faint); margin-bottom: 4px; }
.d-preview { font-size: 14px; white-space: pre-wrap; color: var(--ink); }

/* settings */
.role { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: center; margin: 8px 0; }
.role .name { font-weight: 650; }
.role .prov { display: block; font-size: 12px; color: var(--faint); font-weight: 400; }
table.jobs { width: 100%; border-collapse: collapse; font-size: 13px; }
table.jobs th, table.jobs td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.jobs th { color: var(--muted); font-weight: 600; }
.status-ok { color: var(--good); } .status-error, .status-failed { color: var(--bad); } .status-running { color: var(--accent); }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; margin: 0; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(18px + var(--safe-bottom)); transform: translateX(-50%); z-index: 60; background: #1d2338; color: var(--ink);
  border: 1px solid #34406a; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100vw - 32px); box-shadow: 0 8px 30px rgba(0,0,0,0.5); }
.toast.error { border-color: #6a3434; color: #ffd0d0; }

/* login */
.page-login { display: flex; align-items: center; justify-content: center; min-height: 100vh; min-height: 100dvh;
  background: radial-gradient(1200px 600px at 50% -10%, #1a1f4a 0%, transparent 60%), var(--bg); }
.login { width: 100%; max-width: 380px; padding: 24px var(--gutter); }
.login-card { text-align: center; }
.login-mark { margin-bottom: 14px; filter: drop-shadow(0 0 18px rgba(124, 196, 255, 0.45)); }
.login-card h1 { font-size: 26px; }
.login-card .btn { margin-top: 18px; }
.status { min-height: 1.5em; margin-top: 12px; color: var(--muted); font-size: 14px; }

/* galaxy */
.page-galaxy { overflow: hidden; }
.page-galaxy .main { max-width: none; padding: 0; margin: 0; position: fixed; inset: 0; z-index: 1; }
.galaxy-wrap { position: absolute; inset: 0; overflow: hidden;
  background:
    radial-gradient(1px 1px at 12% 18%, rgba(255,255,255,0.7), transparent 60%),
    radial-gradient(1px 1px at 72% 12%, rgba(255,255,255,0.6), transparent 60%),
    radial-gradient(1.5px 1.5px at 38% 64%, rgba(255,255,255,0.55), transparent 60%),
    radial-gradient(1px 1px at 88% 78%, rgba(255,255,255,0.5), transparent 60%),
    radial-gradient(1px 1px at 22% 88%, rgba(255,255,255,0.45), transparent 60%),
    radial-gradient(1px 1px at 55% 30%, rgba(200,220,255,0.5), transparent 60%),
    radial-gradient(1px 1px at 6% 52%, rgba(255,255,255,0.4), transparent 60%),
    radial-gradient(1.5px 1.5px at 94% 40%, rgba(220,200,255,0.5), transparent 60%),
    radial-gradient(900px 700px at 50% 55%, #111633 0%, #070914 55%, #04050a 100%);
}
#graph { position: absolute; inset: 0; }
#graph canvas { display: block; touch-action: none; }
.page-galaxy .topbar { position: fixed; left: 0; right: 0; background: linear-gradient(rgba(5,6,11,0.85), rgba(5,6,11,0.55)); border-bottom-color: transparent; }
.legend { position: absolute; z-index: 5; left: var(--gutter); bottom: calc(14px + var(--safe-bottom)); max-width: min(300px, calc(100vw - 32px));
  background: rgba(10, 12, 22, 0.72); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border: 1px solid rgba(35,40,64,0.8); border-radius: 12px; padding: 8px; }
.legend h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 2px 4px 6px; display: flex; justify-content: space-between; gap: 8px; }
.legend h3 button { appearance: none; background: none; border: 0; color: var(--accent); font: inherit; font-size: 12px; cursor: pointer; padding: 0; text-transform: none; letter-spacing: 0; }
.legend ul { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow-y: auto; }
.legend li button { appearance: none; width: 100%; background: none; border: 0; color: var(--ink); font: inherit; font-size: 13px; display: flex; align-items: center; gap: 8px;
  padding: 5px 6px; border-radius: 8px; cursor: pointer; text-align: left; min-height: 30px; }
.legend li button:hover { background: rgba(255,255,255,0.05); }
.legend li button[aria-pressed="false"] { opacity: 0.38; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 8px currentColor; }
.legend .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.legend.collapsed ul { display: none; }
.galaxy-note { position: absolute; z-index: 5; right: var(--gutter); bottom: calc(14px + var(--safe-bottom)); max-width: 40vw; font-size: 12px; color: var(--faint); text-align: right; }
.galaxy-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 32px; color: var(--muted); z-index: 4; }

/* side panel / bottom sheet */
.sheet { position: fixed; z-index: 40; background: rgba(13, 16, 28, 0.94); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid #2a3050; box-shadow: 0 -10px 40px rgba(0,0,0,0.5); overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  left: 0; right: 0; bottom: 0; max-height: 72vh; max-height: 72dvh; border-radius: 18px 18px 0 0; padding: 10px var(--gutter) calc(20px + var(--safe-bottom));
  transform: translateY(105%); transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); }
.sheet.open { transform: translateY(0); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: #39406a; margin: 0 auto 10px; }
.sheet .close { position: absolute; right: 10px; top: 8px; }
.sheet .kind { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.sheet .statement { font-size: 18px; font-weight: 600; margin: 4px 36px 10px 0; }
.sheet h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 16px 0 6px; }
.sheet .body { font-size: 14px; color: var(--muted); white-space: pre-wrap; }
.sheet .chip.link { cursor: pointer; color: var(--ink); min-height: 34px; }
.sheet .chip.link.tension { border-color: #6a3434; }
@media (min-width: 760px) {
  .sheet { left: auto; top: 0; right: 0; bottom: 0; width: 400px; max-height: none; border-radius: 0; padding: calc(var(--safe-top) + 100px) 20px 24px;
    transform: translateX(105%); box-shadow: -10px 0 40px rgba(0,0,0,0.5); }
  .sheet.open { transform: translateX(0); }
  .sheet .grab { display: none; }
  .sheet .close { top: calc(var(--safe-top) + 100px); }
}
@media (prefers-reduced-motion: reduce) { .sheet { transition: none; } .loading::after { animation: none; content: "..."; } }

/* 3d-force-graph injects these with a <style> tag, which the CSP blocks; restyle here */
.scene-nav-info, .graph-info-msg { display: none; }
.scene-container { position: relative; }
.float-tooltip-kap { position: absolute; z-index: 30; max-width: 320px; padding: 6px 10px; border-radius: 8px; font-size: 13px; background: rgba(13,16,28,0.92);
  color: var(--ink); border: 1px solid #2a3050; pointer-events: none; white-space: normal; }
.float-tooltip-kap:empty { display: none; }

/* WebKit (iPhone Safari) stops drawing a WebGL canvas that sits under backdrop-filter layers.
   The galaxy page uses solid translucent panels instead. */
.page-galaxy .topbar, .page-galaxy .legend, .page-galaxy .sheet { -webkit-backdrop-filter: none; backdrop-filter: none; }
.page-galaxy .topbar { background: linear-gradient(rgba(5,6,11,0.92), rgba(5,6,11,0.6)); }
.page-galaxy .legend { background: rgba(10, 12, 22, 0.86); }
.page-galaxy .sheet { background: rgba(13, 16, 28, 0.97); }
.readonly-banner { margin: 4px 0 10px; padding: 10px 12px; border-radius: 10px; background: #2a2008; border: 1px solid #5a4a1d; color: var(--warn); font-size: 14px; }
