:root {
  color-scheme: dark;
  --bg: #101613;
  --bg-raise: #18211c;
  --bg-sunken: #0c100e;
  --line: #314239;
  --text: #edf3ee;
  --muted: #a9b8ae;
  --gold: #e0b15a;
  --gold-ink: #2a210f;
  --teal: #8fd0c6;
  --danger: #ffb0a4;
  --ok: #b7e7c6;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --font: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
  --display: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  max-width: 100%;
  overflow-x: hidden;
  color: var(--text);
  font-family: var(--font);
  line-height: 1.45;
  background:
    radial-gradient(900px 420px at 0% -10%, rgba(224, 177, 90, 0.18), transparent 55%),
    radial-gradient(800px 480px at 100% 0%, rgba(143, 208, 198, 0.14), transparent 50%),
    linear-gradient(180deg, #141c18 0%, #0c1210 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(180deg, #000, transparent 80%);
}

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  background: var(--gold);
  color: var(--gold-ink);
  padding: 0.5rem 0.8rem;
  z-index: 5;
}

.skip:focus { top: 0.5rem; }

.top, .panel, .search-panel, .toolbar, .results, .banner, .status, .noscript {
  position: relative;
  width: min(980px, calc(100% - 2rem));
  margin-left: auto;
  margin-right: auto;
}

#vault .search-panel,
#vault .toolbar,
#vault .results,
#vault .banner {
  width: min(1320px, calc(100% - 2rem));
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  align-items: flex-end;
  padding: 2.2rem 0 1rem;
}

.kicker {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
  font-size: 0.75rem;
}

h1, h2, h3 { font-family: var(--display); font-weight: 600; }

h1 { margin: 0.2rem 0; font-size: clamp(2rem, 4vw, 3.3rem); line-height: 1.05; }

h2 { margin: 0 0 0.6rem; font-size: 1.55rem; }

.lede, .hint, .fine { color: var(--muted); }

.lede { max-width: 38rem; margin: 0.4rem 0 0; }

.top-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 0.6rem; }

.hint { margin: 0; font-size: 0.92rem; }

.status {
  min-height: 1.4rem;
  margin-top: 0;
  color: var(--ok);
}

.status[data-tone="err"] { color: var(--danger); }

.panel, .search-panel, dialog {
  background: rgba(24, 33, 28, 0.92);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.panel { padding: 1.3rem 1.3rem 1.4rem; }

.search-panel { padding: 1rem 1.1rem 0.9rem; margin-top: 1rem; }

.inset { margin-top: 0.8rem; box-shadow: none; }

label { display: block; margin: 0.85rem 0 0.35rem; font-size: 0.92rem; }

input, textarea, button { font: inherit; color: inherit; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-sunken);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
}

textarea { resize: vertical; }

input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.button-row, .toolbar, .card-actions, .secret-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.button-row, .toolbar { margin-top: 1rem; }

button, .file-label {
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1rem;
  background: var(--gold);
  color: var(--gold-ink);
  cursor: pointer;
  min-height: 44px;
}

