/* LinkStack. One stylesheet, no framework. Light and dark follow the system setting. */

:root {
  color-scheme: light dark;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1f1e1c;
  --muted: #64625d;
  --line: #e1dfd8;
  --field-line: #8f8d86;
  --accent: #2553c7;
  --accent-text: #ffffff;
  --accent-soft: #e4eafb;
  --visited: #5b5a6e;
  --danger: #b3261e;
  --danger-text: #ffffff;
  --danger-soft: #fbe9e7;
  --good: #19703d;
  --good-soft: #e3f4ea;
  --toast: #262522;
  --toast-text: #f6f5f1;
  --toast-accent: #a9c1ff;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 10px 30px rgb(0 0 0 / 0.12);
  --radius: 0.75rem;
  --measure: 46rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151516;
    --surface: #1e1e20;
    --text: #eceae6;
    --muted: #a5a39d;
    --line: #323235;
    --field-line: #7b797e;
    --accent: #8fb0ff;
    --accent-text: #0d1730;
    --accent-soft: #243050;
    --visited: #b9b6cc;
    --danger: #ff8f85;
    --danger-text: #2a0b08;
    --danger-soft: #3a1f1d;
    --good: #7fd6a0;
    --good-soft: #1c3326;
    --toast: #eceae6;
    --toast-text: #1f1e1c;
    --toast-accent: #2553c7;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 10px 30px rgb(0 0 0 / 0.5);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

h1 {
  margin: 0 0 0.75rem;
  font-size: 1.4rem;
  line-height: 1.25;
}

h2 {
  margin: 1.75rem 0 0.5rem;
  font-size: 1.05rem;
  line-height: 1.3;
}

p {
  margin: 0 0 0.75rem;
}

a {
  color: var(--accent);
  text-underline-offset: 0.15em;
}

code,
pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

code {
  padding: 0.05em 0.3em;
  border-radius: 0.3em;
  background: var(--bg);
  overflow-wrap: anywhere;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

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

.bad {
  color: var(--danger);
}

.lede {
  margin: 0 0 1rem;
  color: var(--muted);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---- Frame ---------------------------------------------------------------------------- */

.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0.55rem 1rem;
}

.brand {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
}

/* On a phone the tile stands for the name, so the menu fits beside it on one line. */
@media (max-width: 29.99rem) {
  .brand span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

.brand svg {
  color: var(--accent);
}

.brand-bar {
  fill: var(--accent-text);
}

.site-nav {
  display: flex;
  gap: 0.15rem;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.site-nav::-webkit-scrollbar {
  display: none;
}

.site-nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.25rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
}

/* On the narrowest phones (320px) a little less air between the words keeps the whole menu on screen. */
@media (max-width: 21.5rem) {
  .site-nav a {
    padding-inline: 0.45rem;
  }
}

.site-nav a:hover {
  color: var(--text);
}

.site-nav a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}

.count {
  color: var(--muted);
  font-size: 0.8em;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.alert-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--danger);
}

.page {
  flex: 1;
  width: 100%;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.25rem 1rem;
  /* The bottom padding keeps the last row clear of the toast. */
  padding: 1rem 1rem 4.5rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.site-footer form {
  margin: 0;
}

/* A button that reads as a link, for the things that are done rarely. */
.text-button {
  min-height: 2rem;
  margin: 0;
  padding: 0.25rem 0.4rem;
  border: 0;
  border-radius: 0.4rem;
  background: transparent;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
}

.text-button:hover {
  color: var(--text);
}

/* ---- Controls ------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.25rem;
  margin: 0;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.btn:hover {
  border-color: var(--field-line);
}

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.btn.primary:hover {
  filter: brightness(1.1);
}

.btn.quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn.quiet:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.btn.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: var(--danger-text);
  font-weight: 600;
}

input[type="text"],
input[type="search"],
input[type="password"],
textarea {
  display: block;
  width: 100%;
  min-height: 2.5rem;
  margin: 0;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--field-line);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--text);
  font: inherit; /* 16px, which also stops iOS zooming in on focus */
}

textarea {
  min-height: 4.5rem;
  resize: vertical;
}

::placeholder {
  color: var(--muted);
  opacity: 1;
}

@media (pointer: coarse) {
  .btn,
  .site-nav a {
    min-height: 2.75rem;
  }

  input[type="text"],
  input[type="search"],
  input[type="password"] {
    min-height: 2.75rem;
  }
}

.card {
  margin: 0 0 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.card > :first-child {
  margin-top: 0;
}

.card > :last-child {
  margin-bottom: 0;
}

/* A tag, wherever it shows: on a link, as a filter, as a pick under the add form. */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  padding: 0.05rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  line-height: 1.5;
  text-decoration: none;
  white-space: nowrap;
}

a.tag:hover,
button.tag:hover {
  border-color: var(--field-line);
  color: var(--text);
}

button.tag {
  cursor: pointer;
}

.tag.on,
.tag[aria-pressed="true"] {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}

.tag > span {
  font-variant-numeric: tabular-nums;
  font-weight: 400;
  opacity: 0.8;
}

/* A button that opens a small panel beneath its row (a note to write, a deletion to confirm). */
details.reveal > summary {
  list-style: none;
}

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

details.reveal[open] > summary {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--text);
}

