:root {
  --bg: #0b0d12;
  --bg-2: #10131a;
  --surface: #151923;
  --surface-2: #1b2030;
  --line: #252b3b;
  --line-2: #31384c;
  --text: #e7e9f0;
  --muted: #8d95aa;
  --faint: #5f6780;
  --ember: #ff8a3d;
  --ember-soft: rgba(255, 138, 61, 0.14);
  --ok: #3ecf8e;
  --ok-soft: rgba(62, 207, 142, 0.13);
  --warn: #f5b942;
  --warn-soft: rgba(245, 185, 66, 0.13);
  --bad: #ff5c5c;
  --bad-soft: rgba(255, 92, 92, 0.13);
  --info: #7aa8ff;
  --info-soft: rgba(122, 168, 255, 0.13);
  --sim: #c38cff;
  --sim-soft: rgba(195, 140, 255, 0.14);
  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --nav-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: 0.95rem; font-weight: 600; }
small, .muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); font-size: 0.92em; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 18px 14px; border-right: 1px solid var(--line); background: var(--bg-2); display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: 0.02em; padding: 4px 8px; }
.brand img { width: 28px; height: 28px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm); color: var(--muted); font-weight: 550; }
.nav a:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--text); box-shadow: inset 2px 0 0 var(--ember); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; font-size: 12px; color: var(--faint); padding: 0 8px; }
main { min-width: 0; padding: 0 0 40px; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: rgba(11, 13, 18, 0.86); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 1.15rem; }
.topbar .spacer { flex: 1; }
.page { padding: 20px 24px; display: flex; flex-direction: column; gap: 18px; max-width: 1280px; }

.banner { padding: 10px 24px; font-size: 13.5px; font-weight: 600; display: flex; gap: 10px; align-items: center; }
.banner.sim { background: var(--sim-soft); color: var(--sim); border-bottom: 1px solid rgba(195, 140, 255, 0.3); }
.banner.stop { background: var(--bad-soft); color: var(--bad); border-bottom: 1px solid rgba(255, 92, 92, 0.35); }

