/* 重置 + 排版 + 通用控件。这一层不含任何布局，布局在 layout.css */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--tx);
  font-family: var(--font);
  font-size: var(--t-base);
  line-height: var(--lh-base);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--accent-dim); }

/* 统一的可见焦点环。键盘操作是这个系统的主要交互方式，焦点必须看得见 */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
:focus:not(:focus-visible) { outline: none; }

h1, h2, h3, h4 { font-weight: 500; line-height: var(--lh-tight); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ─────────────────── 按钮 ─────────────────── */

.btn {
  font: inherit;
  font-size: var(--t-sm);
  line-height: 1.4;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--tx-2);
  cursor: pointer;
  transition: background .12s var(--ease), color .12s var(--ease), border-color .12s var(--ease);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-3); color: var(--tx); border-color: var(--tx-3); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #04070d;
  font-weight: 500;
}
.btn-primary:hover:not(:disabled) { background: #7fb2ff; border-color: #7fb2ff; color: #04070d; }

.btn-danger { border-color: rgba(224, 108, 90, .45); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(224, 108, 90, .12); color: var(--danger); border-color: var(--danger); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--tx-3); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--tx); border-color: transparent; }

.btn-sm { font-size: var(--t-xs); padding: var(--s-1) var(--s-3); }
.btn-block { width: 100%; justify-content: center; }
.btn-icon {
  width: 38px; height: 38px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 15px; border-radius: var(--r-sm);
}

/* ─────────────────── 表单 ─────────────────── */

input, textarea, select {
  font: inherit;
  font-size: var(--t-base);
  width: 100%;
  background: var(--surface-2);
  color: var(--tx);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: var(--s-3) var(--s-3);
  transition: border-color .12s var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--tx-3); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; line-height: var(--lh-base); min-height: 60px; }
select { cursor: pointer; }

.field { margin-bottom: var(--s-4); }
.field > label {
  display: block;
  font-size: var(--t-sm);
  color: var(--tx-2);
  margin-bottom: var(--s-2);
  font-weight: 400;
}
.field-hint { font-size: var(--t-xs); color: var(--tx-3); margin-top: var(--s-2); line-height: 1.6; }

.check { display: flex; align-items: center; gap: var(--s-2); font-size: var(--t-sm); color: var(--tx-2); }
.check input { width: auto; }

/* ─────────────────── 层级徽章 ─────────────────── */
/* 四个层级色只在这里出现。外溢到边框/正文就会变成六色混战 */

.kind {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  font-size: var(--t-xs);
  font-weight: 600;
  padding: 2px var(--s-2);
  border-radius: var(--r-sm);
  letter-spacing: .04em;
}
.kind-dao { background: rgba(224, 180, 69, .16); color: var(--dao); }
.kind-fa  { background: rgba(79, 184, 148, .16); color: var(--fa); }
.kind-shu { background: rgba(107, 168, 245, .16); color: var(--shu); }
.kind-qi  { background: rgba(185, 142, 222, .16); color: var(--qi); }

/* ─────────────────── 标签 / 芯片 ─────────────────── */

.tag {
  font-size: var(--t-xs);
  color: var(--tx-3);
  background: var(--surface-2);
  padding: 2px var(--s-2);
  border-radius: var(--r-sm);
  white-space: nowrap;
}
.tag-warn { color: var(--warn); background: rgba(240, 136, 90, .12); }
.tag-ok   { color: var(--ok);   background: rgba(79, 184, 148, .12); }

.chip {
  font: inherit;
  font-size: var(--t-sm);
  padding: var(--s-1) var(--s-3);
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--tx-3);
  cursor: pointer;
  transition: all .12s var(--ease);
}
.chip:hover { color: var(--tx); border-color: var(--tx-3); }
.chip[aria-pressed="true"] {
  background: var(--accent-dim);
  border-color: var(--accent-line);
  color: var(--accent);
}

/* ─────────────────── 卡片 ─────────────────── */
/* 内边距从 14px 提到 20px，卡间距从 10px 提到 16px —— 密度是旧版最大的问题 */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: var(--s-5);
  margin-bottom: var(--s-4);
}
.card-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin-bottom: var(--s-3);
}
.card-row:last-child { margin-bottom: 0; }
.card.is-selected { border-color: var(--accent-line); box-shadow: inset 0 0 0 1px var(--accent-line); }
.card.is-done { opacity: .4; }

.stmt { font-size: var(--t-md); line-height: 1.7; }
.cond {
  font-size: var(--t-base);
  color: var(--tx-2);
  border-left: 2px solid var(--line-strong);
  padding-left: var(--s-3);
  margin: var(--s-3) 0;
}
.meta {
  font-size: var(--t-xs);
  color: var(--tx-3);
  line-height: 1.6;
}
.meta.mono { font-family: var(--mono); }
.actions { display: flex; gap: var(--s-2); flex-wrap: wrap; margin-top: var(--s-4); }

/* ─────────────────── 提示 / 空状态 ─────────────────── */

.hint {
  font-size: var(--t-sm);
  color: var(--tx-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent-line);
  border-radius: var(--r-sm);
  padding: var(--s-3) var(--s-4);
  margin-bottom: var(--s-5);
  line-height: 1.7;
}
.empty {
  color: var(--tx-3);
  padding: var(--s-8) var(--s-4);
  text-align: center;
  font-size: var(--t-base);
  line-height: 1.9;
}
.empty strong { color: var(--tx-2); font-weight: 500; }
.err { color: var(--warn); font-size: var(--t-base); padding: var(--s-4) 0; line-height: 1.7; }

kbd {
  font-family: var(--mono);
  font-size: var(--t-xs);
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
  padding: 1px var(--s-2);
  color: var(--tx-2);
}

/* ─────────────────── 分节 ─────────────────── */

.section { margin-bottom: var(--s-7); }
.section > h3 {
  font-size: var(--t-sm);
  color: var(--tx-3);
  margin-bottom: var(--s-4);
  font-weight: 500;
  letter-spacing: .04em;
}
.section-note { font-size: var(--t-sm); color: var(--tx-3); margin-top: var(--s-3); line-height: 1.7; }

/* ─────────────────── 骨架屏 ─────────────────── */

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-sm);
  height: 1em;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ─────────────────── Toast ─────────────────── */

.toasts {
  position: fixed;
  bottom: var(--s-5);
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: var(--s-3) var(--s-4);
  font-size: var(--t-sm);
  box-shadow: var(--shadow);
  max-width: 90vw;
  animation: toast-in .18s var(--ease);
}
.toast-err { border-color: rgba(240, 136, 90, .5); color: var(--warn); }
.toast-ok  { border-color: rgba(79, 184, 148, .5); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ─────────────────── 弹层 ─────────────────── */
/* 旧版用一个 confirm() 做三选一（确定=只存我的 / 取消=存全部），
   于是「取消」反而执行了动作，没有任何中止的办法。这里换成真正的弹层。 */

.modal-back {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .66);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: var(--s-4);
  animation: fade-in .14s var(--ease);
}
@keyframes fade-in { from { opacity: 0; } }
.modal {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
}
.modal h3 { font-size: var(--t-md); margin-bottom: var(--s-3); }
.modal-body { font-size: var(--t-base); color: var(--tx-2); line-height: 1.8; margin-bottom: var(--s-5); }
.modal-actions { display: flex; gap: var(--s-2); justify-content: flex-end; flex-wrap: wrap; }
