:root {
  --bg: #0c0c0e;
  --fg: #e8e4da;
  --mute: #827e74;
  --accent: #d4a76a;
  --line: #222126;
  --line-strong: #605e67;
  --pad: clamp(16px, 4vmin, 32px);
  --text: clamp(14px, 1.7vmin, 16px);
  --small: clamp(11px, 1.3vmin, 12px);
  --ease: 160ms cubic-bezier(.2, .7, .2, 1);
}

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

html { color-scheme: dark; }
html, body {
  background: var(--bg);
  color: var(--fg);
  font: var(--text) / 1.55 ui-monospace, "SF Mono", Menlo, "Cascadia Code", monospace;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible { outline: 1px solid var(--accent); outline-offset: 3px; }
input:focus-visible { outline: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

body { display: flex; flex-direction: column; }

a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; background: none; border: 0; }
[hidden] { display: none !important; }
.muted { color: var(--mute); }
.small { font-size: var(--small); }

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: var(--pad);
}
header h1 { font: inherit; font-weight: normal; display: flex; align-items: baseline; gap: 6px; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

.src {
  font-size: var(--small);
  color: var(--mute);
  transition: color var(--ease);
}
.src:hover { color: var(--accent); }
.brand { letter-spacing: -0.01em; transition: color var(--ease); }
.brand:hover { color: var(--accent); }
nav { display: flex; gap: 12px; font-size: var(--small); color: var(--mute); }
#handle { color: var(--accent); }
.text { cursor: pointer; color: var(--mute); transition: color var(--ease); }
.text:hover { color: var(--fg); }

main {
  flex: 1;
  width: min(100%, 40rem);
  margin: 0 auto;
  padding: 0 var(--pad) max(var(--pad), env(safe-area-inset-bottom));
}
main[data-state="out"], main[data-state="empty"], main[data-state="blocked"], main[data-state="loading"] {
  display: flex;
  align-items: center;
  padding-bottom: 20vh;
}
main > section { display: none; width: 100%; animation: rise var(--ease) both; }
main[data-state="out"] > [data-for="out"],
main[data-state="empty"] > [data-for="empty"],
main[data-state="blocked"] > [data-for="blocked"],
main[data-state="ready"] > [data-for="ready"] { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

label, .lede { display: block; margin-bottom: 12px; }

input[type="text"], input[type="search"] {
  width: 100%;
  font-size: max(16px, var(--text));
  padding: 10px 0;
  border-bottom: 1px solid var(--line-strong);
  border-radius: 0;
  outline: none;
  -webkit-appearance: none;
  transition: border-color var(--ease);
}
input:focus { border-bottom-color: var(--accent); }
input::placeholder { color: var(--mute); }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

#signin { position: relative; }
#suggest {
  position: absolute;
  left: 0; right: 0;
  list-style: none;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  z-index: 1;
}
#suggest li {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  padding: 6px 0;
  cursor: pointer;
  color: var(--mute);
  transition: color var(--ease);
}
#suggest li[aria-selected="true"], #suggest li:hover { color: var(--fg); }
#suggest span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#suggest b { flex-shrink: 0; }
#suggest .avatar { width: 20px; height: 20px; flex-shrink: 0; border-radius: 50%; object-fit: cover; background: var(--line); }
#suggest b { font-weight: normal; color: var(--fg); }

button:not(.text) {
  cursor: pointer;
  min-height: 44px;
  padding: 10px 0;
  color: var(--accent);
  border-bottom: 1px solid transparent;
  transition: border-color var(--ease), opacity var(--ease);
}
button:not(.text):hover { border-bottom-color: var(--accent); }
button:disabled { opacity: .5; cursor: wait; }

/* settings is a real modal: native <dialog>, so escape, focus trapping and
   the backdrop come from the browser. full-screen on phones, a centered sheet
   on anything wider. */
dialog#settings {
  border: 0;
  padding: 0;
  margin: 0;
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
}
dialog#settings::backdrop { background: rgba(0, 0, 0, .6); }
.modal {
  width: min(100%, 40rem);
  margin: 0 auto;
  padding: var(--pad);
  padding-bottom: max(var(--pad), env(safe-area-inset-bottom));
}
.modal-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal h2 { font: inherit; font-weight: normal; }
.modal fieldset { border: 0; margin-top: 20px; }
.modal legend { padding: 0 0 8px; }
.modal fieldset p { margin-top: 10px; }

@media (min-width: 720px) {
  dialog#settings {
    width: min(100vw - 2 * var(--pad), 40rem);
    /* the UA sheet gives a top-layer dialog inset:0, so `auto` stretches it
       to the viewport; fit-content sizes it to the sheet. */
    height: fit-content;
    max-height: min(100dvh - 2 * var(--pad), 44rem);
    margin: auto;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    overflow: auto;
  }
  .modal { padding: 28px; }
}

.clients { display: flex; flex-wrap: wrap; gap: 8px; }
.clients button {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 10px;
  color: var(--mute);
  border: 1px solid var(--line);
  border-radius: var(--radius, 4px);
  cursor: pointer;
  transition: color var(--ease), border-color var(--ease);
}
.clients button:hover { color: var(--fg); border-color: var(--line-strong); }
.clients button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.clients img { width: 16px; height: 16px; border-radius: 3px; }

.backlinks { position: relative; display: inline-flex; }
.backlinks > button {
  min-height: 0;
  padding: 0;
  font-size: var(--small);
  color: var(--mute);
  cursor: pointer;
  transition: color var(--ease);
}
.backlinks > button:hover:not(:disabled) { color: var(--accent); }
.backlinks > button:disabled { cursor: default; opacity: 1; }
.backlink-menu {
  position: absolute;
  left: 0;
  top: 1.6em;
  z-index: 2;
  min-width: 12rem;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius, 4px);
  padding: 4px 0;
}
.backlink-menu a {
  display: block;
  padding: 6px 10px;
  font-size: var(--small);
  color: var(--mute);
  transition: color var(--ease);
}
.backlink-menu a:hover { color: var(--fg); }
[data-for="empty"] .small, [data-for="blocked"] .small { margin-top: 16px; }

.bar { height: 1px; background: var(--line); margin-top: -1px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 300ms linear; }
#status { min-height: 1.6em; margin: 10px 0 18px; }
#status a { color: var(--accent); cursor: pointer; }

#results {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
#results li { min-width: 0; animation: rise var(--ease) both; }
#results li.record { grid-column: 1 / -1; padding: 8px 0; border-bottom: 1px solid var(--line); }
#results li.record .meta { display: flex; gap: 10px; font-size: var(--small); color: var(--mute); margin-bottom: 2px; }
#results li.record p { white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
#results li.record a:hover p { color: var(--accent); }
.thumbs { display: flex; gap: 6px; margin-top: 8px; }
.thumbs img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--line);
  opacity: .9;
  transition: opacity var(--ease);
}
#results li.record a:hover .thumbs img { opacity: 1; }
#results li.media a { display: block; aspect-ratio: 1; overflow: hidden; border-radius: 4px; background: var(--line); }
#results li.media img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform var(--ease), opacity var(--ease); opacity: .92; }
#results li.media a:hover img { transform: scale(1.02); opacity: 1; }
#results li.media .cap { display: block; margin-top: 4px; font-size: var(--small); color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 480px) {
  #results { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