.reveal-panel {
  position: absolute;
  z-index: 10;
  top: calc(100% - 0.4rem);
  right: 0.5rem;
  left: 0.5rem;
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.reveal-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.reveal-panel .btn {
  justify-self: end;
}

/* A panel holding more than one small form (a tag's rename and its delete). */
div.reveal-panel > form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

div.reveal-panel > form + form {
  padding-top: 0.6rem;
  border-top: 1px solid var(--line);
}

@media (min-width: 40rem) {
  .reveal-panel {
    left: auto;
    width: 24rem;
  }
}

/* ---- What just happened --------------------------------------------------------------- */

/* A toast at the foot of the window that takes itself away; its Undo is the safety net. */
.flash {
  position: fixed;
  z-index: 50;
  bottom: max(1rem, env(safe-area-inset-bottom));
  left: 50%;
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: max-content;
  max-width: calc(100vw - 2rem);
  padding: 0.55rem 0.6rem 0.55rem 1rem;
  border-radius: var(--radius);
  background: var(--toast);
  color: var(--toast-text);
  box-shadow: var(--shadow);
  font-size: 0.95rem;
  animation: toast-in 0.18s ease-out, toast-out 0.3s ease-in 8s forwards;
}

.flash:hover,
.flash:focus-within {
  animation-play-state: paused;
}

.flash > span {
  padding: 0.3rem 0.4rem 0.3rem 0;
}

.flash form {
  margin: 0;
}

.flash-undo {
  min-height: 2.25rem;
  margin: 0;
  padding: 0.25rem 0.7rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--toast-accent);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.flash-undo:hover {
  background: color-mix(in srgb, var(--toast-text) 14%, transparent);
}

.flash-undo:focus-visible {
  outline-color: var(--toast-accent);
}

/* Something that needs putting right stays put, at the top of the page. */
.flash.error {
  position: static;
  translate: none;
  width: auto;
  max-width: none;
  margin: 0 0 1rem;
  padding: 0.6rem 1rem;
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  color: var(--text);
  box-shadow: none;
  animation: none;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(0.5rem);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

/* ---- The stack ------------------------------------------------------------------------ */

.add {
  margin: 0 0 1.25rem;
}

.add-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  margin: 0;
}

#add-url {
  grid-column: 1 / -1;
}

/* The tags on offer stay out of the way until there is a link for them to go on. */
.add:has(#add-url:placeholder-shown):has(#add-tags:placeholder-shown) .tag-picks {
  display: none;
}

.add-form .btn {
  min-height: 2.5rem;
  padding-inline: 1.1rem;
}

@media (min-width: 40rem) {
  .add-form {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto;
  }

  #add-url {
    grid-column: auto;
  }
}

@media (pointer: coarse) {
  .add-form .btn {
    min-height: 2.75rem;
  }
}

