:root {
  --bg: #0b1220;
  --bg-elev: #10192b;
  --card: #162033;
  --line: #2a384c;
  --text: #e7edf5;
  --muted: #93a0b5;
  --emerald: #34d399;
  --emerald-ink: #042f24;
  --amber: #fbbf24;
  --amber-ink: #2a2106;
  --rose: #fb7185;
  --rose-ink: #2a0c12;
  --sky: #7dd3fc;
  --focus: #6ee7b7;
  --dock: 0px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 ui-sans-serif, system-ui, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.top {
  height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.brand { font-weight: 700; letter-spacing: 0.04em; color: var(--emerald); }
h1, h2, h3 { margin: 0; font-size: 16px; font-weight: 650; }
.rowtools h1 { flex: 1; min-width: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-note { margin: 0; flex: 1; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session, .status {
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
}
.status { color: var(--emerald); border-color: #1f6b4a; }
.app { height: calc(100% - 52px); min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.frame { flex: 1; min-height: 0; display: flex; overflow: hidden; }
.stage { flex: 1; min-width: 0; min-height: 0; display: flex; overflow: hidden; }
.stage > .col { flex: 1; min-width: 0; min-height: 0; overflow: hidden; }
.col { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg); overflow: hidden; }
.col > .col { flex: 1 1 auto; min-height: 0; overflow: hidden; }
.card-list { flex: 1; min-height: 0; }
.colhead {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
}
.rowtools, .chips, .filters { display: flex; gap: 8px; align-items: center; overflow-x: auto; }
.chips button, .filters button, .side button, .bottom button, .btn, .modbar button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  min-height: 44px;
  padding: 0 12px;
}
.chips button[aria-pressed="true"], .filters button[aria-pressed="true"], .side button[aria-current="page"], .bottom button[aria-current="page"] {
  border-color: var(--emerald);
  color: var(--emerald);
}
input[type="search"], input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  background: #0c1424;
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 44px;
  padding: 8px 10px;
}
textarea { min-height: 120px; resize: vertical; }
.scroller { flex: 1; min-height: 0; overflow: auto; position: relative; }
.spacer { width: 100%; }
.win { position: absolute; top: 0; left: 0; right: 0; }
.vrow {
  overflow: hidden;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid #1d2838;
}
.vrow.selected { background: #132033; box-shadow: inset 3px 0 0 var(--emerald); }
.thumb, .thumb-btn {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: #243044;
  display: block;
  object-fit: cover;
  border: 1px solid var(--line);
  padding: 0;
}
.thumb-btn { position: relative; }
.thumb-ph {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: linear-gradient(160deg, #243044, #1a2436);
  border: 1px solid var(--line);
}
.v-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-meta, .muted { color: var(--muted); font-size: 12px; }
.v-com { color: #d5deea; font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.post-row { align-items: start; height: 120px; grid-template-columns: 56px minmax(0, 1fr); padding-top: 8px; }
.backlinks, .quote-link { font-size: 12px; }
.quote-link {
  background: transparent;
  border: 0;
  color: var(--sky);
  padding: 0 2px;
  min-height: 24px;
  text-decoration: underline;
}
.empty {
  margin: 24px 16px;
  padding: 20px 16px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
}
.banner {
  margin: 0;
  padding: 8px 12px;
  background: #2a2106;
  color: #fde68a;
  border-bottom: 1px solid #6b5a1e;
  font-size: 13px;
}
.side { display: none; }
.dock {
  flex: 0 0 auto;
  background: #0e1626;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.cheat {
  margin: 0;
  padding: 6px 10px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}
.bottom { display: flex; gap: 6px; padding: 6px; }
.bottom button { flex: 1; background: transparent; }
.modbar { display: flex; gap: 8px; padding: 8px; }
.modbar button { flex: 1; min-width: 44px; background: var(--card); }
.modbar button .sub { display: block; font-size: 10px; color: var(--muted); font-weight: 500; }
.modbar button.danger { border-color: #7f1d1d; }
.modbar button.warn { border-color: #78580a; }
.mod-note { margin: 0; padding: 0 10px 6px; color: var(--muted); font-size: 12px; }
.card-list { overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.mcard, .qcard {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.mcard header, .qcard header { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.mcard h2, .qcard h2 { margin: 0; font-size: 16px; }
.flags, .actions { display: flex; flex-wrap: wrap; gap: 6px; }
.flag, .chip {
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 2px 8px;
  font-size: 12px;
  color: var(--text);
}
.card-list > .chip, .card-list > p, .card-list > h2 { max-width: 100%; }
.card-list > .chip { align-self: flex-start; }
.chip-ok, .chip-done { border-color: #1f6b4a; color: var(--emerald); }
.chip-near, .chip-pending { border-color: #78580a; color: var(--amber); }
.chip-missing, .chip-failed, .chip-new { border-color: #7f1d1d; color: var(--rose); }
.chip-behind { border-color: #1e4e6a; color: var(--sky); }
.actions button, .btn { min-height: 44px; }
.snack {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--dock, 150px) + 8px);
  z-index: 40;
  background: #102033;
  border: 1px solid var(--emerald);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.gallery, .sheet, .quote {
  position: fixed;
  z-index: 50;
  background: #070d18;
}
.gallery { inset: 0; display: flex; flex-direction: column; }
.gallery[hidden], .sheet[hidden], .quote[hidden], .snack[hidden], .modbar[hidden] { display: none !important; }
.gallery-top, .filmstrip { display: flex; gap: 8px; align-items: center; padding: 8px; }
.gallery-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 8px; }
.gallery-stage img {
  width: min(86vw, 640px);
  height: min(56vh, 560px);
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  background: #111;
}
.filmstrip { overflow-x: auto; border-top: 1px solid var(--line); flex: 0 0 auto; }
.filmstrip button { flex: 0 0 52px; width: 52px; height: 52px; padding: 0; border-radius: 8px; border: 1px solid var(--line); background: #1a2436; }
.filmstrip button[aria-current="true"] { border-color: var(--emerald); }
.filmstrip img { width: 48px; height: 48px; object-fit: cover; display: block; }
.quote {
  left: 12px;
  right: 12px;
  bottom: calc(var(--dock, 150px) + 8px);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  max-height: 46vh;
  overflow: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,.4);
}
.quote h3 { margin: 0 0 6px; font-size: 14px; }
.sheet {
  inset: 0;
  overflow: auto;
  padding: 16px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sheet h2 { margin: 0; }
.art-preview { width: 120px; height: 120px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); background: #1a2436; }
.table-wrap { overflow: auto; }
table.gens {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
table.gens th, table.gens td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 6px 8px;
  vertical-align: middle;
  white-space: nowrap;
}
table.gens th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--bg-elev); }

@media (max-width: 999px) {
  .col.right, .modbar.desk { display: none !important; }
  body.view-thread .col.left { display: none !important; }
  body.view-thread .col.right { display: flex !important; flex: 1; }
  .desk-table { display: none; }
  .post-scroll { scroll-padding-bottom: 12px; }
}
@media (min-width: 1000px) {
  .frame { display: grid; grid-template-columns: 200px minmax(0, 1fr); }
  .stage {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(340px, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }
  .side {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border-right: 1px solid var(--line);
    background: var(--bg-elev);
  }
  .side .cheat { padding: 12px 4px; font-size: 12px; }
  .dock { display: none; }
  .col.right { border-left: 1px solid var(--line); }
  .modbar.desk {
    position: static;
    border-top: 1px solid var(--line);
    background: var(--bg-elev);
  }
  .quote { left: auto; right: 24px; width: min(420px, 36vw); bottom: 24px; }
  .sheet { inset: 52px 0 0 auto; width: min(520px, 42vw); border-left: 1px solid var(--line); }
  .phone-cards { display: none; }
  .snack { left: auto; right: 24px; width: min(440px, 40vw); bottom: 24px; }
  body.view-manager .stage { grid-template-columns: minmax(0, 1.75fr) minmax(260px, 0.62fr); }
  body.view-queue .stage { grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr); }
  .side .cheat { display: flex; flex-direction: column; gap: 4px; line-height: 1.3; }
}

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
