/* ScribeMind — aged journal paper */

:root {
  --paper: #ece1c8;
  --paper-light: #f5eedb;
  --paper-card: #f1e8d2;
  --paper-dark: #ddceac;
  --ink: #3b3226;
  --ink-soft: #71624c;
  --ink-faint: #9c8c72;
  --leather: #7d5a38;
  --rust: #a4552f;
  --sage: #6d7a58;
  --line: #d9c9a6;
  --rule-blue: rgba(110, 130, 150, 0.25);
  --shadow: 0 1px 3px rgba(59, 50, 38, 0.14), 0 4px 14px rgba(59, 50, 38, 0.08);
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--serif);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(255, 250, 235, 0.55), transparent 55%),
    radial-gradient(ellipse at 90% 100%, rgba(120, 90, 50, 0.10), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.055'/%3E%3C/svg%3E");
  -webkit-font-smoothing: antialiased;
}

/* ---------- shell ---------- */

.app-header {
  text-align: center;
  padding: 14px 16px 6px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--leather);
  font-variant: small-caps;
}

.app-header .tagline {
  margin: 2px 0 0;
  font-size: 0.72rem;
  font-style: italic;
  color: var(--ink-faint);
  letter-spacing: 0.06em;
}

main#view {
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 14px 96px;
}

/* nav */
nav.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  background: linear-gradient(180deg, var(--paper-light), var(--paper-card));
  border-top: 1px solid var(--line);
  box-shadow: 0 -3px 14px rgba(59, 50, 38, 0.12);
  padding: 6px 0 max(8px, env(safe-area-inset-bottom));
  z-index: 40;
}

nav.tabs a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  padding: 4px 0 2px;
}

nav.tabs a svg {
  display: block;
  margin: 0 auto 2px;
  width: 22px;
  height: 22px;
  stroke: currentColor;
}

nav.tabs a.active { color: var(--rust); }

@media (min-width: 720px) {
  nav.tabs {
    position: static;
    max-width: 760px;
    margin: 4px auto 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 4px 0;
  }
  nav.tabs a { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 0.85rem; padding: 9px 0; }
  nav.tabs a svg { margin: 0; width: 18px; height: 18px; }
  main#view { padding-bottom: 40px; }
}

/* ---------- shared bits ---------- */

.card {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin: 12px 0;
}

.card .body { white-space: pre-wrap; line-height: 1.5; margin: 6px 0; }

.meta {
  font-size: 0.72rem;
  color: var(--ink-faint);
  font-style: italic;
}

.badge {
  display: inline-block;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-style: normal;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  background: var(--paper-light);
}

