/* ============================================================
   千年虫与爱丽丝们 — 基础层
   双主题：白昼梦核 / 深夜 VHS
   ============================================================ */

:root {
  /* 纸与雾（白昼） */
  --bg:        #e7e9ea;
  --bg-a:      #eef0f1;
  --bg-b:      #e4e8ea;
  --bg-c:      #e7e1e3;
  --bg-d:      #eae8e8;

  --fog-a:     rgba(190, 186, 230, 0.9);
  --fog-b:     rgba(176, 209, 205, 0.78);
  --fog-c:     rgba(233, 195, 204, 0.7);
  --window:    rgba(255, 255, 255, 0.9);
  --vignette:  rgba(84, 92, 100, 0.2);

  /* 墨 */
  --ink:       #16181b;
  --ink-2:     #4c5258;
  --ink-3:     #757b81;
  --ink-4:     #9aa0a5;

  /* 线与面 */
  --line:      rgba(22, 24, 27, 0.14);
  --line-2:    rgba(22, 24, 27, 0.07);
  --edge:      rgba(255, 255, 255, 0.9);
  --surface:   rgba(255, 255, 255, 0.86);
  --surface-2: rgba(255, 255, 255, 0.52);
  --surface-3: #ffffff;
  --panel:     rgba(255, 255, 255, 0.56);
  --rail:      rgba(255, 255, 255, 0.32);
  --chat:      rgba(255, 255, 255, 0.48);
  --bubble:    #ffffff;
  --hover:     rgba(255, 255, 255, 0.6);
  --card-a:    rgba(255, 255, 255, 0.86);
  --card-b:    rgba(255, 255, 255, 0.52);

  /* 操作 */
  --btn:       #16181b;
  --btn-ink:   #eef0f1;

  --ok:        #5f8f6c;
  --warn:      #a8544a;

  /* 幽灵图标 */
  --ghost-bg:  #d2d5d6;
  --ghost:     #2b2f34;

  /* 眼睛 */
  --eye-line:    rgba(22, 24, 27, 0.82);
  --eye-soft:    rgba(22, 24, 27, 0.15);
  --eye-iris-in: rgba(40, 32, 27, 0.96);
  --eye-iris-mid: rgba(104, 80, 62, 0.5);
  --eye-iris-out: rgba(104, 80, 62, 0.04);
  --eye-pupil:   rgba(10, 11, 13, 0.92);
  --eye-glint:   rgba(250, 248, 244, 0.75);
  --eye-sclera:  rgba(250, 249, 246, 0.45);
  --eye-accent:  #9a4a42;
  --eye-veil:    rgba(10, 12, 14, 0.42);

  /* 质感 */
  --scan:      rgba(22, 24, 27, 0.028);
  --grain:     0.055;
  --shadow-card: inset 0 1px 0 rgba(255, 255, 255, 0.9),
                 0 2px 10px rgba(52, 62, 72, 0.06),
                 0 44px 90px -38px rgba(52, 62, 72, 0.42);
  --shadow-panel: 0 30px 70px -52px rgba(46, 56, 66, 0.7);

  /* 字体 */
  --sans:  "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --serif: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
  --mono:  "Cascadia Mono", "SF Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
}

