:root {
  color-scheme: dark;
  --bg: #17161d;
  --ink: #f4f2f8;
  --muted: #b6b3c1;
  --line: #3b3945;
  --panel: #292832;
  --panel-soft: #22212a;
  --field: #15141b;
  --brand: #63a9ea;
  --brand-dark: #4d94d5;
  --accent: #fc6d26;
  --danger: #ff8a80;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  background: rgba(23, 22, 29, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.brand-link {
  color: inherit;
  text-decoration: none;
}

.brand-link:focus-visible {
  outline: 2px solid rgba(99, 169, 234, 0.55);
  outline-offset: 4px;
  border-radius: 8px;
}

h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.logout-link {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: #aad4f8;
  background: var(--panel-soft);
  text-decoration: none;
  font-weight: 800;
  font-size: 13px;
}

.stats span,
.meta span,
.tags a {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--panel-soft);
  text-decoration: none;
}

.shell {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 18px clamp(14px, 3vw, 28px) 48px;
}

.panel,
.filters,
.quick-terms,
.link-card,
.empty,
.flash {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.18);
}

.add-panel {
  padding: 16px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.section-head a,
.primary-action,
.secondary-action {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: #aad4f8;
  background: var(--panel-soft);
  text-decoration: none;
  font-weight: 900;
}

.home-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.primary-action {
  border-color: var(--brand);
  color: #101018;
  background: var(--brand);
}

.primary-action:hover {
  background: var(--brand-dark);
}

.link-form,
.edit-form,
.filters form,
.quick-terms {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.full,
.primary {
  grid-column: 1 / -1;
}

input,
select,
textarea,
button {
  width: 100%;
  min-height: 44px;
  border: 1px solid #686575;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--field);
  font: inherit;
}

input::placeholder,
textarea::placeholder {
  color: #858191;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid rgba(99, 169, 234, 0.55);
  outline-offset: 2px;
  border-color: var(--brand);
}

textarea {
  resize: vertical;
}

button {
  cursor: pointer;
  font-weight: 800;
  background: var(--panel-soft);
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

button:hover {
  border-color: var(--brand);
  background: #302f3b;
}

.primary {
  background: var(--brand);
  color: #101018;
  border-color: var(--brand);
}

.primary:hover {
  background: var(--brand-dark);
  transform: translateY(-1px);
}

.quick-terms {
  margin-top: 12px;
  padding: 12px;
}

.quick-terms form {
  display: grid;
  grid-template-columns: 1fr 84px;
  gap: 8px;
}

.filters {
  margin-top: 12px;
  padding: 12px;
  position: sticky;
  top: 88px;
  z-index: 4;
  background: rgba(41, 40, 50, 0.96);
  backdrop-filter: blur(12px);
}

.filters form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
}

.filter-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.filter-details summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 0 12px;
  color: #aad4f8;
  font-weight: 900;
  list-style: none;
}

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

.filter-details summary::before {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-right: 8px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--brand);
}

.filter-details[open] summary::before {
  content: "-";
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 116px 86px;
  gap: 8px;
  padding: 0 10px 10px;
}

.check-filter {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid #686575;
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
}

.check-filter input {
  width: 18px;
  min-height: 18px;
  margin: 0 8px 0 0;
}

.clear-filter {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #aad4f8;
  background: var(--field);
  text-decoration: none;
  font-weight: 900;
}

.link-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.link-card {
  display: grid;
  grid-template-columns: 138px 1fr;
  gap: 14px;
  padding: 12px;
}

.thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 13 / 9;
  overflow: hidden;
  border-radius: 7px;
  background: #343240;
  color: var(--brand);
  font-weight: 900;
  text-decoration: none;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.content {
  min-width: 0;
}

.meta,
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.link-card h2 {
  margin: 8px 0 6px;
  font-size: 18px;
  line-height: 1.35;
  letter-spacing: 0;
}

.link-card h2 a {
  text-decoration: none;
  color: #f7f4ff;
}

.link-card h2 a:hover {
  color: #aad4f8;
}

.app-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 10px;
}

.app-open-link,
.web-open-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 800;
  text-decoration: none;
}

.app-open-link {
  background: var(--brand);
  color: #101018;
}

.web-open-link {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: #f7f4ff;
}

.web-open-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.web-open-panel {
  width: min(100%, 560px);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(22, 22, 31, 0.92);
  padding: 18px;
}

.web-open-panel h1 {
  margin: 0 0 10px;
  font-size: 24px;
  letter-spacing: 0;
}

.web-open-panel p {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.55;
}

.web-open-panel input {
  width: 100%;
  margin-bottom: 12px;
}

.web-open-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.web-open-actions button,
.web-open-actions a {
  min-height: 40px;
}

.primary-copy-action {
  width: 100%;
  background: var(--brand);
  color: #101018;
  font-weight: 900;
}

.web-open-hint {
  min-height: 22px;
  margin-top: 12px !important;
}

.link-card p {
  margin: 0 0 10px;
  color: #c9c6d2;
  line-height: 1.55;
}

.tags a {
  color: #9dccf5;
}

.edit-box {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.edit-box summary {
  width: max-content;
  cursor: pointer;
  color: #aad4f8;
  font-weight: 800;
  list-style: none;
}

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

.edit-box summary::before {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-right: 6px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--brand);
}

.edit-box[open] summary {
  margin-bottom: 12px;
}

.edit-box[open] summary::before {
  content: "-";
}

.edit-form {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.delete-form {
  margin-top: 10px;
}

.delete-form button {
  color: var(--danger);
  border-color: rgba(255, 138, 128, 0.45);
}

.empty,
.flash {
  padding: 16px;
}

.flash {
  margin-bottom: 12px;
  border-color: rgba(99, 169, 234, 0.45);
  background: rgba(99, 169, 234, 0.16);
  color: #c7e3ff;
  font-weight: 800;
}

.flash.error {
  border-color: rgba(255, 138, 128, 0.45);
  background: rgba(255, 138, 128, 0.16);
  color: var(--danger);
}

.login-page {
  display: grid;
  place-items: start center;
  padding: 12vh 16px;
}

.login-shell {
  width: min(420px, 100%);
}

.login-card {
  display: grid;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.28);
}

.login-card h1 {
  font-size: 24px;
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    position: static;
  }

  .top-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats {
    justify-content: flex-start;
  }

  .link-form,
  .edit-form,
  .quick-terms,
  .link-card {
    grid-template-columns: 1fr;
  }

  .quick-terms form {
    grid-template-columns: 1fr 76px;
  }

  .shell {
    padding-top: 12px;
  }

  .filters {
    margin-top: 0;
    top: 0;
  }

  .filter-grid {
    grid-template-columns: 1fr;
  }

  .home-actions,
  .primary-action,
  .secondary-action {
    width: 100%;
  }

  .thumb {
    aspect-ratio: 16 / 9;
  }
}
