:root {
  --bg: #0f0f0f;
  --bg-elev: #161616;
  --bg-muted: #222222;
  --fg: #f2f2f2;
  --muted: #9b9b9b;
  --line: #2c2c2c;
  --line-strong: #3f3f3f;
  --danger: #e7b4b4;
  --danger-bg: #3a1c1c;
  --img-size: 160;
  --bar: 56px;
  color-scheme: dark;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.45;
  overflow-x: hidden;
}

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

#ytlinks {
  min-height: 100vh;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--fg);
}

#ytlinks[hidden],
#ytlinks [hidden] {
  display: none !important;
}

#ytlinks button,
#ytlinks input {
  font: inherit;
  color: inherit;
}

#ytlinks button {
  cursor: pointer;
}

#ytlinks button:disabled {
  cursor: default;
  opacity: 0.55;
}

#ytlinks a {
  color: inherit;
}

.edit-banner {
  text-align: center;
  padding: 8px 12px;
  background: #1a1a1a;
  color: #d0d0d0;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--line);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: var(--bar);
  padding: calc(4px + env(safe-area-inset-top)) 8px 4px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding-right: 8px;
  color: inherit;
  text-decoration: none;
  font-weight: 600;
  letter-spacing: -0.03em;
  font-size: 1.15rem;
  white-space: nowrap;
}

.brand-mark {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e23d3d;
  flex: none;
}

.cat-nav {
  display: flex;
  gap: 6px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

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

.top-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.icon-btn,
.chip,
.text-btn,
.btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg);
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  padding: 0;
}

.icon-btn:active,
.text-btn:active,
.chip:active,
.btn:active {
  background: #2a2a2a;
}

.text-btn,
.chip,
.btn {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border-color: var(--line-strong);
  background: #1c1c1c;
  font-weight: 500;
  white-space: nowrap;
}

.text-btn.is-on,
.chip.is-on {
  background: #f2f2f2;
  color: #141414;
  border-color: transparent;
}

.btn {
  border-radius: 12px;
  min-height: 48px;
}

.btn-primary {
  background: #f2f2f2;
  color: #141414;
  border-color: transparent;
}

.btn-primary:active {
  background: #dedede;
}

.btn-danger {
  background: #1c1c1c;
  color: var(--danger);
  border-color: #7a4545;
}

.sheet {
  position: fixed;
  z-index: 30;
  top: calc(var(--bar) + env(safe-area-inset-top));
  left: 0;
  right: 0;
  bottom: 0;
  overflow: auto;
  background: #101010;
  padding: 8px 12px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sheet button {
  width: 100%;
  min-height: 48px;
  text-align: left;
  border-radius: 12px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #171717;
  font-weight: 500;
}

.sheet button.is-on {
  background: #f2f2f2;
  color: #141414;
  border-color: transparent;
}

.page-head {
  text-align: center;
  padding: 28px 16px 12px;
}

.page-head h1 {
  margin: 0;
  font-size: clamp(1.7rem, 4vw, 2.15rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.page-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.add-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(
    auto-fill,
    minmax(min(100%, calc(var(--img-size) * 1px + 2.75rem)), 1fr)
  );
  gap: 1.35rem 0.75rem;
  padding: 8px 16px calc(56px + env(safe-area-inset-bottom));
  max-width: 1120px;
  margin: 0 auto;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  text-decoration: none;
  color: inherit;
  min-width: 0;
  padding: 8px 6px 12px;
  border-radius: 18px;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.card:active {
  background: rgba(255, 255, 255, 0.06);
}

@media (hover: hover) and (pointer: fine) {
  .card:hover {
    background: rgba(255, 255, 255, 0.04);
  }
}

.avatar {
  width: calc(var(--img-size) * 1px);
  height: calc(var(--img-size) * 1px);
  max-width: 100%;
  position: relative;
  display: grid;
  place-items: center;
  background: #1c1c1c;
  border: 1px solid #2a2a2a;
  overflow: hidden;
  flex: none;
}

.avatar.circle {
  border-radius: 50%;
}

.avatar.tile {
  border-radius: 22%;
}

.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  background: #fff;
}

.avatar-letter {
  font-size: calc(var(--img-size) * 0.28 * 1px);
  font-weight: 600;
  color: #cfcfcf;
  line-height: 1;
}

.card-name {
  margin-top: 0.9rem;
  font-size: calc(0.75rem + var(--img-size) * 0.0065rem);
  font-weight: 500;
  line-height: 1.3;
  word-break: break-word;
  max-width: 100%;
}

.card-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.3;
  word-break: break-word;
}

.edit-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
}

