/* ---------- Design tokens ---------- */
:root {
  color-scheme: dark;
  --bg: #0d1117;
  --bg-elevated: #151b23;
  --bg-card: #161c26;
  --bg-card-hover: #1b2230;
  --border: #262d3a;
  --border-soft: #1e2530;
  --text: #e6e9ef;
  --text-dim: #9aa4b2;
  --text-faint: #636d7e;
  --accent: #a78bfa;
  --accent-dim: #7c5ce2;
  --accent-bg: rgba(167, 139, 250, 0.12);
  --amber: #f5b455;
  --amber-bg: rgba(245, 180, 85, 0.14);
  --blue: #5aa9ff;
  --blue-bg: rgba(90, 169, 255, 0.14);
  --green: #4ade80;
  --green-bg: rgba(74, 222, 128, 0.14);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.14);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.3);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f7f7fb;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #fbfbff;
    --border: #e4e4ee;
    --border-soft: #ececf5;
    --text: #14161f;
    --text-dim: #5c6170;
    --text-faint: #8a8fa0;
    --accent: #7c5ce2;
    --accent-dim: #6a49d1;
    --accent-bg: rgba(124, 92, 226, 0.08);
    --amber: #b4790a;
    --amber-bg: rgba(180, 121, 10, 0.1);
    --blue: #2f7de1;
    --blue-bg: rgba(47, 125, 225, 0.1);
    --green: #16a34a;
    --green-bg: rgba(22, 163, 74, 0.1);
    --red: #dc2626;
    --red-bg: rgba(220, 38, 38, 0.1);
    --shadow-soft: 0 1px 2px rgba(20, 22, 31, 0.06);
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body {
  min-height: 100vh;
  min-height: 100dvh;
}
button, input, textarea {
  font-family: inherit;
  color: inherit;
}
a { color: var(--accent); }
::selection { background: var(--accent-bg); color: var(--accent); }

/* ---------- Layout ---------- */
.app { min-height: 100dvh; }
.main {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 48px;
}
.view { animation: fadein 0.18s ease; }
@keyframes fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--border-soft);
}
.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-emoji { font-size: 22px; line-height: 1; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 16px;
  transition: border-color 0.15s, color 0.15s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

.stats-strip {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  gap: 24px;
  padding: 0 16px 14px;
}
.stat { display: flex; flex-direction: column; gap: 1px; }
.stat-value { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.stat-label { font-size: 11.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- Dump box ---------- */
.dump-box {
  margin-top: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-soft);
}
#dump-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.dump-input {
  flex: 1 1 220px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-width: 0;
}
.dump-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.note-toggle {
  background: none;
  border: 1px dashed var(--border);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.note-toggle:hover { border-color: var(--accent); color: var(--accent); }
.note-toggle.active { border-color: var(--accent); color: var(--accent); border-style: solid; }
.dump-note {
  flex: 1 1 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 14px;
  resize: vertical;
  outline: none;
  min-height: 44px;
}
.dump-note:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }

.dump-submit { margin-left: auto; }

.btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 11px 20px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--accent);
  color: #14101f;
}
.btn-primary:hover { background: var(--accent-dim); color: #fff; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost:hover { border-color: var(--text-dim); }
.btn-approve {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid transparent;
}
.btn-approve:hover { border-color: var(--green); }
.btn-dismiss {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.btn-dismiss:hover { border-color: var(--red); color: var(--red); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  margin-top: 18px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.tab:hover { border-color: var(--accent); color: var(--text); }
.tab.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.search-box { margin-top: 14px; }
.search-box input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }

/* ---------- Feed ---------- */
.feed {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
  animation: card-in 0.25s ease;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.card:hover { background: var(--bg-card-hover); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.card:active { transform: scale(0.995); }

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.card-title {
  font-size: 15.5px;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: -0.005em;
}
.card-meta {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--text-faint);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.card-meta .dot::before { content: "·"; margin: 0 2px; }

.card-summary {
  margin-top: 8px;
  font-size: 13.5px;
  color: var(--text-dim);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chip-row {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.chip {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-dim);
  border: 1px solid var(--border-soft);
  font-weight: 500;
  white-space: nowrap;
}
.chip-topic { }
.status-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.status-chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.status-pending { background: var(--amber-bg); color: var(--amber); }
.status-pending::before { animation: pulse 1.4s ease-in-out infinite; }
.status-processing { background: var(--blue-bg); color: var(--blue); }
.status-processing::before { animation: pulse 1s ease-in-out infinite; }
.status-processed { background: var(--green-bg); color: var(--green); }
.status-failed { background: var(--red-bg); color: var(--red); }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.7); }
}

.proposal-badge {
  margin-left: auto;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--accent);
  white-space: nowrap;
}

.relevance-meter {
  margin-top: 8px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-soft);
  overflow: hidden;
}
.relevance-meter-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