button.secondary, .file-label {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

button.danger { background: transparent; color: var(--danger); border: 1px solid rgba(255, 176, 164, 0.45); }

button:disabled { opacity: 0.6; cursor: wait; }

.icon-btn {
  min-width: 1.75rem;
  min-height: 1.75rem;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}

.icon-btn svg {
  width: 0.95rem;
  height: 0.95rem;
  display: block;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  color: var(--text);
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.icon-btn.danger { color: var(--danger); background: transparent; border-color: transparent; }

.icon-btn.danger:hover,
.icon-btn.danger:focus-visible {
  border-color: rgba(255, 176, 164, 0.45);
}

.file-row { position: relative; margin-top: 1.1rem; }

.file-label { display: inline-flex; align-items: center; }

#vault-file {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.fine { margin-bottom: 0; }

.mono, .value { font-family: var(--mono); font-size: 0.92rem; }

.banner {
  margin-top: 0.8rem;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: rgba(224, 177, 90, 0.12);
  color: var(--gold);
}

.results {
  list-style: none;
  padding: 0;
  margin: 1rem auto 3rem;
  column-width: 240px;
  column-gap: 0.75rem;
}

.results.is-empty {
  column-width: auto;
  columns: 1;
}

.card, .empty {
  background: #1a211e;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 0.8rem 0.9rem;
  break-inside: avoid;
  page-break-inside: avoid;
  -webkit-column-break-inside: avoid;
  display: inline-block;
  width: 100%;
  margin: 0 0 0.75rem;
  vertical-align: top;
  font-size: 0.875rem;
  line-height: 1.35;
  box-shadow: none;
}

.card { cursor: pointer; }
.card:hover { border-color: rgba(255, 255, 255, 0.22); }
.card:focus-visible { border-color: var(--gold); }

.empty { color: var(--muted); }

.card-head {
  display: flex;
  align-items: flex-start;
  gap: 0.25rem;
  margin: 0 0 0.55rem;
}

.card h3 {
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 0;
  flex: 1;
  min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-label {
  margin: -0.25rem 0 0.45rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.card-actions {
  display: flex;
  gap: 0.1rem;
  margin: 0;
}

.tags { display: flex; flex-wrap: wrap; gap: 0.25rem; margin: 0 0 0.45rem; padding: 0; list-style: none; }

.tags li {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 0.4rem;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.5;
}

.card-url {
  display: block;
  color: var(--teal);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
}

.card-url:hover { text-decoration: underline; }

.card-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.15rem 0;
  min-width: 0;
}

.card-k {
  color: var(--muted);
  font-size: 0.7rem;
  flex: 0 0 4.7rem;
}

.card-row .value,
.history .value {
  font-family: var(--mono);
  font-size: 0.8rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notes {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.when { margin: 0.4rem 0 0; color: var(--muted); font-size: 0.7rem; }

.card a { color: var(--teal); }

.history {
  margin: 0.35rem 0 0;
}

.history summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.75rem;
  list-style: none;
}

.history summary::-webkit-details-marker { display: none; }

.history summary::before {
  content: "▸ ";
  color: var(--teal);
}

.history[open] summary::before { content: "▾ "; }

.history[open] summary { margin-bottom: 0.25rem; }

.history ul { list-style: none; margin: 0; padding: 0; }

.history li {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  margin: 0.2rem 0;
  min-width: 0;
}

.history .hist-k {
  color: var(--muted);
  font-size: 0.7rem;
  flex: 0 0 auto;
}

.history time { color: var(--muted); font-size: 0.7rem; flex: 0 0 auto; }

.file-row { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.8rem; }

.wide { grid-column: 1 / -1; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

dialog.note-editor,
#editor {
  width: min(600px, calc(100% - 2rem));
  max-height: calc(100vh - 3rem);
  overflow: auto;
  padding: 0;
  color: var(--text);
  background: #1a211e;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

#editor form {
  display: flex;
  flex-direction: column;
  padding: 1rem 1.1rem 0.55rem;
  gap: 0;
}

.note-title {
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 0;
  padding: 0.15rem 0 0.45rem;
  font-size: 1.15rem;
  font-weight: 600;
  font-family: var(--font);
  line-height: 1.3;
}

.note-subtle {
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 0;
  padding: 0.15rem 0 0.55rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.note-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  padding: 0.15rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.note-row label {
  margin: 0;
  flex: 0 0 5.4rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.note-row input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  border-radius: 0;
  padding: 0.45rem 0;
  font-family: var(--mono);
  font-size: 0.9rem;
}

.note-desc {
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 0;
  resize: none;
  overflow: hidden;
  min-height: 4.5rem;
  padding: 0.7rem 0 0.4rem;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--text);
}

#editor input:focus-visible,
#editor textarea:focus-visible,
#editor button:focus-visible {
  outline: none;
  box-shadow: inset 0 -2px 0 var(--gold);
}

#editor button.icon-btn:focus-visible,
#editor .text-btn:focus-visible {
  box-shadow: none;
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.note-history {
  margin: 0.65rem 0 0.2rem;
  padding-top: 0.45rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.8rem;
}

.note-history h3 {
  margin: 0 0 0.35rem;
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.note-history ul { list-style: none; margin: 0; padding: 0; }

.note-history li {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  margin: 0.2rem 0;
  min-width: 0;
}

.note-history .hist-k { color: var(--muted); font-size: 0.72rem; flex: 0 0 auto; }

.note-history .value {
  font-family: var(--mono);
  font-size: 0.8rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-history li { flex-wrap: wrap; }

.note-history time { color: var(--muted); font-size: 0.72rem; flex: 0 0 auto; margin-left: auto; }

.note-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.7rem;
  padding-top: 0.4rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.note-tools { display: flex; gap: 0.1rem; flex: 0 0 auto; }

.note-edited {
  margin: 0 0.2rem 0 auto;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: right;
  min-width: 0;
}

.text-btn {
  min-height: 2rem;
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  font-size: 0.85rem;
}

.text-btn:hover,
.text-btn:focus-visible {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.04);
}

dialog::backdrop { background: rgba(6, 10, 8, 0.72); }

.noscript {
  margin-top: 1rem;
  padding: 1rem;
  background: #3a2420;
  border-radius: 12px;
}

@media (max-width: 720px) {
  .top, .panel, .search-panel, .toolbar, .results, .banner, .status, .noscript,
  #vault .search-panel,
  #vault .toolbar,
  #vault .results,
  #vault .banner {
    width: calc(100% - 1.2rem);
  }
  .top, .top-actions { display: block; }
  .top-actions { margin-top: 1rem; }
  h1 { font-size: clamp(1.7rem, 9vw, 2.4rem); overflow-wrap: anywhere; }
  .lede, .fine, .status, .banner, .hint { overflow-wrap: anywhere; }
  .field, .grid { grid-template-columns: 1fr; }
  .field span:first-child { padding-top: 0; }
  .toolbar button,
  .button-row button,
  .file-row,
  .file-label,
  .file-row button,
  #lock-button,
  #load-published {
    width: 100%;
    justify-content: center;
  }
  .file-row { flex-direction: column; align-items: stretch; }
  #editor,
  dialog.note-editor {
    width: calc(100% - 0.7rem);
    max-width: calc(100% - 0.7rem);
    max-height: calc(100dvh - 0.7rem);
    height: calc(100dvh - 0.7rem);
    margin: 0.35rem auto;
    border-radius: 8px;
  }
  .note-row { flex-wrap: wrap; }
  .note-row label { flex-basis: 5.5rem; }
  .note-row input { flex: 1 1 8rem; }
  .note-edited { flex: 1 1 8rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}
