:root {
  color-scheme: light;
  font-family: Inter, Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f7f8fd;
  --surface: rgba(255,255,255,.9);
  --surface-strong: #ffffff;
  --panel: #f2f3fb;
  --line: #e2e5f1;
  --line-strong: #d5d9ea;
  --text: #1f2430;
  --muted: #7c8498;
  --accent: #6f77d9;
  --accent-soft: #eceeff;
  --accent-strong: #5158bc;
  --danger: #d95656;
  --shadow: 0 14px 40px rgba(38, 45, 86, .08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(111,119,217,.08), transparent 28rem),
    var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
dialog, summary, kbd { font-family: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

body[data-theme="mint"] {
  --accent: #4e9c85;
  --accent-soft: #e8f5f0;
  --accent-strong: #377866;
}
body[data-theme="blue"] {
  --accent: #4d7fc0;
  --accent-soft: #eaf2fc;
  --accent-strong: #36649f;
}
body[data-theme="pink"] {
  --accent: #b46b8e;
  --accent-soft: #f9ebf1;
  --accent-strong: #94506f;
}
body[data-mode="dark"] {
  color-scheme: dark;
  --bg: #161820;
  --surface: rgba(31,34,45,.94);
  --surface-strong: #222531;
  --panel: #1c1f29;
  --line: #323746;
  --line-strong: #404656;
  --text: #f1f3f8;
  --muted: #9ca4b7;
  --accent-soft: rgba(111,119,217,.18);
  --shadow: 0 14px 40px rgba(0,0,0,.25);
}

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 18px clamp(14px, 2.2vw, 30px) 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: max-content; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  color: white; font-weight: 800; font-size: 18px;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 28%, transparent);
}
.brand strong { display: block; font-size: 16px; letter-spacing: -.03em; }
.brand span { display: block; margin-top: 2px; font-size: 11px; color: var(--muted); }
.desktop-actions { display: flex; align-items: center; gap: 8px; }

.btn, .icon-btn, .chip {
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: var(--surface-strong);
  box-shadow: 0 1px 0 rgba(255,255,255,.4) inset;
  transition: .16s ease;
}
.btn:hover, .icon-btn:hover, .chip:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); transform: translateY(-1px); }
.btn:active, .icon-btn:active, .chip:active { transform: translateY(0); }
.btn { min-height: 38px; padding: 0 13px; border-radius: 11px; font-size: 13px; font-weight: 700; }
.btn.compact { min-height: 34px; padding: 0 11px; font-size: 12px; white-space: nowrap; }
.btn.primary { color: white; border-color: var(--accent); background: var(--accent); }
.btn.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.icon-btn { width: 38px; height: 38px; padding: 0; border-radius: 11px; display: grid; place-items: center; }
.chip { min-height: 34px; padding: 0 12px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.chip.active { color: var(--accent-strong); border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); background: var(--accent-soft); }