/* mode pill, always visible */
.mode { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: 12.5px; letter-spacing: 0.06em; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; }
.mode .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--info); }
.mode.watch { color: var(--info); }
.mode.active { color: var(--ember); border-color: rgba(255, 138, 61, 0.55); background: var(--ember-soft); }
.mode.active .dot { background: var(--ember); animation: pulse 1.6s infinite; }
.mode.stop { color: var(--bad); border-color: rgba(255, 92, 92, 0.6); background: var(--bad-soft); }
.mode.stop .dot { background: var(--bad); }
.mode.paused { color: var(--warn); border-color: rgba(245, 185, 66, 0.5); }
.mode.paused .dot { background: var(--warn); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255, 138, 61, 0.6); } 70% { box-shadow: 0 0 0 8px rgba(255, 138, 61, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 138, 61, 0); } }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card.flat { background: transparent; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.grid.accounts { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.two { grid-template-columns: 1.4fr 1fr; }
.grid.names { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.divider { height: 1px; background: var(--line); margin: 10px 0; }

/* chips & pills */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.chip.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.chip.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.chip.bad { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.chip.info { color: var(--info); background: var(--info-soft); border-color: transparent; }
.chip.ember { color: var(--ember); background: var(--ember-soft); border-color: transparent; }
.chip.sim { color: var(--sim); background: var(--sim-soft); border-color: rgba(195, 140, 255, 0.35); }
.chip.ghost { background: transparent; }

/* state colours */
.st-watching, .st-unknown, .st-not_found_unknown { color: var(--muted); }
.st-scheduled, .st-reserved_estimate { color: var(--info); background: var(--info-soft); border-color: transparent; }
.st-armed { color: var(--ember); background: var(--ember-soft); border-color: rgba(255, 138, 61, 0.4); }
.st-attempting { color: #111; background: var(--ember); border-color: transparent; }
.st-claimed, .st-available { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.st-missed, .st-cancelled, .st-taken { color: var(--faint); }
.st-paused { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.st-needs_attention, .st-restricted, .st-invalid { color: var(--bad); background: var(--bad-soft); border-color: transparent; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 13px; border-radius: var(--radius-sm); border: 1px solid var(--line-2); background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 13.5px; cursor: pointer; min-height: 36px; transition: background .12s, border-color .12s; }
.btn:hover { border-color: var(--faint); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--ember); border-color: var(--ember); color: #160b03; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--bad-soft); border-color: rgba(255, 92, 92, 0.5); color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.sm { padding: 4px 9px; min-height: 30px; font-size: 12.5px; }
.btn.icon { padding: 6px; min-width: 34px; }
.btn.on { color: var(--ember); border-color: rgba(255, 138, 61, 0.5); background: var(--ember-soft); }
.btn.big { padding: 14px 18px; font-size: 15px; }

/* forms */
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 550; }
input[type=text], input[type=password], input[type=search], input[type=number], input[type=date], input[type=datetime-local], select, textarea {
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 8px 10px; color: var(--text); min-height: 38px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--ember); outline-offset: 1px; }
input[type=range] { width: 100%; accent-color: var(--ember); }
input[type=checkbox] { accent-color: var(--ember); width: 17px; height: 17px; }
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; align-items: end; }

/* segmented filters */
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 11px; color: var(--muted); font-weight: 600; font-size: 12.5px; cursor: pointer; min-height: 32px; }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.on { background: var(--ember-soft); color: var(--ember); }

.filters { display: flex; flex-direction: column; gap: 10px; }
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filter-row > .lbl { font-size: 12px; color: var(--faint); font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; min-width: 70px; }

/* account cards */
.acct { display: flex; flex-direction: column; gap: 10px; position: relative; }
.acct .label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); font-weight: 700; }
.acct .ign { font-size: 1.5rem; font-weight: 750; letter-spacing: -0.01em; word-break: break-all; }
.acct.keep { border-color: rgba(62, 207, 142, 0.4); }
.acct.paused { opacity: 0.8; border-style: dashed; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--faint); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.skin { image-rendering: pixelated; width: 64px; height: 64px; border-radius: 8px; background: var(--bg-2); border: 1px solid var(--line); object-fit: cover; object-position: 0 0; }

/* name cards */
.name-card { display: flex; flex-direction: column; gap: 9px; }
.name-card.dismissed { opacity: 0.55; }
.name-title { display: flex; align-items: baseline; gap: 8px; justify-content: space-between; }
.name-title .nm { font-size: 1.45rem; font-weight: 760; letter-spacing: 0.005em; word-break: break-all; }
.name-title .orig { color: var(--muted); font-size: 13px; }
.score { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.bar { flex: 1; height: 5px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #b4542a, var(--ember)); border-radius: 99px; }
.parts { display: grid; grid-template-columns: auto 1fr auto; gap: 3px 8px; font-size: 12px; color: var(--muted); align-items: center; }
.parts .bar { height: 4px; }
.window { font-size: 13px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 7px 9px; }
.window b { color: var(--text); }
.stars { display: inline-flex; gap: 1px; }
.stars button { background: none; border: 0; color: var(--line-2); cursor: pointer; font-size: 17px; padding: 0 1px; line-height: 1; min-height: 28px; }
.stars button.on { color: var(--warn); }

/* lists & timeline */
.list { display: flex; flex-direction: column; }
.list > .item { display: flex; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.list > .item:last-child { border-bottom: 0; }
.ev-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--faint); }
.ev-info .ev-dot { background: var(--info); }
.ev-warn .ev-dot { background: var(--warn); }
.ev-error .ev-dot { background: var(--bad); }
.ev-success .ev-dot { background: var(--ok); }
.ev-time { font-size: 12px; color: var(--faint); white-space: nowrap; }
.day-head { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); font-weight: 700; margin: 14px 0 6px; }
.overlap { box-shadow: inset 3px 0 0 var(--warn); padding-left: 8px !important; }

.warnings { display: flex; flex-direction: column; gap: 6px; }
.warning { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); font-size: 13.5px; font-weight: 550; }
.warning.bad { background: var(--bad-soft); color: var(--bad); }
.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--info-soft); color: #c9d9ff; font-size: 13.5px; }
.notice.blocked { background: var(--bad-soft); color: #ffc4c4; }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 1.35rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }

.empty { color: var(--muted); padding: 22px; text-align: center; border: 1px dashed var(--line-2); border-radius: var(--radius); }

/* modal & toast */
dialog { border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; max-width: min(560px, calc(100vw - 24px)); width: 100%; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6); }
dialog::backdrop { background: rgba(5, 6, 9, 0.7); backdrop-filter: blur(3px); }
#modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; max-height: 85vh; overflow: auto; }
.consequences { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.confirm-box { border: 1px solid rgba(255, 138, 61, 0.4); background: var(--ember-soft); border-radius: var(--radius-sm); padding: 12px; }
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
#toast .t { background: var(--surface-2); border: 1px solid var(--line-2); padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); font-size: 13.5px; max-width: 90vw; }
#toast .t.err { border-color: rgba(255, 92, 92, 0.6); color: #ffc4c4; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 26px; }

/* emergency */
.estop { width: 100%; padding: 20px; font-size: 1.1rem; font-weight: 800; letter-spacing: 0.06em; border-radius: var(--radius); border: 2px solid var(--bad); background: var(--bad-soft); color: var(--bad); cursor: pointer; }
.estop:hover { background: rgba(255, 92, 92, 0.22); }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-opt { padding: 14px; border-radius: var(--radius); border: 1px solid var(--line-2); background: var(--bg-2); cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 4px; }
.mode-opt.sel.watch { border-color: var(--info); background: var(--info-soft); }
.mode-opt.sel.active { border-color: var(--ember); background: var(--ember-soft); }
.mode-opt b { font-size: 14px; letter-spacing: 0.04em; }

/* bottom nav on phones */
.bottom-nav { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .grid.two { grid-template-columns: 1fr; }
  .topbar { padding: 10px 14px; }
  .page { padding: 14px; padding-bottom: calc(var(--nav-h) + 24px); }
  .banner { padding: 8px 14px; }
  .bottom-nav { display: grid; grid-template-columns: repeat(6, 1fr); position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: rgba(16, 19, 26, 0.96); backdrop-filter: blur(10px); border-top: 1px solid var(--line); z-index: 10; }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--faint); font-size: 10.5px; font-weight: 650; }
  .bottom-nav a.active { color: var(--ember); }
  .bottom-nav a:hover { text-decoration: none; }
  .bottom-nav svg { width: 21px; height: 21px; }
  .grid.names { grid-template-columns: 1fr; }
  .grid.accounts { grid-template-columns: 1fr; }
  .filter-row > .lbl { min-width: 100%; }
  .topbar h1 { font-size: 1.05rem; }
  .hide-sm { display: none !important; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
details > summary { cursor: pointer; list-style-position: inside; padding: 2px 0; }
.notice, .warning { overflow-wrap: anywhere; }

.token-help p { margin: 0 0 10px; line-height: 1.5; }
.token-help ul.facts, .token-help ol.steps { margin: 6px 0 10px; padding-left: 20px; line-height: 1.55; }
.token-help ol.steps li, .token-help ul.facts li { margin: 4px 0; overflow-wrap: anywhere; }
.token-help details > summary { margin: 6px 0; }
