*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --border: #2a2a3a;
  --accent: #7c5cbf;
  --accent-light: #9d7de0;
  --text: #e0e0f0;
  --text-dim: #888899;
  --danger: #f87171;
  --success: #4ade80;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }

/* ── Layout ── */
#app { display: flex; flex-direction: column; height: 100%; max-width: 640px; margin: 0 auto; }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
header h1 { font-size: 17px; font-weight: 600; letter-spacing: -.3px; }
.header-actions { display: flex; gap: 8px; }

.icon-btn {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-size: 20px; padding: 4px; border-radius: 6px; line-height: 1;
  transition: color .15s;
}
.icon-btn:hover { color: var(--text); }

#main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ── Views ── */
.view { display: none; }
.view.active { display: flex; flex-direction: column; height: 100%; }

/* ── Auth ── */
#view-auth {
  align-items: center; justify-content: center;
  padding: 32px 24px; gap: 24px; text-align: center;
}
.auth-logo { font-size: 48px; }
.auth-title { font-size: 22px; font-weight: 700; }
.auth-subtitle { color: var(--text-dim); font-size: 14px; line-height: 1.5; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.auth-card h2 { font-size: 15px; font-weight: 600; }
.auth-tabs { display: flex; gap: 0; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.auth-tab { flex: 1; padding: 8px; background: none; border: none; color: var(--text-dim); font-size: 13px; cursor: pointer; }
.auth-tab.active { background: var(--accent); color: #fff; }
input[type=email], input[type=password], input[type=text] {
  width: 100%; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 14px; outline: none;
}
input:focus { border-color: var(--accent); }
.btn {
  width: 100%; padding: 10px; background: var(--accent); color: #fff; border: none;
  border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; transition: opacity .15s;
}
.btn:hover { opacity: .9; }
.btn:disabled { opacity: .5; cursor: default; }
.auth-status { font-size: 13px; min-height: 18px; }
.auth-polling { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.auth-polling::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ── Search bar ── */
.search-bar { padding: 10px 14px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.search-input {
  width: 100%; padding: 9px 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; color: var(--text); font-size: 14px; outline: none;
}
.search-input:focus { border-color: var(--accent); }

/* ── Clip list ── */
#clips-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.clip-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer;
  transition: background .1s;
}
.clip-item:hover { background: var(--surface); }
.clip-thumb {
  width: 52px; height: 52px; border-radius: 8px; object-fit: cover;
  background: var(--border); flex-shrink: 0; font-size: 22px;
  display: flex; align-items: center; justify-content: center;
}
.clip-meta { flex: 1; min-width: 0; }
.clip-title { font-size: 14px; font-weight: 500; line-height: 1.35; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clip-domain { font-size: 12px; color: var(--text-dim); }
.clip-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.tag { font-size: 11px; padding: 2px 7px; background: var(--border); border-radius: 10px; color: var(--text-dim); }
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-dim); font-size: 14px; }

/* ── Reader ── */
#view-reader { background: var(--bg); }
.reader-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
.reader-header h2 { font-size: 14px; font-weight: 500; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#reader-body {
  padding: 20px 18px 48px; font-size: 16px; line-height: 1.7;
  max-width: 100%; overflow-x: hidden;
}
#reader-body h1,h2,h3 { margin: 1em 0 .4em; }
#reader-body p { margin-bottom: .9em; }
#reader-body a { color: var(--accent-light); }
#reader-body img { max-width: 100%; border-radius: 8px; margin: 8px 0; }
#reader-body pre { background: var(--surface); padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
mark { background: rgba(124,92,191,.35); color: inherit; border-radius: 2px; }

/* ── Nav bar ── */
#nav-bar {
  display: flex; border-top: 1px solid var(--border);
  background: var(--bg); position: sticky; bottom: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 3px; padding: 10px 0; border: none; background: none;
  color: var(--text-dim); cursor: pointer; font-size: 11px; transition: color .15s;
}
.nav-btn.active { color: var(--accent-light); }
.nav-btn .nav-icon { font-size: 22px; }

/* ── Offline badge ── */
.offline-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 3px 8px; border-radius: 20px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-dim);
}

/* ── Clip form ── */
.clip-form-wrap {
  padding: 24px 16px; display: flex; flex-direction: column; gap: 12px;
}
.clip-form-title { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
#clip-url-input {
  width: 100%; padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 14px;
}
#clip-url-input:focus { outline: none; border-color: var(--accent); }
#clip-queue-list { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.queue-item {
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  font-size: 13px; color: var(--text-dim); word-break: break-all;
}

/* ── Knowledge Graph ── */
#view-graph { position: relative; overflow: hidden; }
#graph-svg { display: block; width: 100%; height: 100%; }
#graph-svg .link { stroke: var(--border); stroke-opacity: 0.6; }
#graph-svg .node circle { fill: var(--accent); stroke: var(--bg); stroke-width: 2px; cursor: pointer; transition: fill .15s; }
#graph-svg .node circle:hover { fill: var(--accent-light); }
#graph-svg .node text { fill: var(--text-dim); font-size: 10px; pointer-events: none; }
.graph-tooltip {
  position: absolute; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; font-size: 12px; max-width: 200px;
  pointer-events: none; z-index: 20; line-height: 1.5;
}
.graph-tooltip strong { display: block; color: var(--text); margin-bottom: 2px; }
.graph-tooltip span { color: var(--text-dim); }

/* ── Misc ── */
.hidden { display: none !important; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; margin: 32px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ── */
@media (min-width: 640px) {
  #app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
