/* Zettel — paper & ink.
   Light: slips of paper in a wooden box. Dark: the same box at night.
   Your words are set in a serif; only the chrome is sans. */

:root {
  /* Paper (light) */
  --bg: #faf7f2;
  --bg-soft: #f3eee5;
  --card: #fffdf9;
  --card-hi: #f6f1e7;
  --ink: #2a2622;
  --ink-soft: #5d564c;
  --ink-faint: #948a79;
  --accent: #b5654a;
  --accent-soft: #dcae9c;
  --accent-wash: #f7ece6;
  --line: #e5ded3;
  --good: #4f7a5c;
  --bad: #a8503f;
  --shadow: 0 1px 2px rgba(42, 38, 34, 0.05), 0 6px 18px rgba(42, 38, 34, 0.06);
  --shadow-lift: 0 2px 4px rgba(42, 38, 34, 0.07), 0 12px 32px rgba(42, 38, 34, 0.1);

  --radius: 10px;
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-text: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Ink (dark) — warm, like aged paper by lamplight */
    --bg: #16130f;
    --bg-soft: #1d1914;
    --card: #221d17;
    --card-hi: #2b251d;
    --ink: #ece5d8;
    --ink-soft: #b4aa99;
    --ink-faint: #7e7565;
    --accent: #d98a6a;
    --accent-soft: #8b5540;
    --accent-wash: #2c211a;
    --line: #332c23;
    --good: #83b08c;
    --bad: #d98a7a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lift: 0 2px 6px rgba(0, 0, 0, 0.4), 0 16px 40px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
a { color: var(--accent); }

/* ---- Gate ---- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card {
  max-width: 350px; text-align: center; background: var(--card);
  border: 1px solid var(--line); border-radius: 14px; padding: 38px 30px 32px; box-shadow: var(--shadow);
}
.gate-card p { color: var(--ink-soft); font-size: 14px; line-height: 1.55; margin: 6px 0 0; }
.gate-card form { display: flex; gap: 8px; margin-top: 22px; }
.gate-card input { flex: 1; }

.mark {
  width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 12px;
  display: grid; place-items: center; font-family: var(--font-text);
  font-weight: 600; font-size: 27px; color: #fffdf9; background: var(--accent);
}
.mark.small { width: 25px; height: 25px; border-radius: 7px; font-size: 15px; }

h1 { margin: 0; font-family: var(--font-text); font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }

/* ---- Inputs ---- */
input, textarea {
  background: var(--bg-soft); border: 1px solid var(--line); color: var(--ink);
  border-radius: 8px; padding: 11px 13px; font-size: 15px; font-family: var(--font-ui);
  width: 100%; outline: none; transition: border-color 0.15s, background 0.15s;
}
input:focus, textarea:focus { border-color: var(--accent-soft); background: var(--card); }
textarea { resize: vertical; line-height: 1.6; font-family: var(--font-text); font-size: 16px; }
::placeholder { color: var(--ink-faint); }

button[type="submit"], .btn {
  background: var(--accent); color: #fffdf9; border: none;
  border-radius: 8px; padding: 11px 20px; font-weight: 600; font-size: 14.5px; white-space: nowrap;
  transition: filter 0.15s;
}
button[type="submit"]:hover, .btn:hover { filter: brightness(1.07); }
button[type="submit"]:active, .btn:active { transform: translateY(1px); }

/* ---- Shell ---- */
.app { max-width: 700px; margin: 0 auto; padding: 0 18px 96px; }
.topbar { position: sticky; top: 0; z-index: 5; padding: 20px 0 12px; background: var(--bg); }
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -18px; height: 18px;
  background: linear-gradient(var(--bg), transparent); pointer-events: none;
}
.topline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand {
  display: flex; align-items: center; gap: 9px;
  font-family: var(--font-text); font-weight: 600; font-size: 19px; letter-spacing: -0.01em;
}
.brain-select {
  width: auto; padding: 6px 10px; font-size: 13px; border-radius: 7px;
  background: var(--card); color: var(--ink-soft); border: 1px solid var(--line);
}
.visiting {
  margin: 12px 0 0; padding: 8px 12px; border-radius: 7px; font-size: 12.5px;
  background: var(--accent-wash); color: var(--accent); border: 1px solid var(--accent-soft);
}
.tabs {
  display: flex; gap: 2px; margin-top: 16px; border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: 1 0 auto; background: none; border: none; color: var(--ink-faint);
  padding: 8px 6px 10px; font-weight: 550; font-size: 13px; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color 0.15s;
}
@media (min-width: 480px) { .tabs button { padding: 8px 14px 10px; font-size: 13.5px; } }
.tabs button:hover { color: var(--ink-soft); }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }
.badge {
  background: var(--accent); color: #fffdf9; font-size: 10.5px; font-weight: 700;
  border-radius: 999px; padding: 1px 6px; margin-left: 4px; vertical-align: 1px;
}