.badge.fleeting { color: var(--sage); border-color: rgba(109, 122, 88, 0.4); }
.badge.literature { color: #5c6b7a; border-color: rgba(92, 107, 122, 0.4); }
.badge.permanent { color: var(--rust); border-color: rgba(164, 85, 47, 0.4); }
.badge.pending { color: #8a6d1f; border-color: rgba(138, 109, 31, 0.45); background: #f3ead0; }

h2.section {
  font-size: 0.95rem;
  font-variant: small-caps;
  letter-spacing: 0.12em;
  color: var(--leather);
  border-bottom: 1px solid var(--line);
  padding-bottom: 5px;
  margin: 22px 0 4px;
}

button, .btn {
  font-family: var(--serif);
  font-size: 0.88rem;
  color: var(--paper-light);
  background: linear-gradient(180deg, #8a6540, var(--leather));
  border: 1px solid #6a4c2e;
  border-radius: 7px;
  padding: 9px 18px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(59, 50, 38, 0.25);
}

button:active { transform: translateY(1px); }

button.secondary {
  color: var(--ink-soft);
  background: var(--paper-light);
  border: 1px solid var(--line);
}

button.danger {
  color: #fff;
  background: linear-gradient(180deg, #b0603a, var(--rust));
  border-color: #8c4726;
}

button.small { font-size: 0.76rem; padding: 5px 12px; }

button.primary-big {
  width: 100%;
  font-size: 1.05rem;
  padding: 14px;
  letter-spacing: 0.05em;
}

button:disabled { opacity: 0.5; cursor: default; }

input[type='text'], input[type='search'], input[type='password'], textarea, select {
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--ink);
  background: var(--paper-light);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  width: 100%;
  outline: none;
}

input:focus, textarea:focus, select:focus { border-color: var(--leather); }

textarea { resize: vertical; min-height: 90px; line-height: 1.6; }

textarea.ruled {
  min-height: 160px;
  font-size: 1.05rem;
  line-height: 28px;
  padding-top: 6px;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 27px,
    var(--rule-blue) 27px,
    var(--rule-blue) 28px
  );
  background-attachment: local;
}

.field { margin: 10px 0; }
.field label {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin-bottom: 4px;
  font-variant: small-caps;
}

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.right { justify-content: flex-end; }
.grow { flex: 1; }

.empty {
  text-align: center;
  color: var(--ink-faint);
  font-style: italic;
  padding: 28px 10px;
}

/* segmented control */
.segmented {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  background: var(--paper-light);
  margin: 10px 0;
}

.segmented button {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  color: var(--ink-soft);
  padding: 11px 0;
  font-size: 0.92rem;
}

.segmented button.active {
  background: linear-gradient(180deg, #8a6540, var(--leather));
  color: var(--paper-light);
}

/* toast */
#toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper-light);
  font-size: 0.85rem;
  padding: 9px 20px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 60;
  max-width: 86vw;
  text-align: center;
}

#toast.show { opacity: 0.94; }

/* auth overlay */
#auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--paper);
  background-image: inherit;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#auth-overlay .card { max-width: 340px; width: 100%; text-align: center; }
#auth-overlay h2 { font-variant: small-caps; letter-spacing: 0.12em; color: var(--leather); margin: 4px 0 2px; }
#auth-overlay .err { color: var(--rust); font-size: 0.8rem; min-height: 1.1em; margin: 6px 0 0; }

/* promote panel */
.promote-panel {
  border-top: 1px dashed var(--line);
  margin-top: 12px;
  padding-top: 12px;
}

.original-note {
  font-size: 0.85rem;
  font-style: italic;
  color: var(--ink-soft);
  border-left: 3px solid var(--paper-dark);
  padding: 4px 10px;
  margin: 8px 0;
  white-space: pre-wrap;
}

.link-row {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--paper-light);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
  margin: 6px 0;
  font-size: 0.85rem;
}

.link-row .snippet { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-row select { width: auto; font-size: 0.8rem; padding: 5px 8px; }
.link-row .remove { background: none; border: none; box-shadow: none; color: var(--rust); font-size: 1rem; padding: 0 4px; }

.search-results {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper-light);
  max-height: 180px;
  overflow-y: auto;
  margin-top: 4px;
}

.search-results .item {
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}

.search-results .item:last-child { border-bottom: none; }
.search-results .item:hover { background: var(--paper-card); }

/* graph */
#graph-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-light);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin: 12px 0;
  height: 340px;
}

@media (min-width: 720px) { #graph-wrap { height: 440px; } }

#graph-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.graph-controls {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.graph-controls button {
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--ink-soft);
  background: var(--paper-card);
  border: 1px solid var(--line);
}

/* note detail traversal */
.trav-card {
  display: block;
  text-decoration: none;
  color: var(--ink);
}

.trav-card .rel {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--rust);
}

.trav-card:active { background: var(--paper-light); }

a.wiki { color: var(--leather); }

/* filter chips */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.chips button {
  font-size: 0.78rem;
  padding: 5px 14px;
  border-radius: 999px;
  color: var(--ink-soft);
  background: var(--paper-light);
  border: 1px solid var(--line);
  box-shadow: none;
}
.chips button.active {
  color: var(--paper-light);
  background: var(--leather);
  border-color: #6a4c2e;
}

/* scan */
.scan-candidate { display: flex; gap: 10px; align-items: flex-start; margin: 8px 0; }
.scan-candidate input[type='checkbox'] { margin-top: 12px; width: 18px; height: 18px; accent-color: var(--leather); }
.scan-candidate textarea { min-height: 60px; font-size: 0.9rem; }

#scan-preview { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); margin: 8px 0; }

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--paper-dark);
  border-top-color: var(--leather);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -3px;
  margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }
