/* 色彩与 Farm 同源：深色默认，浅色跟随系统；html[data-theme] 手动覆盖 */
:root {
  --bg: #090e10; --surface: #10171a; --surface-2: #172125; --line: #22313a;
  --text: #eaf3f1; --muted: #8ba3a8; --accent: #5eead4; --accent-ink: #06201c;
  --ok: #5eead4; --bad: #f58d8d; --s2: #7cb4f5; --s4: #c9a0f5;
  --glass: rgba(16, 23, 26, .72);
  --shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 16px 44px rgba(0,0,0,.45);
  --scrim: linear-gradient(180deg, rgba(9,14,16,.78), rgba(9,14,16,.52) 45%, rgba(9,14,16,.82));
  --warm: radial-gradient(60% 55% at 18% 18%, rgba(245,141,141,.30), transparent 70%),
          radial-gradient(55% 50% at 82% 26%, rgba(201,160,245,.24), transparent 70%),
          radial-gradient(60% 55% at 55% 100%, rgba(240,184,110,.24), transparent 70%), #140e10;
  --grid-dot: rgba(234,243,241,.06);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef3f2; --surface: #ffffff; --surface-2: #f0f5f4; --line: #d9e4e2;
    --text: #13201f; --muted: #587270; --accent: #0e8f7b; --accent-ink: #ffffff;
    --ok: #0e8f7b; --bad: #b3362f; --s2: #2f6fc4; --s4: #8a4fc4;
    --glass: rgba(255, 255, 255, .78);
    --shadow: 0 1px 2px rgba(20,32,31,.06), 0 14px 36px rgba(20,32,31,.10);
    --scrim: linear-gradient(180deg, rgba(238,243,242,.86), rgba(238,243,242,.68) 45%, rgba(238,243,242,.88));
    --warm: radial-gradient(60% 55% at 18% 18%, rgba(245,141,141,.30), transparent 70%),
            radial-gradient(55% 50% at 82% 26%, rgba(201,160,245,.26), transparent 70%),
            radial-gradient(60% 55% at 55% 100%, rgba(240,184,110,.30), transparent 70%), #f7efea;
    --grid-dot: rgba(19,32,31,.07);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #eef3f2; --surface: #ffffff; --surface-2: #f0f5f4; --line: #d9e4e2;
  --text: #13201f; --muted: #587270; --accent: #0e8f7b; --accent-ink: #ffffff;
  --ok: #0e8f7b; --bad: #b3362f; --s2: #2f6fc4; --s4: #8a4fc4;
  --glass: rgba(255, 255, 255, .78);
  --shadow: 0 1px 2px rgba(20,32,31,.06), 0 14px 36px rgba(20,32,31,.10);
  --scrim: linear-gradient(180deg, rgba(238,243,242,.86), rgba(238,243,242,.68) 45%, rgba(238,243,242,.88));
  --warm: radial-gradient(60% 55% at 18% 18%, rgba(245,141,141,.30), transparent 70%),
          radial-gradient(55% 50% at 82% 26%, rgba(201,160,245,.26), transparent 70%),
          radial-gradient(60% 55% at 55% 100%, rgba(240,184,110,.30), transparent 70%), #f7efea;
  --grid-dot: rgba(19,32,31,.07);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); overflow: hidden;
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Segoe UI", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased; transition: background-color .3s;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 背景 ---------- */
#bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
#bg > * { position: absolute; inset: 0; transition: opacity .8s ease; }
.bg-ambient {
  background:
    radial-gradient(900px 560px at 6% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
    radial-gradient(800px 520px at 100% 0%, color-mix(in srgb, var(--s4) 10%, transparent), transparent 70%),
    radial-gradient(900px 600px at 70% 110%, color-mix(in srgb, var(--s2) 8%, transparent), transparent 70%);
  animation: drift 30s ease-in-out infinite alternate;
}
@keyframes drift { to { transform: translate3d(-1.5%, 1.5%, 0) scale(1.04); } }
.bg-grid {
  background-image: radial-gradient(var(--grid-dot) 1px, transparent 1.2px);
  background-size: 26px 26px;
  -webkit-mask-image: radial-gradient(ellipse 80% 70% at 50% 50%, #000 35%, transparent 85%);
  mask-image: radial-gradient(ellipse 80% 70% at 50% 50%, #000 35%, transparent 85%);
}
.bg-img { background: var(--warm); background-size: cover; background-position: center; opacity: 0; transform: scale(1.03); }
.bg-scrim { background: var(--scrim); opacity: 0; }
body.nsfw .bg-img, body.nsfw .bg-scrim { opacity: 1; }
body.nsfw.no-bg .bg-scrim { opacity: .25; }
body.nsfw .bg-ambient { opacity: 0; }
body.nsfw .bg-grid { opacity: .5; }

/* ---------- 顶栏 ---------- */
.top {
  position: fixed; z-index: 5; inset: 0 0 auto 0; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 20px 12px; pointer-events: none;
}
.top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark {
  position: relative; flex: none; width: 34px; height: 34px; border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--s2));
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 30%, transparent);
}
.mark i { position: absolute; inset: 9px; border-radius: 50%; border: 2px solid rgba(255,255,255,.92); border-right-color: transparent; transform: rotate(-30deg); }
.brand-txt { min-width: 0; }
h1 { margin: 0; font-size: 16px; line-height: 1.2; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.tools { display: flex; align-items: center; gap: 8px; }
.search, .icon-btn, .sfw, .legend, .card {
  background: var(--glass); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(16px) saturate(1.2); backdrop-filter: blur(16px) saturate(1.2);
}
.search {
  display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 8px 0 11px; border-radius: 11px; color: var(--muted);
  transition: border-color .2s, box-shadow .2s;
}
.search svg { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.search input { background: none; border: 0; outline: 0; color: var(--text); width: 168px; font: inherit; font-size: 13px; padding: 0; }
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { display: none; }
.search kbd {
  font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); padding: 3px 6px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface-2);
}
.search:focus-within kbd { visibility: hidden; }
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; cursor: pointer; color: var(--muted); padding: 0;
  transition: color .2s, border-color .2s;
}
.icon-btn:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; display: none; }
.icon-btn svg .fill { fill: currentColor; stroke: none; }
.icon-btn[data-mode="auto"] .i-auto, .icon-btn[data-mode="light"] .i-light, .icon-btn[data-mode="dark"] .i-dark { display: block; }

