:root {
  --bg: #15110d;
  --bg-2: #1d1813;
  --panel: #231d17;
  --panel-2: #2b241c;
  --line: #3a3026;
  --text: #ece3d4;
  --muted: #a8998380;
  --muted-text: #a89983;
  --accent: #d9a441;
  --accent-ink: #1a1410;
  --off: #e0644f;
  --fake: #4fbf86;
  --ruin: #5b9be6;
  --noble: #b07be6;
  --danger: #e0644f;
  --warn: #e6b450;
  --ok: #4fbf86;
  --radius: 10px;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 650; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted-text); }
.center { text-align: center; }
.mono { font-family: var(--mono); }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1rem;
  background: rgba(21, 17, 13, .92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.05rem; }
.brand svg { width: 22px; height: 22px; color: var(--accent); }
.world-badge { font-size: .75rem; font-weight: 600; padding: .1rem .45rem; border-radius: 6px; background: var(--panel-2); color: var(--accent); }
.clock { margin-left: auto; font-family: var(--mono); font-size: 1.05rem; padding: .2rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); }
.user { display: flex; align-items: center; gap: .6rem; }

main { max-width: 1100px; margin: 0 auto; padding: 1rem; }

/* ---------- controls ---------- */
button, .btn {
  font: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .5rem .9rem;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-ink);
  font-weight: 600; text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button:disabled, .btn.disabled { opacity: .45; cursor: not-allowed; filter: none; pointer-events: none; }
button.ghost, .btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.ghost:hover, .btn.ghost:hover { border-color: var(--accent); }
button.small, .btn.small { padding: .25rem .6rem; font-size: .85rem; }
button.danger { background: transparent; color: var(--danger); border-color: var(--line); }