html[data-theme="night"] {
  --bg:        #090b0d;
  --bg-a:      #0b0e11;
  --bg-b:      #0a0c0f;
  --bg-c:      #0d0a0f;
  --bg-d:      #08090b;

  --fog-a:     rgba(110, 78, 190, 0.22);
  --fog-b:     rgba(36, 150, 160, 0.16);
  --fog-c:     rgba(190, 56, 116, 0.12);
  --window:    rgba(150, 190, 220, 0.1);
  --vignette:  rgba(0, 0, 0, 0.72);

  --ink:       #e9edef;
  --ink-2:     #b3bcc1;
  --ink-3:     #8a949a;
  --ink-4:     #6d777e;

  --line:      rgba(233, 237, 239, 0.16);
  --line-2:    rgba(233, 237, 239, 0.07);
  --edge:      rgba(255, 255, 255, 0.08);
  --surface:   rgba(17, 21, 24, 0.86);
  --surface-2: rgba(17, 21, 24, 0.55);
  --surface-3: #15191c;
  --panel:     rgba(17, 21, 24, 0.62);
  --rail:      rgba(10, 13, 15, 0.55);
  --chat:      rgba(15, 19, 22, 0.58);
  --bubble:    #171c1f;
  --hover:     rgba(255, 255, 255, 0.06);
  --card-a:    rgba(19, 24, 27, 0.94);
  --card-b:    rgba(13, 17, 20, 0.72);

  --btn:       #e9edef;
  --btn-ink:   #0b0d0f;

  --ok:        #7fb389;
  --warn:      #d07b72;

  --ghost-bg:  #1b2023;
  --ghost:     #dfe4e6;

  /* 眼睛 */
  --eye-line:    rgba(236, 240, 242, 0.82);
  --eye-soft:    rgba(236, 240, 242, 0.12);
  --eye-iris-in: rgba(232, 222, 206, 0.9);
  --eye-iris-mid: rgba(170, 154, 134, 0.45);
  --eye-iris-out: rgba(170, 154, 134, 0.03);
  --eye-pupil:   rgba(8, 9, 11, 0.94);
  --eye-glint:   rgba(255, 255, 255, 0.65);
  --eye-sclera:  rgba(8, 10, 12, 0.42);
  --eye-accent:  #c9706a;
  --eye-veil:    rgba(0, 0, 0, 0.55);

  --scan:      rgba(255, 255, 255, 0.03);
  --grain:     0.09;
  --shadow-card: inset 0 1px 0 rgba(255, 255, 255, 0.06),
                 0 50px 110px -40px rgba(0, 0, 0, 0.85);
  --shadow-panel: 0 40px 80px -50px rgba(0, 0, 0, 0.9);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

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

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background 0.45s ease, color 0.45s ease;
}

h1, h2, h3, h4, p, dl, dd, figure { margin: 0; }

a { color: inherit; }

button { font: inherit; color: inherit; }

input, textarea, select, button { -webkit-tap-highlight-color: transparent; }

::selection {
  background: rgba(110, 110, 120, 0.32);
}

:focus-visible {
  outline: 1px solid var(--ink-3);
  outline-offset: 3px;
}

/* 夜间标题的一点点色差 */
html[data-theme="night"] h1,
html[data-theme="night"] h2,
html[data-theme="night"] .app__id h1 {
  text-shadow: 1px 0 rgba(255, 60, 140, 0.18), -1px 0 rgba(0, 220, 255, 0.14);
}

/* ---------- 通用 ---------- */
.mono {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.kicker {
  display: block;
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.24em;
  color: var(--ink-4);
  text-transform: uppercase;
}

.dim { color: var(--ink-3); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.grain {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  background-size: 260px 260px;
  opacity: var(--grain);
  mix-blend-mode: multiply;
  pointer-events: none;
}

html[data-theme="night"] .grain { mix-blend-mode: screen; }

/* ---------- 主题开关 ---------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.theme-toggle:hover { border-color: var(--ink-3); }

.theme-toggle b {
  font-weight: 500;
  color: var(--ink);
}

.theme-toggle .sep { opacity: 0.5; }

html[data-theme="light"] .theme-toggle .t-day,
html[data-theme="night"] .theme-toggle .t-night {
  color: var(--ink);
  font-weight: 600;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  font-size: 11px;
  letter-spacing: 0.18em;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.btn:hover { background: var(--hover); }

.btn--primary {
  border-color: var(--btn);
  background: var(--btn);
  color: var(--btn-ink);
  letter-spacing: 0.3em;
}

.btn--primary:hover { opacity: 0.88; background: var(--btn); }

.btn--ghost { color: var(--ink-3); }

.btn--danger {
  border-color: var(--warn);
  color: var(--warn);
}

.btn--danger:hover { background: rgba(168, 84, 74, 0.08); }

.btn--sm { height: 30px; padding: 0 12px; font-size: 10px; letter-spacing: 0.12em; }

/* ---------- 表单 ---------- */
.field { position: relative; }

.field + .field { margin-top: 17px; }

.field__label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 7px;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--ink-2);
}

.field__label small {
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.16em;
  color: var(--ink-4);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.2s ease;
  appearance: none;
}

.field textarea { min-height: 84px; resize: vertical; line-height: 1.75; }