.view { display: none; animation: fade 0.2s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* ---- Capture ---- */
.capture { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.capture textarea { min-height: 130px; }
.capture-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hint { color: var(--ink-faint); font-size: 12.5px; }
.recent { margin-top: 28px; display: flex; flex-direction: column; gap: 12px; }

.lead { color: var(--ink-soft); font-size: 14px; margin: 20px 0 14px; }
.empty { color: var(--ink-faint); font-size: 14px; text-align: center; padding: 48px 20px; line-height: 1.6; }

/* ---- Cards: slips of paper ---- */
.list { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.zcard {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); transition: box-shadow 0.16s, border-color 0.16s, transform 0.16s;
}
.zcard.tappable { cursor: pointer; }
.zcard.tappable:hover { box-shadow: var(--shadow-lift); border-color: var(--accent-soft); transform: translateY(-1px); }
.zcard .z-title {
  font-family: var(--font-text); font-weight: 600; font-size: 17px;
  margin: 0 0 5px; letter-spacing: -0.01em; line-height: 1.3;
}
.zcard .z-body { font-family: var(--font-text); color: var(--ink); font-size: 15.5px; line-height: 1.6; margin: 0; }
.zcard .z-summary { color: var(--ink-faint); font-size: 13px; line-height: 1.5; margin: 10px 0 0; }
.zcard .z-meta { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; margin-top: 12px; }

.chip {
  font-size: 12px; color: var(--ink-soft); background: var(--bg-soft);
  border: 1px solid var(--line); border-radius: 5px; padding: 3px 8px; text-decoration: none;
}
.chip.lang { color: var(--accent); background: var(--accent-wash); border-color: var(--accent-wash); text-transform: uppercase; letter-spacing: 0.04em; font-size: 10.5px; font-weight: 600; }
.pending { font-size: 12px; color: var(--ink-faint); font-style: italic; }
.pending::before { content: "◌ "; font-style: normal; }

/* ---- Inbox ---- */
.sugg {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.sugg h3 {
  margin: 0 0 10px; font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 700;
}
.sugg .pair { display: flex; flex-direction: column; gap: 9px; margin: 0 0 14px; }
.sugg .pair .side {
  font-family: var(--font-text); font-size: 15px; color: var(--ink); line-height: 1.5;
  border-left: 2px solid var(--accent-soft); padding-left: 12px;
}
.sugg .link-word { color: var(--ink-faint); font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase; padding-left: 14px; }
.sugg .actions { display: flex; gap: 8px; align-items: center; }
.sugg .score { color: var(--ink-faint); font-size: 12px; margin-left: auto; }

.tagline { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin-bottom: 9px; }
.tag-suggest {
  background: var(--accent-wash); border: 1px solid var(--accent-soft); color: var(--accent);
  border-radius: 5px; padding: 4px 11px; font-size: 13px; font-weight: 550;
}

.mini {
  padding: 6px 12px; border-radius: 7px; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--line); background: var(--card); color: var(--ink-soft);
  transition: border-color 0.15s, color 0.15s;
}
.mini:hover { border-color: var(--ink-faint); color: var(--ink); }
.mini.yes { border-color: var(--good); color: var(--good); }
.mini.yes:hover { background: var(--good); color: var(--card); }
.mini.no:hover { border-color: var(--bad); color: var(--bad); }

/* ---- Graph ---- */
.graph-controls { display: flex; align-items: center; gap: 16px; margin: 20px 0 10px; }
.toggle { display: flex; align-items: center; gap: 7px; color: var(--ink-soft); font-size: 13px; cursor: pointer; }
.toggle input { width: auto; accent-color: var(--accent); }
.graph-wrap {
  height: calc(100dvh - 250px); min-height: 340px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  touch-action: none; box-shadow: var(--shadow);
}
#graph-canvas { width: 100%; height: 100%; display: block; }
.graph-legend { color: var(--ink-faint); font-size: 12px; margin-top: 10px; }
.graph-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: middle; margin-right: 3px; }
.graph-legend .dot.tag { background: var(--accent); }
.graph-legend .dot.zettel { background: var(--ink-faint); }

/* ---- Spark ---- */
#spark-card .zcard:first-child { border-color: var(--accent-soft); }
.spark-connects { margin-top: 20px; display: flex; flex-direction: column; gap: 12px; }
.spark-connects h4 {
  margin: 0; font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 700;
}

/* ---- Vocabulary ---- */
.vocab-row { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.vocab-row .vname { flex: 1 1 auto; font-size: 14.5px; }
/* On a phone, let the tag name own its line so the buttons never squeeze it. */
@media (max-width: 479px) {
  .vocab-row .vname { flex: 1 1 100%; }
  .vocab-row .vuses { order: -1; }
}
.vocab-row .vuses { color: var(--ink-faint); font-size: 12px; }
.vocab-row .vprop {
  color: var(--accent); background: var(--accent-wash); font-size: 10px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; border-radius: 4px; padding: 2px 6px;
}
.vocab-row button {
  background: none; border: 1px solid var(--line); color: var(--ink-faint);
  border-radius: 6px; padding: 4px 9px; font-size: 12px;
}
.vocab-row button:hover { border-color: var(--ink-faint); color: var(--ink); }

/* ---- Modal ---- */
.modal {
  position: fixed; inset: 0; background: rgba(20, 16, 12, 0.42); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 20px; z-index: 30; animation: fade 0.16s ease;
}
.modal-card {
  position: relative; max-width: 480px; width: 100%; max-height: 82dvh; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 26px 26px 28px; box-shadow: var(--shadow-lift);
}
.modal-close {
  position: absolute; top: 14px; right: 16px; background: none; border: none;
  color: var(--ink-faint); font-size: 22px; line-height: 1; padding: 2px 6px; border-radius: 6px;
}
.modal-close:hover { color: var(--ink); background: var(--bg-soft); }
.modal-card .z-title { font-family: var(--font-text); font-size: 20px; font-weight: 600; margin: 0 26px 8px 0; line-height: 1.25; }
.modal-card .z-body { font-family: var(--font-text); font-size: 16px; line-height: 1.65; margin: 0; }
.modal-card .z-summary { color: var(--ink-faint); font-size: 13.5px; line-height: 1.55; margin-top: 12px; }
.modal-card h4 {
  margin: 22px 0 8px; font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-faint); font-weight: 700;
}
.modal-card .conn-item {
  font-family: var(--font-text); color: var(--ink-soft); font-size: 14.5px;
  padding: 9px 0; border-top: 1px solid var(--line); transition: color 0.15s;
}
.modal-card .conn-item:hover { color: var(--accent); }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); border: none;
  padding: 11px 20px; border-radius: 8px; box-shadow: var(--shadow-lift); font-size: 14px;
  z-index: 40; animation: rise 0.22s ease;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.error { color: var(--bad); font-size: 13px; margin-top: 12px !important; }