.search-wrap {
  position: relative;
  margin-top: 14px;
  display: flex;
  align-items: center;
}
.search-wrap input {
  width: 100%; height: 46px;
  padding: 0 54px 0 42px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  outline: none;
  color: var(--text);
  background: var(--surface-strong);
  box-shadow: 0 6px 20px rgba(47,53,91,.04);
}
.search-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }
.search-icon { position: absolute; left: 15px; color: var(--muted); font-size: 22px; transform: translateY(-1px); }
kbd { position: absolute; right: 12px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); background: var(--panel); font-size: 11px; }
.toolbar-scroll { display: flex; align-items: center; gap: 8px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.toolbar-scroll::-webkit-scrollbar { display: none; }
.filter-group { display: flex; gap: 6px; }
.toolbar-divider { width: 1px; height: 24px; flex: 0 0 1px; background: var(--line); }
.install-hidden { display: none; }

.status-strip {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 9px clamp(14px, 2.2vw, 30px);
  border-bottom: 1px solid var(--line);
  color: var(--muted); font-size: 11px;
  background: color-mix(in srgb, var(--accent-soft) 48%, var(--bg));
}
.status-strip > div { display: flex; align-items: center; gap: 6px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #52a676; box-shadow: 0 0 0 4px rgba(82,166,118,.11); }
.status-strip strong { color: var(--text); font-weight: 700; }

main { min-height: calc(100vh - 190px); padding: 18px clamp(14px, 2.2vw, 30px) 90px; }
.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(285px, 330px);
  align-items: start;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 14px;
  scroll-snap-type: x proximity;
}
.board::-webkit-scrollbar { height: 10px; }
.board::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }
.category-card {
  scroll-snap-align: start;
  min-height: 180px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.category-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent-soft) 46%, var(--surface-strong)), var(--surface));
}
.category-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.category-title .drag-handle { color: var(--muted); font-size: 14px; cursor: grab; }
.category-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.count-badge { min-width: 24px; height: 21px; padding: 0 7px; display: grid; place-items: center; border-radius: 999px; color: var(--muted); background: var(--panel); font-size: 10px; font-weight: 800; }
.category-actions { display: flex; gap: 4px; }
.mini-btn { width: 28px; height: 28px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; }
.mini-btn:hover { color: var(--accent-strong); background: var(--accent-soft); }
.category-body { padding: 9px; }
.group { padding: 6px; border-radius: 12px; }
.group + .group { margin-top: 4px; border-top: 1px solid var(--line); border-radius: 0; padding-top: 10px; }
.group.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--accent-soft); }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 27px; margin-bottom: 3px; }
.group-name { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.group-actions { opacity: 0; transition: .15s; }
.group:hover .group-actions { opacity: 1; }
.link-list { display: grid; gap: 2px; }
.link-row {
  position: relative;
  display: grid;
  grid-template-columns: 24px minmax(0,1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 35px;
  padding: 4px 5px;
  border-radius: 9px;
  transition: .14s ease;
}
.link-row:hover { background: var(--panel); }
.link-row.dragging { opacity: .42; }
.favicon {
  width: 22px; height: 22px; border-radius: 6px;
  display: grid; place-items: center;
  overflow: hidden;
  color: white; font-size: 10px; font-weight: 800;
  background: var(--accent);
}
.favicon img { width: 16px; height: 16px; object-fit: contain; }
.link-main { min-width: 0; }
.link-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 650; }
.link-host { display: none; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 9px; }
.link-row:hover .link-host { display: block; }
.link-actions { display: flex; align-items: center; opacity: 0; transition: .14s; }
.link-row:hover .link-actions { opacity: 1; }
.star-btn { color: #c4a241; }
.add-inline {
  width: 100%; min-height: 34px; margin-top: 7px;
  border: 1px dashed var(--line-strong); border-radius: 10px;
  color: var(--muted); background: transparent; font-size: 11px; font-weight: 700;
}
.add-inline:hover { color: var(--accent-strong); border-color: var(--accent); background: var(--accent-soft); }

.empty-state {
  grid-column: 1 / -1;
  width: min(620px, 100%);
  margin: 8vh auto 0;
  padding: 42px 28px;
  text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: 24px;
  background: var(--surface);
}
.empty-icon { width: 58px; height: 58px; margin: 0 auto 16px; display: grid; place-items: center; border-radius: 18px; background: var(--accent-soft); color: var(--accent-strong); font-size: 26px; font-weight: 800; }
.empty-state h2 { margin: 0; font-size: 20px; letter-spacing: -.04em; }
.empty-state p { max-width: 460px; margin: 10px auto 18px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.empty-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }

.modal { width: min(560px, calc(100vw - 24px)); padding: 0; border: 0; border-radius: 22px; color: var(--text); background: transparent; }
.modal::backdrop { background: rgba(21,24,35,.48); backdrop-filter: blur(5px); }
.modal-card { max-height: min(80vh, 760px); overflow: auto; border: 1px solid var(--line); border-radius: 22px; background: var(--surface-strong); box-shadow: 0 30px 90px rgba(20,22,37,.24); }
.modal-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 20px 20px 14px; border-bottom: 1px solid var(--line); background: var(--surface-strong); }
.modal-head h2 { margin: 2px 0 0; font-size: 20px; letter-spacing: -.04em; }
.eyebrow { margin: 0; color: var(--accent); font-size: 9px; font-weight: 900; letter-spacing: .13em; }
.modal-body { padding: 18px 20px 22px; }
.form-grid { display: grid; gap: 14px; }
.form-row { display: grid; gap: 7px; }
.form-row.two { grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row label { color: var(--muted); font-size: 11px; font-weight: 800; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; min-height: 42px; padding: 9px 11px;
  border: 1px solid var(--line-strong); border-radius: 11px; outline: none;
  color: var(--text); background: var(--bg);
}
.form-row textarea { min-height: 150px; resize: vertical; line-height: 1.55; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
.checkbox-row { display: flex; align-items: center; gap: 9px; font-size: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.helper { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.result-list { display: grid; gap: 8px; margin-top: 12px; }
.result-item { padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.result-item strong { display: block; font-size: 12px; }
.result-item span { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; overflow-wrap: anywhere; }
.theme-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.theme-option { min-height: 72px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); font-size: 11px; font-weight: 800; }
.theme-option.active { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 14%, transparent); }
.theme-swatch { display: block; width: 24px; height: 24px; margin: 0 auto 7px; border-radius: 50%; }
.sync-card { padding: 13px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.sync-card strong { display: block; font-size: 12px; }
.sync-card p { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 80;
  max-width: calc(100vw - 28px); padding: 10px 14px;
  border-radius: 999px;
  color: #fff; background: #262a35;
  font-size: 12px; font-weight: 700;
  box-shadow: 0 12px 30px rgba(0,0,0,.22);
  opacity: 0; pointer-events: none; transform: translate(-50%, 14px);
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.mobile-nav { display: none; }

@media (max-width: 760px) {
  .topbar { padding: 12px 12px 9px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
  .brand span, .desktop-actions { display: none; }
  .search-wrap { margin-top: 11px; }
  .search-wrap input { height: 43px; }
  kbd { display: none; }
  .toolbar-scroll { margin-top: 8px; }
  .toolbar-divider, .toolbar-scroll > .btn { display: none; }
  .status-strip { padding: 8px 12px; }
  .status-help, #summaryText { display: none; }
  main { padding: 12px 10px 92px; }
  .board { display: block; overflow: visible; }
  .category-card { margin-bottom: 10px; border-radius: 15px; box-shadow: 0 5px 18px rgba(38,45,86,.05); }
  .category-head { position: sticky; top: 132px; z-index: 3; }
  .group-actions, .link-actions { opacity: 1; }
  .link-row { min-height: 42px; grid-template-columns: 28px minmax(0,1fr) auto; padding: 5px 4px; }
  .favicon { width: 26px; height: 26px; }
  .link-title { font-size: 13px; }
  .link-host { display: block; font-size: 9px; }
  .empty-state { margin-top: 4vh; padding: 30px 18px; }
  .modal { width: calc(100vw - 16px); }
  .modal-card { max-height: 86vh; }
  .modal-head { padding: 17px 16px 12px; }
  .modal-body { padding: 15px 16px 20px; }
  .form-row.two { grid-template-columns: 1fr; }
  .theme-grid { grid-template-columns: repeat(2, 1fr); }
  .mobile-nav {
    position: fixed; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); z-index: 30;
    display: grid; grid-template-columns: repeat(5,1fr);
    padding: 7px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: color-mix(in srgb, var(--surface-strong) 92%, transparent);
    box-shadow: 0 14px 40px rgba(28,31,49,.18);
    backdrop-filter: blur(18px);
  }
  .mobile-nav button { min-width: 0; padding: 4px 2px; border: 0; border-radius: 11px; color: var(--muted); background: transparent; font-size: 9px; font-weight: 800; }
  .mobile-nav button span { display: block; margin-bottom: 2px; font-size: 18px; line-height: 1; }
  .mobile-nav button.active { color: var(--accent-strong); background: var(--accent-soft); }
  .toast { bottom: 82px; }
}

@media (min-width: 761px) and (max-width: 1100px) {
  .board { grid-auto-columns: minmax(280px, 38vw); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