/* ---------- Empty / loading states ---------- */
.empty-state {
  padding: 56px 20px;
  text-align: center;
  color: var(--text-faint);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.empty-state .emoji { font-size: 32px; }
.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Detail view ---------- */
.back-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 16px 0 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: color 0.15s;
}
.back-btn:hover { color: var(--accent); }

.detail-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-top: 8px;
}
.detail-title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.detail-meta {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-faint);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.detail-link {
  display: inline-block;
  margin-top: 12px;
  font-size: 13.5px;
  word-break: break-all;
}
.detail-section { margin-top: 20px; }
.detail-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin: 0 0 8px;
  font-weight: 700;
}
.detail-section p {
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text);
  margin: 0;
}
.claims-list {
  margin: 0;
  padding-left: 18px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-dim);
}
.claims-list li { margin-bottom: 4px; }
.kb-path {
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--text-faint);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.note-block {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13.5px;
  color: var(--text-dim);
  font-style: italic;
}
.proposal-block {
  margin-top: 20px;
  background: var(--accent-bg);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--radius-md);
  padding: 16px;
}
.proposal-block h3 {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin: 0 0 8px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}
.proposal-block p { font-size: 14px; line-height: 1.55; margin: 0 0 14px; color: var(--text); }
.proposal-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.proposal-status-line {
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}
.plane-ref {
  font-weight: 700;
  color: var(--accent);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.error-block {
  margin-top: 16px;
  background: var(--red-bg);
  border: 1px solid color-mix(in srgb, var(--red) 35%, transparent);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 13.5px;
  color: var(--red);
}

/* ---------- Token screen ---------- */
.token-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.token-screen[hidden] { display: none; }
.token-card {
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.token-emoji { font-size: 44px; margin-bottom: 8px; }
.token-card h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: -0.01em; }
.token-sub { color: var(--text-dim); font-size: 14px; margin: 0 0 24px; }
#token-form { display: flex; flex-direction: column; gap: 12px; }
#token-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 16px;
  font-size: 15px;
  outline: none;
  text-align: center;
  letter-spacing: 0.02em;
}
#token-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.token-error { color: var(--red); font-size: 13px; margin-top: 14px; }

/* ---------- Toasts ---------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  width: min(92vw, 380px);
  align-items: center;
}
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
  animation: toast-in 0.2s ease;
  text-align: center;
}
.toast.error { border-color: color-mix(in srgb, var(--red) 40%, var(--border)); color: var(--red); }
.toast.success { border-color: color-mix(in srgb, var(--green) 40%, var(--border)); color: var(--green); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.toast.leaving { animation: toast-out 0.18s ease forwards; }
@keyframes toast-out { to { opacity: 0; transform: translateY(4px); } }

/* ---------- Responsive ---------- */
@media (min-width: 640px) {
  .stats-strip { gap: 32px; }
  .card-title { font-size: 16px; }
}

@media (max-width: 400px) {
  .main { padding: 0 12px 40px; }
  .dump-box { padding: 12px; }
  .card { padding: 14px; }
}
