:root {
  --bg-0: #070809;
  --bg-1: #0c0d10;
  --bg-2: #12141a;
  --bg-3: #181b23;
  --ink-0: #f3efe6;
  --ink-1: #c5c3bb;
  --ink-2: #8b8d94;
  --ink-3: #5d5f67;
  --line: rgba(243, 239, 230, 0.08);
  --line-2: rgba(243, 239, 230, 0.14);
  --signal: #c8e86a;
  --signal-ink: #101208;
  --heat-high: #ff6d4d;
  --heat-med: #e8c35a;
  --heat-low: #6d7078;
  --warn: #ff8a6a;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --font-display: "Newsreader", "Iowan Old Style", Palatino, Georgia, serif;
  --font-ui: "IBM Plex Sans", "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --dock-pad: calc(10px + env(safe-area-inset-bottom));
  --mast-pad: calc(14px + env(safe-area-inset-top));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-0);
  color: var(--ink-0);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

html { color-scheme: dark; }

body {
  min-height: 100dvh;
  background:
    radial-gradient(900px 420px at 88% -8%, rgba(200, 232, 106, 0.045), transparent 52%),
    radial-gradient(700px 380px at -10% 110%, rgba(255, 109, 77, 0.035), transparent 46%),
    var(--bg-0);
}

::selection {
  background: color-mix(in srgb, var(--signal) 35%, transparent);
  color: var(--ink-0);
}

.skip {
  position: absolute;
  left: 12px;
  top: 8px;
  transform: translateY(-140%);
  background: var(--signal);
  color: var(--signal-ink);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 20;
  font-weight: 600;
  text-decoration: none;
}

.skip:focus { transform: none; }

.app {
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-areas:
    "mast"
    "deck"
    "filters"
    "composer";
  grid-template-rows: auto 1fr auto auto;
  grid-template-columns: 1fr;
  overflow: hidden;
}

.mast {
  grid-area: mast;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: var(--mast-pad) 16px 10px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: var(--signal);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
}

.brand-copy h1 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: -0.03em;
  margin: 0;
  line-height: 1.1;
}

.lede {
  margin: 3px 0 0;
  color: var(--ink-2);
  font-size: 0.78rem;
  letter-spacing: 0.01em;
}

.mast-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.count {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.pill {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--ink-2);
  border: 1px solid var(--line);
}

.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.pill.high { color: var(--heat-high); background: color-mix(in srgb, var(--heat-high) 12%, var(--bg-2)); border-color: color-mix(in srgb, var(--heat-high) 28%, transparent); }
.pill.med { color: var(--heat-med); background: color-mix(in srgb, var(--heat-med) 12%, var(--bg-2)); border-color: color-mix(in srgb, var(--heat-med) 28%, transparent); }
.pill.low { color: var(--heat-low); }
.pill.pending { color: var(--signal); }
.pill.failed { color: var(--warn); }
.pill.time { color: var(--ink-1); }

.composer {
  grid-area: composer;
  position: sticky;
  bottom: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 10px 16px var(--dock-pad);
  background: color-mix(in srgb, var(--bg-0) 82%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}

textarea, input[type="password"] {
  width: 100%;
  border: 1px solid var(--line-2);
  background: var(--bg-2);
  color: var(--ink-0);
  border-radius: 14px;
  padding: 13px 14px;
  font-size: 16px;
  font-family: var(--font-ui);
  line-height: 1.4;
  resize: none;
}

textarea:focus, input:focus {
  outline: 2px solid color-mix(in srgb, var(--signal) 55%, transparent);
  outline-offset: 1px;
}

.composer-side {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-end;
  gap: 6px;
  min-width: 96px;
}

.add {
  appearance: none;
  border: 0;
  background: var(--signal);
  color: var(--signal-ink);
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 600;
  min-height: 48px;
  min-width: 96px;
  padding: 0 20px;
  border-radius: 14px;
  cursor: pointer;
}

.add:disabled { opacity: 0.5; }
.add, .filter-row button, .actions a, .actions button, .chip, .row {
  touch-action: manipulation;
}

.text-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  padding: 8px;
  cursor: pointer;
}