.edit-controls button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: #242424;
  color: var(--fg);
}

.edit-controls button.danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: transparent;
}

.empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 28px 8px;
  color: var(--muted);
}

.empty strong {
  color: var(--fg);
  font-size: 1.15rem;
  font-weight: 600;
}

.empty p {
  margin: 0;
  max-width: 28rem;
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

.fail-list {
  margin: 4px 0 12px;
  padding: 0;
  list-style: none;
  color: var(--fg);
  text-align: left;
}

.fail-list li {
  margin: 0;
  border-bottom: 1px solid var(--line);
}

.fail-list button {
  display: flex;
  width: 100%;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px;
  border: 0;
  background: transparent;
  color: var(--fg);
  text-align: left;
}

.fail-list button span {
  color: var(--muted);
  flex: none;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal {
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--bg-elev);
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.modal h2 {
  margin: 0 0 14px;
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

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

.modal-head h2 {
  margin: 0;
}

.field {
  margin-bottom: 14px;
  min-width: 0;
  max-width: 100%;
}

.field label,
.hint {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.92rem;
}

.field input[type="text"],
.field input[type="url"],
.field input[type="search"] {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #3a3a3a;
  background: #1a1a1a;
  color: var(--fg);
  font-size: 16px;
}

.field input:focus-visible,
.icon-btn:focus-visible,
.text-btn:focus-visible,
.btn:focus-visible,
.chip:focus-visible,
.sheet button:focus-visible,
.edit-controls button:focus-visible {
  outline: 2px solid #f2f2f2;
  outline-offset: 2px;
}

.lookup {
  min-height: 1.3em;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.preview-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.preview-row .grow {
  flex: 1;
  min-width: 0;
}

.form-preview .avatar {
  width: 72px;
  height: 72px;
}

.form-preview .avatar-letter {
  font-size: 1.4rem;
}

.help {
  color: #d5d5d5;
  text-underline-offset: 2px;
}

.check-list {
  max-height: 220px;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 4px 10px;
  margin-bottom: 8px;
}

.check-list label {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  min-height: 44px;
  color: var(--fg);
  font-size: 1rem;
  text-align: left;
}

.check-list input,
.toggle input {
  width: 18px;
  height: 18px;
  accent-color: #f2f2f2;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin: 8px 0;
  color: var(--fg);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.btn-row .btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 10px 12px;
  white-space: normal;
  line-height: 1.25;
  text-align: center;
}

.rule {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

.size-readout {
  text-align: center;
  margin: 6px 0 12px;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: #f2f2f2;
}

.thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.thumbs button {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  overflow: hidden;
  background: #111;
  flex: none;
}

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

.conflict {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.conflict-side {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  text-align: center;
}

.conflict-side .avatar {
  width: 96px;
  height: 96px;
  margin: 8px auto;
}

.conflict-side .avatar-letter {
  font-size: 1.6rem;
}

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 12px 16px;
  border-radius: 12px;
  background: #f2f2f2;
  color: #141414;
  font-weight: 500;
  text-align: center;
}

.search-grid {
  padding-left: 0;
  padding-right: 0;
  max-width: none;
}

@media (min-width: 720px) {
  .overlay {
    align-items: center;
    padding: 24px;
  }

  .modal {
    max-width: 520px;
    max-height: min(90vh, 860px);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 24px;
  }

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

@media (max-width: 860px) {
  .cat-nav,
  .desktop-only {
    display: none !important;
  }
}

@media (min-width: 861px) {
  .mobile-only {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  #ytlinks * {
    transition: none !important;
  }
}

#ytlinks .text-btn.is-on,
#ytlinks .chip.is-on,
#ytlinks .sheet button.is-on,
#ytlinks .btn-primary,
#ytlinks .btn-primary:active {
  color: #141414;
}

#ytlinks .btn-danger {
  color: var(--danger);
}

#ytlinks .check-list label {
  justify-content: flex-start;
}

#ytlinks.is-editing .card,
#ytlinks.is-search-editing .search-grid .card {
  cursor: default;
}

#ytlinks.is-editing .edit-controls button,
#ytlinks.is-search-editing .edit-controls button {
  cursor: pointer;
}