input, textarea, select {
  font: inherit; color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem .65rem;
  width: 100%;
}
textarea { min-height: 7rem; font-family: var(--mono); font-size: .82rem; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: .85rem; color: var(--muted-text); margin: .6rem 0 .25rem; }
.check { display: inline-flex; align-items: center; gap: .45rem; color: var(--text); margin: 0; cursor: pointer; font-size: .9rem; }
.check input { width: auto; accent-color: var(--accent); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- auth ---------- */
.auth { max-width: 440px; margin: 2rem auto; }
.auth .tabs { margin-bottom: 1rem; }
.code-box { font-family: var(--mono); font-size: 1.6rem; letter-spacing: .08em; text-align: center; padding: .8rem; border: 2px dashed var(--accent); border-radius: 10px; margin: .8rem 0; user-select: all; }
.steps { padding-left: 1.2rem; }
.steps li { margin: .35rem 0; }
.note { font-size: .82rem; color: var(--muted-text); }
.error { color: var(--danger); margin-top: .6rem; }

/* ---------- tabs / chips ---------- */
.tabs { display: flex; gap: .25rem; border: 1px solid var(--line); border-radius: 10px; padding: .25rem; background: var(--bg-2); overflow-x: auto; }
.tabs button { flex: 1; background: transparent; border: 1px solid transparent; color: var(--muted-text); font-weight: 600; }
.tabs button.active { background: var(--panel-2); color: var(--text); border-color: var(--line); }

.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .2rem .55rem; border-radius: 7px;
  font-size: .78rem; font-weight: 700; letter-spacing: .02em;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
}
button.chip { cursor: pointer; }
button.chip.on { border-color: currentColor; }
button.chip:not(.on) { opacity: .55; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.t-off { color: var(--off); }
.t-fake { color: var(--fake); }
.t-ruin { color: var(--ruin); }
.t-noble { color: var(--noble); }
.chip.exact { color: var(--warn); border-color: rgba(230, 180, 80, .5); font-size: .72rem; vertical-align: middle; }
.chip .count { color: var(--muted-text); font-weight: 600; }

.badge { font-size: .72rem; font-weight: 800; padding: .12rem .45rem; border-radius: 5px; letter-spacing: .03em; }
.badge.late { background: var(--danger); color: #fff; }
.badge.now { background: var(--ok); color: #08130d; }
.badge.soon { background: var(--warn); color: #1a1205; }
.badge.wait { background: var(--panel-2); color: var(--muted-text); }
.badge.sent { background: #2f3b33; color: var(--ok); }

/* ---------- next send ---------- */
.hero { border-left: 4px solid var(--fake); background: linear-gradient(90deg, rgba(79, 191, 134, .08), transparent 60%), var(--panel); }
.hero.t-off { border-left-color: var(--off); background: linear-gradient(90deg, rgba(224, 100, 79, .08), transparent 60%), var(--panel); }
.hero.t-ruin { border-left-color: var(--ruin); }
.hero.t-noble { border-left-color: var(--noble); }
.hero .kicker { font-size: .75rem; color: var(--muted-text); text-transform: uppercase; letter-spacing: .06em; }
.hero h2 { font-size: 1.4rem; margin: .1rem 0 .4rem; }
.hero .countdown { font-family: var(--mono); font-size: 1.5rem; font-weight: 700; }
.hero-grid { display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: start; }
.hero-actions { display: flex; flex-direction: column; gap: .5rem; align-items: stretch; min-width: 220px; }
@media (max-width: 760px) { .hero-grid { grid-template-columns: 1fr; } .hero-actions { min-width: 0; } }

/* ---------- queue ---------- */
.day { margin: 1.2rem 0 .5rem; font-weight: 700; color: var(--muted-text); }
.day::first-letter { text-transform: uppercase; }
.cmd {
  display: grid; grid-template-columns: 120px 1fr auto; gap: .9rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem; margin-bottom: .5rem;
}
.cmd.late { border-color: rgba(224, 100, 79, .55); }
.cmd.now { border-color: rgba(79, 191, 134, .7); box-shadow: 0 0 0 1px rgba(79, 191, 134, .25); }
.cmd.sent { opacity: .55; }
.cmd .when { font-family: var(--mono); font-weight: 700; }
.cmd .when small { display: block; color: var(--muted-text); font-weight: 500; }
.cmd .meta, .hero .meta { display: grid; grid-template-columns: 70px 1fr; gap: .15rem .6rem; font-size: .88rem; }
.cmd .meta dt, .hero .meta dt { color: var(--muted-text); }
.cmd .meta dd, .hero .meta dd { margin: 0; }
.cmd .head { display: flex; gap: .45rem; align-items: center; flex-wrap: wrap; margin-bottom: .35rem; }
.cmd .actions { display: flex; flex-direction: column; gap: .4rem; align-items: stretch; min-width: 170px; }
.units { display: flex; flex-wrap: wrap; gap: .3rem; }
.unit { font-family: var(--mono); font-size: .8rem; padding: .1rem .4rem; border-radius: 5px; background: var(--bg-2); border: 1px solid var(--line); }
.unit b { color: var(--accent); font-weight: 700; }
.warn { color: var(--warn); font-size: .82rem; }
.sub { color: var(--muted-text); font-size: .82rem; }
.target { color: #f0a08f; }
@media (max-width: 760px) {
  .cmd { grid-template-columns: 1fr; }
  .cmd .actions { min-width: 0; }
}

.filters { display: flex; flex-direction: column; gap: .6rem; }
.empty { text-align: center; padding: 2rem; color: var(--muted-text); }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { padding: .35rem .5rem; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted-text); font-weight: 600; }
.table-wrap { overflow-x: auto; }
td.low { color: var(--danger); font-weight: 700; }

/* ---------- gantt ---------- */
.gantt { position: relative; overflow-x: auto; }
.gantt-inner { position: relative; min-width: 760px; }
.g-axis { position: relative; height: 22px; margin-left: 230px; border-bottom: 1px solid var(--line); }
.g-tick { position: absolute; top: 0; font-size: .72rem; color: var(--muted-text); transform: translateX(-50%); }
.g-row { display: flex; align-items: center; height: 30px; border-bottom: 1px solid rgba(58, 48, 38, .5); }
.g-label { width: 230px; flex: none; font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: .5rem; }
.g-track { position: relative; flex: 1; height: 100%; }
.g-bar { position: absolute; top: 8px; height: 14px; border-radius: 4px; background: currentColor; opacity: .85; }
.g-bar.sent { opacity: .3; }
.g-bar.exact { width: 12px !important; height: 12px; top: 9px; margin-left: -6px; border-radius: 2px; transform: rotate(45deg); opacity: 1; }
.g-now { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); z-index: 2; }

/* ---------- misc ---------- */
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); padding: .6rem 1rem; border-radius: 10px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100% - 2rem); z-index: 20; }
.toast.show { opacity: 1; }
.toast.err { border-color: var(--danger); }
details > summary { cursor: pointer; font-weight: 650; list-style: none; }
details > summary::before { content: '▸ '; color: var(--muted-text); }
details[open] > summary::before { content: '▾ '; }
.source { display: flex; align-items: center; gap: .6rem; padding: .45rem 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.source:last-child { border-bottom: 0; }
.status-ok { color: var(--ok); }
.status-fallback { color: var(--warn); }
.status-error { color: var(--danger); }
.stats { display: flex; gap: .5rem; flex-wrap: wrap; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: .4rem .7rem; min-width: 110px; }
.stat b { display: block; font-size: 1.15rem; }
.stat span { font-size: .75rem; color: var(--muted-text); }
pre.bb { white-space: pre-wrap; background: #efe3c4; color: #2b2116; padding: .8rem; border-radius: 8px; font-size: .8rem; max-height: 420px; overflow: auto; }

/* ---------- plans ---------- */
.plan-head h2 { margin: 0; }
.section-title { margin: 1.4rem 0 .6rem; }
.op-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.op-card { display: flex; flex-direction: column; gap: .5rem; margin: 0; color: var(--text); text-decoration: none; transition: border-color .15s; }
.op-card:hover { border-color: var(--accent); }
.op-name { font-size: 1.05rem; }
.progress { height: 6px; border-radius: 3px; background: var(--bg-2); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--ok); }
.archive-row { display: flex; gap: .8rem; align-items: baseline; padding: .5rem 0; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; flex-wrap: wrap; }
.archive-row:hover b { color: var(--accent); }
.archive-row:last-child { border-bottom: 0; }
details.archive > summary, details.recent > summary { margin-bottom: .2rem; }
.recent { border-color: rgba(79, 191, 134, .35); }
.recent-row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; padding: .4rem 0; border-top: 1px solid var(--line); font-size: .88rem; }