/* Rows of tags stay on one line and scroll sideways on a phone, fading out at the edge. */
.tag-picks,
.tag-filter {
  display: flex;
  gap: 0.35rem;
  margin: 0.6rem -1rem 0;
  padding: 0.15rem 1rem;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, transparent, #000 1rem, #000 calc(100% - 2rem), transparent);
  mask-image: linear-gradient(to right, transparent, #000 1rem, #000 calc(100% - 2rem), transparent);
}

.tag-picks::-webkit-scrollbar,
.tag-filter::-webkit-scrollbar {
  display: none;
}

.tag-filter .tag {
  padding-block: 0.2rem;
  font-size: 0.85rem;
}

@media (min-width: 40rem) {
  .tag-picks,
  .tag-filter {
    flex-wrap: wrap;
    margin-inline: 0;
    padding-inline: 0;
    overflow: visible;
    -webkit-mask-image: none;
    mask-image: none;
  }
}

.filters {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.25rem;
}

.search {
  flex: 1;
  min-width: 0;
  margin: 0;
}

.filter-note {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}

.clear {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
}

.list-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 1.25rem 0 0.4rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.links,
.tag-list {
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  list-style: none;
}

.link {
  position: relative;
  display: grid;
  gap: 0.6rem 1rem;
  padding: 0.85rem 1rem;
}

.link + .link,
.tag-row + .tag-row {
  border-top: 1px solid var(--line);
}

.link-body {
  min-width: 0;
}

.link-title {
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.35;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.link-title:visited {
  color: var(--visited);
}

.link-title:hover {
  text-decoration: underline;
}

.link-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem 0.6rem;
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.link-meta .host {
  font-weight: 500;
  overflow-wrap: anywhere;
}

.link-note {
  margin: 0.55rem 0 0;
  padding: 0.45rem 0.75rem;
  border-left: 3px solid var(--line);
  border-radius: 0 0.4rem 0.4rem 0;
  background: var(--bg);
  font-size: 0.92rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.link-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.link-actions form {
  margin: 0;
}

@media (min-width: 40rem) {
  .link {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }

  .link-actions {
    flex-wrap: nowrap;
  }
}

/* A link you have opened in this visit: the one to come back to and deal with. */
.link.opened::before {
  position: absolute;
  top: 0.7rem;
  bottom: 0.7rem;
  left: 0;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  content: "";
}

.link.busy,
form[aria-busy="true"] {
  opacity: 0.55;
  pointer-events: none;
}

.empty {
  padding: 3rem 1rem;
  color: var(--muted);
  text-align: center;
}

.empty h1 {
  color: var(--text);
  font-size: 1.25rem;
}

/* ---- History -------------------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 0.25rem;
  margin: 0 0 1rem;
  border-bottom: 1px solid var(--line);
}

.tabs a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  margin-bottom: -1px;
  padding: 0.3rem 0.9rem;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
}

.tabs a:hover {
  color: var(--text);
}

.tabs a[aria-current="page"] {
  border-bottom-color: var(--accent);
  color: var(--text);
}

.filters + .links {
  margin-top: 0.75rem;
}

.pager {
  display: flex;
  margin-top: 1rem;
}

.pager a[rel="next"] {
  margin-left: auto;
}

/* ---- Tags ----------------------------------------------------------------------------- */

.merge-bar {
  position: sticky;
  z-index: 5;
  top: 0.5rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 1rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.merge-bar label {
  grid-column: 1 / -1;
  font-size: 0.9rem;
  font-weight: 600;
}

@media (min-width: 40rem) {
  .merge-bar {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .merge-bar label {
    grid-column: auto;
  }
}

.tag-row {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem 0.75rem;
  padding: 0.4rem 0.5rem 0.4rem 1rem;
}

.tag-check {
  display: inline-flex;
  flex: 1 1 6rem;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  min-height: 2.5rem;
  font-weight: 600;
  cursor: pointer;
}

.tag-check input {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  accent-color: var(--accent);
}

.tag-name {
  overflow-wrap: anywhere;
}

.tag-counts {
  display: inline-flex;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.tag-counts a {
  color: inherit;
}

.tag-row > details {
  margin-left: auto;
}

/* ---- Mail ----------------------------------------------------------------------------- */

.card.status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.card.status p {
  margin: 0;
}

.card.status p + p {
  margin-top: 0.2rem;
  font-size: 0.9rem;
}

.card.status form {
  margin: 0;
}

.example {
  margin: 0 0 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  background: var(--bg);
  line-height: 1.55;
  overflow-x: auto;
}

.example em {
  color: var(--accent);
  font-style: normal;
  font-weight: 700;
}

.rules {
  display: grid;
  gap: 0.4rem;
  margin: 0 0 0.75rem;
  padding-left: 1.2rem;
}

.mail-log {
  margin: 0;
  padding: 0;
  list-style: none;
}

.mail-log li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: 0.15rem 0.6rem;
  padding: 0.6rem 0;
  border-top: 1px solid var(--line);
}

.mail-subject {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.mail-meta {
  display: flex;
  flex-wrap: wrap;
  grid-column: 2;
  gap: 0.1rem 0.6rem;
  color: var(--muted);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.badge {
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge.good {
  background: var(--good-soft);
  color: var(--good);
}

.badge.bad {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---- Forms on their own pages --------------------------------------------------------- */

.edit-form,
.login {
  display: grid;
  gap: 0.35rem;
}

.edit-form label,
.login label {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.edit-address {
  margin: 0;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.login {
  max-width: 22rem;
  margin: 2.5rem auto 0;
  padding: 1.25rem;
}

.login h1 {
  margin: 0;
}

.login .bad {
  margin: 0.5rem 0 0;
}

.login .btn {
  min-height: 2.75rem;
  margin-top: 1.25rem;
}

@media (prefers-reduced-motion: reduce) {
  .flash {
    animation: toast-out 0.01s linear 8s forwards;
  }
}
