:root {
  --ink: #1A2238;
  --ink-soft: #2C3654;
  --paper: #E6E3D8;
  --card: #FBFAF6;
  --brass: #B6862F;
  --brass-soft: #D9B66A;
  --stamp: #8C2F26;
  --line: #CFC9B8;
  --text: #20202a;
  --text-muted: #5b5a52;

  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;

  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  height: 100dvh;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  position: relative;
  box-shadow: 0 0 40px rgba(0,0,0,0.08);
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) 18px 12px;
  background: var(--ink);
  color: var(--card);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-seal { width: 30px; height: 30px; border-radius: 50%; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-family: var(--serif); font-weight: 600; font-size: 19px; letter-spacing: 0.2px; }
.brand-tag { font-family: var(--mono); font-size: 10px; letter-spacing: .06em; color: var(--brass-soft); text-transform: uppercase; }

.install-btn {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--brass-soft);
  padding: 7px 12px;
  border-radius: 3px;
}
.hidden { display: none !important; }

/* ===== Main view ===== */
.view {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 16px 96px;
  -webkit-overflow-scrolling: touch;
}

.view-heading {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  margin: 4px 0 4px;
}
.view-sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 16px;
  display: block;
}

.search {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 3px;
  font-family: var(--sans);
  font-size: 14px;
  margin-bottom: 16px;
}
.search:focus { outline: 2px solid var(--brass); outline-offset: 1px; }

/* ===== Record card ===== */
.record {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brass);
  border-radius: 2px;
  padding: 14px 14px 12px;
  margin-bottom: 12px;
  position: relative;
  cursor: pointer;
}
.record:hover { border-left-color: var(--stamp); }
.record:focus-visible, button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--stamp);
  outline-offset: 2px;
}

.record-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
  letter-spacing: .03em;
}
.record-no { color: var(--stamp); font-weight: 500; }
.record-tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 2px 6px;
  border: 1px solid var(--brass);
  color: var(--ink);
  border-radius: 2px;
  margin-right: 6px;
}
.record-author {
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 4px;
}
.record-body {
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--text);
  white-space: pre-wrap;
}
.record-foot {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-muted);
}
.endorse {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  color: var(--text-muted);
}
.endorse.active { color: var(--stamp); }
.endorse svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; }

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty .serif { font-family: var(--serif); font-size: 18px; color: var(--ink); display:block; margin-bottom:6px; }

/* ===== Detail view ===== */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-soft);
  margin-bottom: 14px;
}
.detail-card { background: var(--card); border: 1px solid var(--line); padding: 18px; border-radius: 2px; }
.notes { margin-top: 18px; }
.note {
  border-top: 1px solid var(--line);
  padding: 10px 0;
  font-size: 13.5px;
}
.note-meta { font-family: var(--mono); font-size: 10px; color: var(--text-muted); margin-bottom: 3px; }
.note-input-row { display: flex; gap: 8px; margin-top: 12px; }
.note-input-row input {
  flex: 1;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 2px;
  font-family: var(--sans);
  font-size: 13.5px;
}

/* ===== Connections ===== */
.connection {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  padding: 12px 14px;
  border-radius: 2px;
  margin-bottom: 10px;
}
.connection-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--ink);
  color: var(--brass-soft);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-weight: 600; font-size: 15px;
  flex: 0 0 auto;
}
.connection-name { font-weight: 600; font-size: 14px; }
.connection-rel { font-family: var(--mono); font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.add-connection-row { display: flex; gap: 8px; margin-top: 14px; }
.add-connection-row input { flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 2px; font-family: var(--sans); }

/* ===== Profile ===== */
.profile-row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 14px;
  margin-bottom: 12px;
}
.profile-label { font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: 6px; display:block; }
.profile-row input { width: 100%; border: none; font-size: 15px; font-family: var(--sans); padding: 0; background: none; }
.ios-help { font-size: 12.5px; color: var(--text-muted); line-height: 1.5; margin-top: 6px; }
.ios-help b { color: var(--text); }

/* ===== Buttons ===== */
.btn-primary {
  background: var(--ink);
  color: var(--card);
  font-weight: 600;
  font-size: 14px;
  padding: 11px 18px;
  border-radius: 3px;
}
.btn-primary:hover { background: var(--ink-soft); }
.btn-ghost {
  color: var(--ink);
  font-size: 14px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--card);
}
.btn-danger { color: var(--stamp); border-color: var(--stamp); }
.btn-block { width: 100%; }

/* ===== Tabbar ===== */
.tabbar {
  flex: 0 0 auto;
  display: flex;
  background: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 0 8px;
  color: #8A93AE;
  font-size: 10.5px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.tab svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.tab.active { color: var(--brass-soft); }

/* ===== FAB ===== */
.fab {
  position: absolute;
  right: 18px;
  bottom: calc(72px + env(safe-area-inset-bottom));
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--stamp);
  color: var(--card);
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 6px 16px rgba(140,47,38,0.4);
}
.fab:hover { background: #a3392e; }

/* ===== Compose sheet ===== */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(20,24,38,0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--paper);
  border-radius: 14px 14px 0 0;
  padding: 10px 20px max(20px, env(safe-area-inset-bottom));
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.sheet-handle { width: 36px; height: 4px; background: var(--line); border-radius: 2px; margin: 6px auto 14px; }
.sheet h2 { font-family: var(--serif); font-size: 19px; margin: 0 0 14px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: 6px; }
.field textarea, .field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 10px;
  font-family: var(--sans);
  font-size: 14.5px;
  background: var(--card);
  resize: vertical;
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
}
