/* Paper Deck — calm, readable, tablet-first. */

:root {
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f2f7;
  --text: #1f2333;
  --text-soft: #6b7186;
  --border: #e4e6ef;
  --shadow: 0 1px 3px rgba(24, 28, 45, 0.07), 0 6px 18px rgba(24, 28, 45, 0.05);
  --radius: 14px;
  --status-toread: #64748b;
  --status-reading: #d97706;
  --status-read: #059669;
  --status-revisit: #7c3aed;
}
[data-theme='dark'] {
  --accent: #818cf8;
  --accent-soft: #2b2e4a;
  --bg: #14161f;
  --surface: #1d2029;
  --surface-2: #262a36;
  --text: #e8eaf2;
  --text-soft: #9ba1b5;
  --border: #333747;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.3);
  --status-toread: #94a3b8;
  --status-reading: #fbbf24;
  --status-read: #34d399;
  --status-revisit: #a78bfa;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter',
    'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
#root { height: 100%; display: flex; flex-direction: column; }

.splash {
  height: 100vh; display: flex; flex-direction: column; gap: 10px;
  align-items: center; justify-content: center;
  color: var(--text-soft); font-size: 18px; letter-spacing: 0.4px;
}
.splash-mark { font-size: 44px; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 18px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.brand {
  font-weight: 700; font-size: 19px; letter-spacing: -0.2px;
  display: flex; align-items: center; gap: 8px; margin-right: 10px;
  white-space: nowrap;
}
.nav { display: flex; gap: 4px; flex: 1; }
.nav button {
  border: none; background: none; padding: 10px 16px; border-radius: 10px;
  font-size: 15px; color: var(--text-soft); min-height: 44px;
}
.nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.iconbtn {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 10px; min-width: 44px; min-height: 44px; font-size: 18px;
}

/* ------------------------------------------------------------- library */
.page { flex: 1; overflow-y: auto; padding: 18px; }
.lib-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 6px; }
.search {
  flex: 1 1 260px; padding: 12px 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); min-height: 46px;
  outline: none;
}
.search:focus { border-color: var(--accent); }
.sort-select {
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); min-height: 46px;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 16px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-soft);
  padding: 8px 14px; border-radius: 999px; font-size: 13.5px; min-height: 38px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; text-align: left; display: flex; flex-direction: column;
  gap: 8px; transition: transform 0.08s ease; min-height: 150px;
}
.card:active { transform: scale(0.985); }
.card h3 { margin: 0; font-size: 16px; line-height: 1.35; font-weight: 650; }
.card .meta { color: var(--text-soft); font-size: 13px; }
.card .foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; }
.tag-row { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px; font-weight: 550;
}
.status-pill {
  font-size: 12px; font-weight: 650; padding: 4px 10px; border-radius: 999px;
  color: #fff; white-space: nowrap;
}
.stars { color: #f59e0b; font-size: 14px; letter-spacing: 1px; }
.stars .off { color: var(--border); }
.empty { text-align: center; color: var(--text-soft); padding: 70px 20px; font-size: 15px; }
.empty .big { font-size: 40px; margin-bottom: 10px; }

/* -------------------------------------------------------------- reader */
.reader { flex: 1; display: flex; min-height: 0; }
.pdf-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--surface-2); }
.pdf-toolbar {
  display: flex; gap: 6px; align-items: center; padding: 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.tool {
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  min-width: 46px; min-height: 46px; font-size: 17px;
}
.tool.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tool-spacer { flex: 1; }
.pdf-scroll { flex: 1; overflow: auto; padding: 14px; }
.pdf-page {
  position: relative; margin: 0 auto 14px; box-shadow: var(--shadow);
  background: #fff; border-radius: 4px; overflow: hidden;
}
.pdf-page canvas { display: block; }
.pdf-page .ink {
  position: absolute; inset: 0; touch-action: pan-y;
}
.pdf-page .ink.drawing { touch-action: none; }
.pdf-missing {
  flex: 1; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; color: var(--text-soft); padding: 30px;
  text-align: center;
}

.notes-pane {
  width: 380px; max-width: 45vw; border-left: 1px solid var(--border);
  background: var(--surface); overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.notes-pane h2 { margin: 2px 0 4px; font-size: 17px; line-height: 1.35; }
.notes-pane .paper-meta { color: var(--text-soft); font-size: 13px; margin-bottom: 4px; }
.section { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.section > button {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  background: var(--surface-2); border: none; padding: 12px 14px;
  font-weight: 600; font-size: 14px; min-height: 46px;
}
.section textarea {
  width: 100%; border: none; background: var(--surface); resize: vertical;
  min-height: 110px; padding: 12px 14px; outline: none; line-height: 1.5; font-size: 14px;
}
.field-row { display: flex; gap: 10px; align-items: center; }
.field-row label { font-size: 13px; color: var(--text-soft); min-width: 52px; }
.field-row select {
  flex: 1; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); min-height: 44px;
}
.star-input button {
  background: none; border: none; font-size: 26px; padding: 4px; color: var(--border);
}
.star-input button.on { color: #f59e0b; }
.save-state { font-size: 12px; color: var(--text-soft); text-align: right; min-height: 16px; }

@media (max-width: 820px) {
  .reader { flex-direction: column; }
  .notes-pane { width: 100%; max-width: none; border-left: none; border-top: 1px solid var(--border); max-height: 45%; }
}

/* ----------------------------------------------------------- add + settings */
.form-page { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.form-page h1, .page h1 { font-size: 22px; margin: 6px 0 2px; }
.hint { color: var(--text-soft); font-size: 13.5px; line-height: 1.5; margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13.5px; font-weight: 600; color: var(--text-soft); }
.field input, .field textarea, .field select {
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); min-height: 46px; outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.btn {
  border: none; border-radius: 12px; padding: 13px 20px; font-weight: 650;
  min-height: 48px; font-size: 15px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: default; }
.inline-add { display: flex; gap: 8px; }
.inline-add input { flex: 1; }

.settings-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow);
}
.settings-card h2 { margin: 0; font-size: 16px; }
.bookmarklet {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  border: 1px dashed var(--accent); border-radius: 12px; padding: 12px 18px;
  font-weight: 650; text-decoration: none; text-align: center;
}
code.mono {
  background: var(--surface-2); padding: 2px 7px; border-radius: 6px;
  font-size: 12.5px; word-break: break-all;
}

/* --------------------------------------------------------------- toast */
.toast {
  position: fixed; bottom: max(24px, env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 12px 22px; border-radius: 999px; font-size: 14.5px; font-weight: 550;
  box-shadow: var(--shadow); z-index: 100; max-width: 86vw;
}