.sfw {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px 0 8px; border-radius: 999px; cursor: pointer;
  font-size: 11.5px; font-weight: 650; letter-spacing: .08em; color: var(--text); transition: border-color .2s;
}
.sfw:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.sfw i { position: relative; width: 30px; height: 18px; border-radius: 999px; background: var(--accent); transition: background .25s; }
.sfw i::after { content: ""; position: absolute; top: 2px; left: 14px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: left .25s; }
.sfw[aria-pressed="false"] i { background: #e8798f; }
.sfw[aria-pressed="false"] i::after { left: 2px; }
.sfw b { min-width: 26px; text-align: left; }

/* ---------- 画布 ---------- */
#c { position: fixed; inset: 0; z-index: 1; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- 底栏：图例 + 元信息 ---------- */
.foot {
  position: fixed; z-index: 4; inset: auto 0 0 0; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px calc(12px + env(safe-area-inset-bottom)); pointer-events: none;
}
.legend { pointer-events: auto; display: flex; gap: 2px; padding: 3px; border-radius: 12px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.legend::-webkit-scrollbar { display: none; }
.legend button {
  flex: none; display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 10px; border: 0; background: none; border-radius: 9px;
  font-size: 12px; color: var(--text); cursor: pointer; transition: opacity .2s, background .2s;
}
.legend button:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.legend button[aria-pressed="false"] { opacity: .38; }
.legend button[aria-pressed="false"] .dot { background: transparent !important; box-shadow: inset 0 0 0 1.5px var(--c); }
.legend .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--c); }
.legend .dot.sq { border-radius: 2px; }
.legend em { font-style: normal; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.meta { display: flex; gap: 14px; font-size: 11.5px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- 卡片 ---------- */
.card {
  position: fixed; z-index: 6; left: 0; top: 0; width: 312px; max-width: calc(100vw - 24px); padding: 16px; border-radius: 18px;
  box-shadow: var(--shadow); pointer-events: none; opacity: 0; transform: translateY(6px) scale(.985);
  transition: opacity .16s ease, transform .16s ease;
}
.card.show { opacity: 1; transform: none; }
.card.pinned { pointer-events: auto; }
.card .head { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); }
.card .kind { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px 2px 7px; border-radius: 999px; background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); font-weight: 600; }
.card .kind i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.card .close { margin-left: auto; width: 26px; height: 26px; border-radius: 8px; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 17px; line-height: 1; display: none; }
.card.pinned .close { display: grid; place-items: center; }
.card .close:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
.card h2 { margin: 8px 0 4px; font-size: 17px; line-height: 1.3; font-weight: 650; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card .st { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 500; color: var(--muted); }
.card .st i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.card .st.up { color: var(--ok); } .card .st.up i { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.card .st.down { color: var(--bad); } .card .st.down i { background: var(--bad); }
.card p { margin: 0 0 12px; color: color-mix(in srgb, var(--text) 82%, var(--muted)); font-size: 13px; line-height: 1.6; }
.card .sec { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; display: grid; grid-template-columns: 52px 1fr; gap: 7px 10px; font-size: 12px; align-items: baseline; }
.card .sec dt { color: var(--muted); }
.card .sec dd { margin: 0; display: flex; flex-wrap: wrap; gap: 4px 6px; min-width: 0; }
.card .mono { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.card .chip { display: inline-flex; align-items: center; gap: 5px; padding: 1px 7px; border-radius: 6px; font-size: 11.5px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text); }
.card .chip i { width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
.card .chip.warn { color: var(--bad); }
.card .actions { display: flex; gap: 8px; margin-top: 14px; }
.card .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 10px;
  font-size: 13px; font-weight: 600; text-decoration: none; background: var(--accent); color: var(--accent-ink); flex: 1;
}
.card .btn:hover { filter: brightness(1.06); }
.card .tip { margin-top: 12px; font-size: 11px; color: var(--muted); }

@media (max-width: 1180px) { .meta .hint { display: none; } }
@media (max-width: 720px) {
  .top { padding: calc(10px + env(safe-area-inset-top)) 12px 8px; gap: 8px; }
  .mark { width: 30px; height: 30px; border-radius: 10px; } .mark i { inset: 8px; }
  .brand { gap: 9px; }
  .brand p { font-size: 11px; }
  .search { width: 36px; padding: 0; justify-content: center; transition: width .2s; }
  .search { cursor: pointer; }
  .search input { width: 0; }
  .search kbd { display: none; }
  .search:focus-within { width: 150px; padding: 0 10px; justify-content: flex-start; }
  .search:focus-within input { width: 100%; }
  .sfw { padding: 0 10px 0 7px; }
  .foot { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
  .legend { max-width: 100%; }
  .meta { display: none; }
  .card {
    left: 12px !important; right: 12px; top: auto !important; bottom: calc(60px + env(safe-area-inset-bottom));
    width: auto; max-width: none; max-height: 62vh; overflow-y: auto;
  }
}
@media (max-width: 380px) { .brand p { display: none; } }
@media (prefers-reduced-motion: reduce) {
  .bg-ambient { animation: none; }
  .card, #bg > *, .sfw i, .sfw i::after { transition: none; }
}
