:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e1e4ea;
  --text: #1c2230;
  --muted: #646d7e;
  --primary: #3355d6;
  --primary-hover: #2945b8;
  --primary-soft: #e8edfc;
  --danger: #c63a3a;
  --danger-soft: #fbeaea;
  --shadow: 0 1px 2px rgba(20, 28, 45, .06), 0 2px 8px rgba(20, 28, 45, .05);
  --shadow-lg: 0 8px 30px rgba(20, 28, 45, .18);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #13161c;
    --surface: #1b1f27;
    --surface-2: #242a34;
    --border: #2f3642;
    --text: #e6e9ef;
    --muted: #98a1b2;
    --primary: #6f8cff;
    --primary-hover: #8aa1ff;
    --primary-soft: #26304d;
    --danger: #ff7a7a;
    --danger-soft: #3a2424;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
button, input, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); cursor: pointer; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); background: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn {
  width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent;
  cursor: pointer; font-size: 22px; line-height: 1; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

label { display: block; font-weight: 500; font-size: 14px; }
input:not([type=checkbox]):not([type=radio]), textarea {
  display: block; width: 100%; margin-top: 5px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface);
}
textarea { resize: vertical; }
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
input[type=checkbox], input[type=radio] { accent-color: var(--primary); width: 16px; height: 16px; margin: 0; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; font-size: 14px; padding: 0; margin-bottom: 8px; }
.sub-legend { font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
.form-error { color: var(--danger); font-size: 14px; margin: 0; min-height: 0; }
.form-error:empty { display: none; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand-lg { font-size: 20px; margin-bottom: 18px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  background: var(--primary) url("favicon.svg") center / cover;
}

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 380px; padding: 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  display: grid; gap: 14px;
}
.auth-card h1 { font-size: 22px; }
.auth-card p.muted { margin: -6px 0 0; }
.auth-card p.muted:empty { display: none; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.search { position: relative; flex: 1; max-width: 520px; margin-left: auto; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { margin: 0 !important; padding-left: 36px !important; background: var(--surface-2) !important; border-color: transparent !important; }
.search input:focus { background: var(--surface) !important; border-color: var(--border) !important; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--primary-soft); color: var(--primary); font-weight: 700;
}
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 240px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg);
}
.menu-list button {
  display: block; width: 100%; text-align: left; padding: 9px 10px;
  border: 0; background: none; border-radius: 7px; cursor: pointer;
}
.menu-list button:hover { background: var(--surface-2); }
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; font-weight: 600; }
.menu-head small { display: block; font-weight: 400; color: var(--muted); }