.toast {
  margin: 0;
  min-height: 0;
  color: var(--ink-2);
  font-size: 0.72rem;
  max-width: 96px;
}

.toast.error { color: var(--warn); }

.filters {
  grid-area: filters;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 8px;
  background: color-mix(in srgb, var(--bg-0) 88%, transparent);
  border-top: 1px solid var(--line);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar { display: none; }

.filter-group {
  min-width: 0;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  padding-right: 8px;
  border-right: 1px solid var(--line);
}

.subjects-group { border-right: 0; }

.filter-label {
  display: none;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 6px;
}

.filter-cluster,
.filters {
  overflow: hidden;
}

.filter-row {
  display: flex;
  gap: 6px;
  overflow: visible;
  padding-bottom: 2px;
}

.filter-row::-webkit-scrollbar { display: none; }

.filter-row button {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 8px 12px;
  min-height: 40px;
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
}

.filter-row button.on {
  background: var(--ink-0);
  border-color: var(--ink-0);
  color: var(--bg-0);
}

.deck {
  grid-area: deck;
  min-height: 0;
  overflow: auto;
  padding: 4px 16px 18px;
  overscroll-behavior: contain;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 14px 18px;
  overflow: hidden;
  touch-action: pan-y;
}

.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--ink-3);
}

.card.high::before { background: var(--heat-high); }
.card.med::before { background: var(--heat-med); }
.card.low::before { background: var(--heat-low); }
.card.pending::before { background: var(--signal); }
.card.failed { border-color: color-mix(in srgb, var(--warn) 32%, var(--line)); }
.card.failed::before { background: var(--warn); }
.card.selected { border-color: var(--line-2); box-shadow: inset 0 0 0 1px var(--line-2); }

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 8px;
}

.byline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--ink-2);
  font-size: 0.78rem;
  min-width: 0;
}

.byline .origin {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.badges {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  justify-content: flex-end;
  flex-shrink: 0;
}

.card h2 {
  font-family: var(--font-display);
  font-size: 1.28rem;
  font-weight: 500;
  line-height: 1.22;
  letter-spacing: -0.025em;
  margin: 0 0 10px;
  overflow-wrap: anywhere;
}

.list:not(.is-rows) .card h2,
.list:not(.is-rows) .card .summary {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.list:not(.is-rows) .card h2 { -webkit-line-clamp: 3; }
.list:not(.is-rows) .card .summary { -webkit-line-clamp: 4; }

.summary {
  margin: 0 0 10px;
  color: var(--ink-1);
  font-size: 0.98rem;
  line-height: 1.5;
}

.why {
  margin: 0 0 12px;
  color: var(--ink-2);
  font-size: 0.82rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 12px;
}

.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--ink-1);
  font-size: 0.72rem;
  padding: 5px 9px;
  border-radius: 999px;
  cursor: pointer;
}

.chip:hover { border-color: var(--line-2); color: var(--ink-0); }

.actions {
  display: flex;
  gap: 8px;
}

.actions a,
.actions button,
.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 12px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
}

.actions a,
.btn.primary {
  background: var(--ink-0);
  color: var(--bg-0);
  border: 0;
}

.actions button,
.btn.ghost {
  appearance: none;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--ink-0);
}

.card.swiping { user-select: none; }
.card.snap-done { transform: translateX(-28%); opacity: 0.35; }

.empty, .error-state {
  padding: 36px 8px 24px;
  color: var(--ink-2);
}

.empty h2, .error-state h2 {
  font-family: var(--font-display);
  color: var(--ink-0);
  font-size: 1.6rem;
  font-weight: 500;
  margin: 0 0 8px;
}

.row {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  border-radius: 12px;
  padding: 12px 10px 12px 12px;
  display: grid;
  grid-template-columns: 4px 1fr;
  gap: 12px;
  cursor: pointer;
  min-height: 64px;
}

