/* PilotNav — modern flat design, 3 themes (light / dark / sepia eye-care), fully responsive. */
:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1a2233;
  --muted: #64748b;
  --border: #e5eaf1;
  --accent: #2563eb;
  --accent-soft: #eef3ff;
  --hover: #f1f5f9;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 8px 24px -12px rgba(16, 24, 40, .12);
  --radius: 14px;
}
[data-theme="dark"] {
  --bg: #0d1220;
  --card: #151c2e;
  --text: #e6eaf2;
  --muted: #8b96ab;
  --border: #232d44;
  --accent: #5b8cff;
  --accent-soft: #1c2743;
  --hover: #1d2540;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}
[data-theme="sepia"] {
  --bg: #d7e6d0;
  --card: #e9f2e3;
  --text: #2c3a2b;
  --muted: #5d7057;
  --border: #c3d8ba;
  --accent: #3e7d3a;
  --accent-soft: #d3e6c8;
  --hover: #dbe9d1;
  --shadow: 0 1px 3px rgba(44, 58, 43, .12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background .25s, color .25s;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: inherit; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

.ic { width: 18px; height: 18px; flex: none; vertical-align: -3px; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar-in { display: flex; align-items: center; gap: 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 19px; letter-spacing: -.02em; }
.brand-ic { width: 26px; height: 26px; color: var(--accent); }
.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--card);
  border-radius: 10px; padding: 7px 10px; font-size: 13px;
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: var(--hover); }
.lang-btn .lang-name { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-btn .user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* language panel */
.lang-panel {
  position: absolute; right: 16px; top: 100%; width: min(420px, calc(100vw - 24px));
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 10px; margin-top: 6px;
}
.lang-search input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg); outline: none; font-size: 14px;
}
.lang-search input:focus { border-color: var(--accent); }
.lang-list {
  list-style: none; margin: 8px 0 0; padding: 0;
  max-height: 320px; overflow-y: auto; overscroll-behavior: contain;
}
.lang-list li {
  display: flex; justify-content: space-between; gap: 8px; align-items: baseline;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.lang-list li:hover, .lang-list li.active { background: var(--hover); }
.lang-list li .code { color: var(--muted); font-size: 12px; }
.lang-list li .en { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lang-list li b { font-weight: 600; white-space: nowrap; }
.lang-empty { color: var(--muted); text-align: center; padding: 14px 0; font-size: 13px; }

/* user panel */
.user-panel {
  position: absolute; right: 16px; top: 100%; min-width: 200px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px; margin-top: 6px;
}
/* login/register panel anchored right below the user button */
.auth-panel {
  position: absolute; right: 16px; top: 100%; width: min(330px, calc(100vw - 24px));
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-top: 6px; z-index: 60;
}
.user-panel .u-head { padding: 8px 12px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.user-panel .u-head b { color: var(--text); font-size: 14px; display: block; }
.user-panel button {
  display: flex; width: 100%; align-items: center; gap: 8px;
  background: none; border: 0; padding: 9px 12px; border-radius: 8px; font-size: 14px; text-align: start;
}
.user-panel button:hover { background: var(--hover); }
.user-panel button.danger { color: var(--danger); }

/* ---------- cards ---------- */
main { display: flex; flex-direction: column; gap: 16px; padding: 18px 16px 8px; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; margin: 0; font-weight: 700; margin-right: auto; }

/* search */
.search-card { padding: 14px 18px 16px; }
/* engine dropdown */
.engine-dd { position: relative; flex: none; }
.engine-btn { display: inline-flex; align-items: center; gap: 6px; padding: 11px 14px; font-weight: 600; }
.engine-btn .caret { font-size: 11px; color: var(--muted); }
.engine-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40;
  min-width: 180px; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 5px;
}
.engine-item {
  display: block; width: 100%; text-align: start; border: 0; background: none;
  padding: 9px 12px; border-radius: 8px; font-size: 13.5px;
}
.engine-item:hover { background: var(--hover); }
.engine-item.active { color: var(--accent); font-weight: 700; background: var(--accent-soft); }
.search-row { display: flex; align-items: center; gap: 10px; }
.search-ic .ic { width: 20px; height: 20px; color: var(--muted); }
#q {
  flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font-size: 15px; background: var(--bg); outline: none;
}
#q:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.btn {
  border: 1px solid var(--border); background: var(--card);
  border-radius: 10px; padding: 9px 18px; font-size: 14px; font-weight: 600;
  transition: all .15s; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-ghost { background: transparent; font-weight: 500; }
.btn-ghost:hover { background: var(--hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-block { width: 100%; }

/* custom grid */
.custom-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; }
.cell {
  position: relative; min-height: 46px; min-width: 0; padding-top: 12px; padding-bottom: 12px;
  border: 1px dashed var(--border); border-radius: 10px;
  background: var(--bg); font-size: 12.5px; font-weight: 600;
  padding: 4px 6px; overflow: hidden; transition: all .15s;
  display: flex; align-items: center; justify-content: center; text-align: center;
  color: var(--text);
}
.cell .cell-plus { color: var(--muted); font-size: 16px; }
.cell:not(.filled):hover { border-color: var(--accent); color: var(--accent); }
.cell-add { border-style: dashed; }
.cell.filled { border-style: solid; }
.cell.filled:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.cell .cell-name { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-grid.edit-mode .cell.filled { cursor: grab; touch-action: none; }
.custom-grid.edit-mode { user-select: none; -webkit-user-select: none; }
.cell-del {
  position: absolute; top: 3px; right: 3px; z-index: 2;
  width: 17px; height: 17px; line-height: 15px; border-radius: 50%;
  background: var(--danger); color: #fff; font-size: 12px; font-weight: 700;
  text-align: center; cursor: pointer; padding: 0;
}
.cell-del:hover { filter: brightness(1.12); }
.drag-ghost {
  position: fixed; z-index: 300; pointer-events: none;
  box-shadow: 0 12px 30px rgba(16, 24, 40, .28);
  border: 1px solid var(--accent); background: var(--card); color: var(--accent);
}
.drag-src { opacity: .3; }
.drag-hint { margin-top: 10px; font-size: 12px; color: var(--muted); }

/* categories */
.cat-row {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 11px 0; border-top: 1px solid var(--border);
}
.cat-row:first-of-type { border-top: 0; padding-top: 2px; }
.cat-row:last-of-type { padding-bottom: 2px; }
.cat-label {
  flex: 0 0 128px; display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 14px; color: var(--accent);
  padding-top: 2px;
}
.cat-label .ic { width: 17px; height: 17px; }
.cat-links { flex: 1; display: flex; flex-wrap: wrap; gap: 4px 4px; }
.cat-link {
  padding: 4px 10px; border-radius: 8px; font-size: 13.5px;
  transition: all .12s;
}
.cat-link:hover { background: var(--accent-soft); color: var(--accent); }
.cat-empty { color: var(--muted); font-size: 13px; }

/* footer */
.footer { border-top: 1px solid var(--border); margin-top: 20px; padding: 16px 0 22px; }
.footer-in { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.visits { display: inline-flex; align-items: center; gap: 6px; }
.visits b { color: var(--text); font-variant-numeric: tabular-nums; }
.footer-feedback { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.footer-feedback:hover { color: var(--accent); }

/* feedback page */
.fb-card { max-width: 640px; margin: 26px auto; }
.fb-intro { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }
.fb-form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.fb-form input, .fb-form textarea {
  display: block; width: 100%; margin-top: 5px;
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; background: var(--bg); outline: none;
  font-family: inherit; resize: vertical;
}
.fb-form input:focus, .fb-form textarea:focus { border-color: var(--accent); }
.fb-actions { display: flex; gap: 8px; justify-content: flex-end; }
.fb-success { text-align: center; padding: 26px 0 12px; }
.fb-success p { color: var(--accent); font-weight: 700; font-size: 15px; margin-bottom: 16px; }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 15, 30, .45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  position: relative; width: min(400px, 100%);
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.modal-sm { width: min(360px, 100%); }
.modal-close {
  position: absolute; top: 10px; right: 12px; border: 0; background: none;
  font-size: 22px; line-height: 1; color: var(--muted);
}
.modal-close:hover { color: var(--text); }
.tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 16px; }
.tab { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.auth-form label, #linkForm label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.auth-form input, #linkForm input {
  display: block; width: 100%; margin-top: 5px;
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; background: var(--bg); outline: none;
}
.auth-form input:focus, #linkForm input:focus { border-color: var(--accent); }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 9px 18px; border-radius: 999px; font-size: 13.5px; z-index: 200;
  box-shadow: var(--shadow);
}

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .custom-grid { grid-template-columns: repeat(4, 1fr); }
  .user-btn .user-name { max-width: 90px; }
}
@media (max-width: 640px) {
  .topbar-in { flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; row-gap: 6px; }
  .brand { order: 1; }
  .top-actions { order: 2; margin-left: auto; }
  .custom-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .cat-row { flex-direction: column; gap: 6px; }
  .cat-label { flex: none; }
  .lang-panel, .user-panel, .engine-menu { right: 8px; left: 8px; width: auto; }
  .auth-panel { right: 8px; left: 8px; width: auto; }
  .search-row { flex-wrap: wrap; }
  #q { flex-basis: 100%; order: 1; }
  .engine-dd { order: 2; flex: 1; }
  .engine-btn { width: 100%; justify-content: space-between; }
  .btn-primary { order: 3; flex: 1; }
  .search-ic { display: none; }
}

/* user center page */
.user-links { list-style: none; margin: 0 0 16px; padding: 0; }
.user-links li {
  display: flex; align-items: baseline; gap: 10px;
  padding: 9px 4px; border-bottom: 1px solid var(--border);
}
.user-links li a { font-weight: 600; color: var(--accent); min-width: 130px; }
.user-link-url { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
