:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --text: #1b2130;
  --muted: #5f6b80;
  --line: #dde1e8;
  --accent: #2f62e9;
  --accent-text: #ffffff;
  --danger: #c8322b;
  --shadow: 0 1px 2px rgb(16 24 40 / .06), 0 1px 3px rgb(16 24 40 / .08);
  --shadow-hover: 0 4px 12px rgb(16 24 40 / .12);
  --radius: 14px;
  --tile-l: 46%;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #171b22;
    --surface-2: #20252e;
    --text: #e6e8ec;
    --muted: #97a1b3;
    --line: #2a303b;
    --accent: #7aa2ff;
    --accent-text: #0e1116;
    --danger: #ff7b72;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-hover: 0 6px 16px rgb(0 0 0 / .5);
    --tile-l: 40%;
    --logo-bg: #eef1f5; /* dark logos (GitHub, Apple...) vanish on a dark card */
    --logo-pad: 5px;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 12px 24px 10px;
}
.tabs {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding-bottom: 8px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: 1px solid transparent; background: transparent;
  padding: 7px 14px; border-radius: 999px; cursor: pointer; color: var(--muted);
  font-weight: 550; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--accent); color: var(--accent-text); }
.tab.add { border: 1px dashed var(--line); }
.tab .pen { font-size: 12px; opacity: .85; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search { flex: 1 1 220px; min-width: 0; }
.search input, .toolbar select {
  width: 100%; height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.toolbar select { width: auto; }
.search input:focus, .toolbar select:focus, .field input:focus, .field textarea:focus, .field select:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
.toggle { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); white-space: nowrap; cursor: pointer; }
.logout { margin: 0; }

.btn {
  height: 36px; padding: 0 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-weight: 550;
}
.btn:hover { border-color: var(--muted); }
.btn[aria-pressed="true"], .btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

.banner {
  position: sticky; top: 0; z-index: 20; padding: 10px 16px; text-align: center;
  background: var(--danger); color: #fff; font-weight: 600;
}
.banner a { color: inherit; }

/* ---------- grid ---------- */
.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  padding: 20px 24px 48px; max-width: 1400px; margin: 0 auto;
}
.card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px 10px 12px; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); color: inherit; text-decoration: none; text-align: center;
  transition: transform .12s ease, box-shadow .12s ease;
  cursor: pointer;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.add { border-style: dashed; background: transparent; box-shadow: none; color: var(--muted); }
.pic { width: 56px; height: 56px; display: grid; place-items: center; flex: none; }
.pic img { width: 56px; height: 56px; object-fit: contain; border-radius: 12px; background: var(--logo-bg, transparent); padding: var(--logo-pad, 0); }
.tile {
  width: 56px; height: 56px; border-radius: 14px; display: grid; place-items: center;
  background: hsl(var(--hue, 220) 55% var(--tile-l)); color: #fff; font-weight: 700; font-size: 24px;
}
.tile.plus { background: var(--surface-2); color: var(--muted); }
.title {
  font-weight: 600; font-size: 14px; max-width: 100%;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.where, .tags { font-size: 12px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 48px 0; }

body.editing .card[data-id] { outline: 1px dashed var(--muted); outline-offset: -5px; }
.dragging { opacity: .4; }
.drop-target { box-shadow: 0 0 0 2px var(--accent) !important; }

/* ---------- dialogs ---------- */
dialog {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  border: 1px solid var(--line); border-radius: 16px; padding: 0;
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgb(0 0 0 / .3);
}
dialog::backdrop { background: rgb(10 14 20 / .45); }
dialog form { padding: 20px; display: grid; gap: 14px; }
dialog h2 { margin: 0; font-size: 18px; }
.field { display: grid; gap: 5px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 550; }
.field input, .field textarea, .field select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.field textarea { min-height: 64px; resize: vertical; }
.field .err { color: var(--danger); font-size: 13px; min-height: 0; }
.field.invalid input, .field.invalid textarea { border-color: var(--danger); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.row .spacer { flex: 1; }
.picture-box { display: flex; gap: 14px; align-items: center; padding: 12px; border-radius: 12px; background: var(--bg); }
.picture-box .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.icon-results { display: flex; gap: 6px; flex-wrap: wrap; }
.icon-results button {
  display: grid; justify-items: center; gap: 2px; width: 74px; padding: 6px 4px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; font-size: 11px;
}
.icon-results button[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.icon-results img { width: 32px; height: 32px; object-fit: contain; }
.icon-results span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.confirm { padding: 12px; border-radius: 12px; background: color-mix(in srgb, var(--danger) 12%, transparent); }
.status { font-size: 13px; color: var(--muted); }
.move { display: none; }
body.editing .move { display: inline-flex; }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 18px; font-size: 22px; }
.login-card form { display: grid; gap: 10px; }
.login-card label { font-size: 13px; color: var(--muted); }
.login-card input[type=password] { height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.login-card .check { display: flex; gap: 8px; align-items: center; color: var(--text); }
.login-card .error { color: var(--danger); margin: 0; }
.login-card button { height: 40px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-weight: 600; cursor: pointer; }

/* ---------- phones ---------- */
@media (max-width: 640px) {
  .top { padding: 10px 16px 8px; }
  .grid { padding: 14px 16px 40px; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .card { padding: 12px 6px 10px; }
  .pic, .pic img, .tile { width: 44px; height: 44px; }
  .tile { font-size: 20px; border-radius: 12px; }
  .title { font-size: 13px; }
  .tags { display: none; }
  .toggle { font-size: 13px; }
  .logout .btn { padding: 0 8px; }
}
@media (prefers-reduced-motion: reduce) { .card { transition: none; } .card:hover { transform: none; } }