.row:hover { background: var(--bg-2); }
.row.on {
  background: var(--bg-2);
  border-color: var(--line);
}

.row-heat { border-radius: 99px; background: var(--ink-3); }
.row.high .row-heat { background: var(--heat-high); }
.row.med .row-heat { background: var(--heat-med); }
.row.low .row-heat { background: var(--heat-low); }
.row.pending .row-heat { background: var(--signal); }
.row.failed .row-heat { background: var(--warn); }

.row-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 1.02rem;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin-bottom: 4px;
}

.row-meta {
  display: block;
  color: var(--ink-2);
  font-size: 0.75rem;
}

.pane {
  grid-area: pane;
  min-height: 0;
  overflow: auto;
  padding: 8px 28px 32px 8px;
  border-left: 1px solid var(--line);
}

.pane-inner .card {
  background: transparent;
  border: 0;
  padding: 8px 4px 16px 14px;
  box-shadow: none;
}

.pane-inner .card h2 {
  font-size: clamp(1.8rem, 3vw, 2.5rem);
  margin-bottom: 16px;
}

.pane-inner .summary {
  font-size: 1.08rem;
  max-width: 40rem;
}

.pane-empty {
  color: var(--ink-2);
  padding: 48px 12px;
}

.pane-empty h2 {
  font-family: var(--font-display);
  color: var(--ink-0);
  font-weight: 500;
  font-size: 2rem;
  margin: 0 0 8px;
}

.login-body { display: flex; }
.login-shell {
  margin: auto;
  width: min(420px, calc(100% - 32px));
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 48px 0;
}

.login-card {
  background: var(--bg-2);
  padding: 22px;
  border-radius: 18px;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card label {
  font-size: 0.8rem;
  color: var(--ink-2);
}

.error {
  color: var(--warn);
  margin: 0;
  font-size: 0.9rem;
}

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

@media (min-width: 720px) {
  .app {
    grid-template-areas:
      "mast"
      "composer"
      "filters"
      "deck";
    grid-template-rows: auto auto auto 1fr;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
  }

  .mast { padding-top: 28px; padding-left: 24px; padding-right: 24px; }
  .brand-copy h1 { font-size: 1.7rem; }

  .composer {
    position: sticky;
    top: 0;
    bottom: auto;
    border-top: 0;
    border-bottom: 1px solid var(--line);
    padding: 8px 24px 14px;
  }

  .filters {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px 16px;
    border-top: 0;
    padding: 8px 24px 12px;
    background: transparent;
    overflow: visible;
  }

  .filter-group {
    border-right: 0;
    padding-right: 0;
    display: block;
  }

  .filter-label { display: none; }
  .deck { padding: 8px 24px 40px; }

  .list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }

  .list.is-rows {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
}

@media (min-width: 1100px) {
  .app {
    max-width: none;
    height: 100dvh;
    grid-template-areas:
      "mast composer composer"
      "filters deck pane";
    grid-template-columns: 230px minmax(320px, 400px) 1fr;
    grid-template-rows: auto 1fr;
  }

  .mast {
    border-bottom: 1px solid var(--line);
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
  }

  .lede { display: none; }

  .mast-meta { justify-content: flex-start; }

  .composer {
    border-bottom: 1px solid var(--line);
    padding: 12px 24px;
  }

  .filter-label { display: block; }

  .filters {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 16px;
    padding: 20px 16px 24px 24px;
    border-right: 1px solid var(--line);
    overflow: auto;
  }

  .filter-row {
    flex-wrap: wrap;
    overflow: visible;
  }

  .deck {
    padding: 12px 8px 24px 12px;
    border-right: 1px solid var(--line);
  }

  .pane { display: block; }

  .list {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
}

@media (max-width: 1099px) {
  .pane { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  .card { transition: none !important; }
}

@media (prefers-reduced-motion: no-preference) {
  .card {
    animation: rise 0.34s ease both;
  }

  @keyframes rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
  }
}