.field input:focus,
.field textarea:focus,
.field select:focus { border-color: var(--ink-3); }

.field input::placeholder,
.field textarea::placeholder { color: var(--ink-4); }

.field select option { background: var(--surface-3); color: var(--ink); }

.field__hint {
  margin-top: 6px;
  color: var(--ink-4);
  font-size: 10.5px;
  line-height: 1.7;
  letter-spacing: 0.03em;
}

.field__row { position: relative; }

.field__row input { padding-right: 52px; }

.peek {
  position: absolute;
  right: 10px;
  bottom: 12px;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  cursor: pointer;
}

.peek:hover { color: var(--ink); }

/* ---------- 面板 ---------- */
.panel {
  padding: 17px 18px;
  border: 1px solid var(--edge);
  border-radius: 4px;
  background: var(--panel);
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.12em;
  color: var(--ink-3);
  white-space: nowrap;
}

.pill--ok { border-color: rgba(95, 143, 108, 0.4); color: var(--ok); }

.pill--warn { border-color: rgba(168, 84, 74, 0.45); color: var(--warn); }

/* ---------- 空状态 ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  padding: 44px 24px;
  border: 1px dashed var(--line);
  border-radius: 4px;
  text-align: center;
}

.empty__ghost {
  width: 44px;
  height: 44px;
  margin-bottom: 18px;
  opacity: 0.42;
  filter: grayscale(1);
}

.empty h3 {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.empty p {
  max-width: 340px;
  margin-top: 10px;
  color: var(--ink-3);
  font-size: 12px;
  line-height: 1.95;
  letter-spacing: 0.04em;
}

.empty .btn { margin-top: 20px; }

/* ---------- 提示条 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 90;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface-3);
  color: var(--ink);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  box-shadow: 0 14px 34px -20px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 表格 ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.table th {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: 8.5px;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: 10px;
  border-bottom: 1px solid var(--line-2);
  color: var(--ink-2);
  vertical-align: middle;
}

.table tr:last-child td { border-bottom: 0; }

.table .t-ink { color: var(--ink); }
.table .t-mono { font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; }
.table .t-actions { text-align: right; white-space: nowrap; }

.table .btn { height: 26px; padding: 0 9px; font-size: 9px; }

/* ---------- VHS 层（仅夜间） ---------- */
.vhs { display: none; }

html[data-theme="night"] .vhs {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 60;
  overflow: hidden;
  pointer-events: none;
}

.vhs__scan {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(to bottom,
      rgba(255, 255, 255, 0) 0px,
      rgba(255, 255, 255, 0) 2px,
      rgba(255, 255, 255, 0.028) 2px,
      rgba(255, 255, 255, 0.028) 3px);
  opacity: 0.9;
}

.vhs__track {
  position: absolute;
  left: 0;
  right: 0;
  height: 14vh;
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.035), transparent);
  animation: vhs-track 14s linear infinite;
}

@keyframes vhs-track {
  0%   { top: -20%; }
  100% { top: 120%; }
}

.vhs__hud {
  position: absolute;
  inset: 0;
  color: rgba(255, 255, 255, 0.52);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.vhs__rec {
  position: absolute;
  left: 22px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.vhs__rec i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ff4d5e;
  box-shadow: 0 0 10px rgba(255, 77, 94, 0.6);
  animation: rec-blink 1.8s steps(2) infinite;
}

@keyframes rec-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0.25; }
}

.vhs__time { position: absolute; right: 22px; bottom: 16px; }

.vhs__mode { position: absolute; right: 22px; top: 16px; opacity: 0.5; }

/* VHS 的轻微色差和滚动条 */
html[data-theme="night"] .vhs__hud::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  top: 0;
  height: 1px;
  background: rgba(255, 255, 255, 0.2);
  animation: vhs-jitter 9s steps(1) infinite;
}

@keyframes vhs-jitter {
  0%, 96%, 100% { transform: translateY(0); opacity: 0.6; }
  97% { transform: translateY(38vh); opacity: 0.9; }
  98% { transform: translateY(63vh); opacity: 0.4; }
  99% { transform: translateY(12vh); opacity: 0.8; }
}

@media (max-width: 960px) {
  .vhs__hud { display: none; }
}

/* ---------- 动效降低 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