/* ---------- Category filter ---------- */
.filters { padding: 14px 24px 0; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  cursor: pointer; font-size: 14px;
}
.chip:hover { border-color: var(--primary); }
.chip .count { color: var(--muted); font-size: 12px; }
.chip[aria-pressed=true] { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip[aria-pressed=true] .count { color: rgba(255, 255, 255, .8); }

/* ---------- Board ---------- */
.board-wrap { padding: 10px 24px 48px; }
.result-line { font-size: 13px; margin: 4px 0 12px; min-height: 18px; }
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.card {
  position: relative; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; transition: box-shadow .15s, transform .15s;
}
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.shot { display: block; position: relative; aspect-ratio: 16 / 10; background: var(--surface-2); overflow: hidden; }
.shot img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.shot-badge {
  position: absolute; left: 10px; bottom: 10px; padding: 3px 9px; border-radius: 999px;
  background: rgba(20, 28, 45, .72); color: #fff; font-size: 12px;
}
.shot-badge.pending::before {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%;
  border: 2px solid #fff; border-right-color: transparent; animation: spin .8s linear infinite; vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.card-body { padding: 12px 14px 14px; display: grid; gap: 6px; flex: 1; align-content: start; }
.card-title {
  font-weight: 600; color: var(--text); text-decoration: none;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-title:hover { color: var(--primary); }
.card-host { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-note { font-size: 13px; color: var(--muted); margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { padding: 2px 8px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 500; }
.card-foot {
  display: flex; align-items: center; gap: 8px; margin-top: 4px; padding-top: 8px;
  border-top: 1px solid var(--border); font-size: 12px; color: var(--muted);
}
.vis { display: inline-flex; align-items: center; gap: 4px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vis svg { width: 13px; height: 13px; flex: none; }
.card-foot .spacer { flex: 1; }
.card-actions { display: flex; gap: 2px; }
.card-actions button {
  width: 28px; height: 28px; display: grid; place-items: center;
  border: 0; border-radius: 7px; background: none; cursor: pointer; color: var(--muted);
}
.card-actions button:hover { background: var(--surface-2); color: var(--text); }
.card-actions button.danger:hover { background: var(--danger-soft); color: var(--danger); }
.card-actions svg { width: 15px; height: 15px; }

.empty { text-align: center; padding: 60px 16px; }
.empty img { width: 220px; border-radius: 12px; opacity: .8; }
.empty h2 { margin: 18px 0 6px; font-size: 19px; }

/* ---------- Dialogs ---------- */
.dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg);
}
.dialog-sm { width: min(400px, calc(100vw - 32px)); }
.dialog-lg { width: min(720px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(10, 14, 24, .45); }
.dialog > form, .dialog > div { display: flex; flex-direction: column; max-height: calc(100vh - 50px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { font-size: 18px; }
.dialog-body { padding: 18px 20px; display: grid; gap: 16px; overflow-y: auto; }
.dialog-body h2 { font-size: 18px; }
.dialog-body > p { margin: 0; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

.pick-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pick-list:empty::after { content: attr(data-empty); color: var(--muted); font-size: 13px; }
.pick {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px;
  border: 1px solid var(--border); border-radius: 999px; font-weight: 400; font-size: 13px; cursor: pointer;
}
.pick:has(input:checked) { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.inline-add { display: flex; gap: 8px; margin-top: 10px; }
.inline-add input { margin: 0 !important; }
.segmented { display: grid; gap: 6px; }
.segmented label { display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
#restricted-picker { margin-top: 6px; padding: 4px 12px 12px; background: var(--surface-2); border-radius: 10px; }
#restricted-picker .small { margin: 10px 0 0; }

/* ---------- Admin ---------- */
.tabs { display: flex; gap: 4px; padding: 10px 20px 0; border-bottom: 1px solid var(--border); }
.tabs button {
  padding: 8px 14px; border: 0; border-bottom: 2px solid transparent; background: none; cursor: pointer;
  color: var(--muted); font-weight: 500; margin-bottom: -1px;
}
.tabs button[aria-selected=true] { color: var(--primary); border-bottom-color: var(--primary); }
.admin-body { min-height: 380px; }
.admin-form { display: grid; gap: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.admin-form h3 { font-size: 15px; }
.admin-form .sub-legend { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; align-self: end; padding-bottom: 10px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; }
.admin-list { list-style: none; margin: 14px 0 0; padding: 0; }
.admin-list li { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.admin-list li:last-child { border-bottom: 0; }
.admin-list .grow { flex: 1; min-width: 0; }
.admin-list .grow small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-list .pill { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.admin-list input { margin: 0 !important; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  padding: 10px 16px; border-radius: 10px; background: #1c2230; color: #fff; box-shadow: var(--shadow-lg); font-size: 14px;
}

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  .brand-text { display: none; }
  #add-link span { display: none; }
  #add-link { width: 38px; padding: 0; }
  .filters { padding: 12px 16px 0; }
  .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .chip { flex: none; }
  .board-wrap { padding: 8px 16px 40px; }
  .board { grid-template-columns: 1fr; gap: 14px; }
  .grid-2 { grid-template-columns: 1fr; }
  .check { padding-bottom: 0; }
}
