:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --ink: #1c1e21;
  --ink-2: #555b63;
  --ink-3: #80868e;
  --line: #e2e0da;
  --accent: #2e6b66;
  --accent-ink: #ffffff;
  --accent-soft: #e1ecea;
  --accent-soft-ink: #24524e;
  --danger: #b0412f;
  --danger-soft: #f6e3df;
  --mark: #f3dc8f;
  --toast: #25282c;
  --toast-ink: #f3f2ee;
  --shadow: 0 1px 2px rgba(20, 22, 25, .04), 0 6px 18px -12px rgba(20, 22, 25, .18);
  --radius: 10px;
  --font: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
  /* 等宽字在前管英文和数字，中文落到后面的中文字体 */
  --mono: "Cascadia Mono", "Cascadia Code", Consolas, "SF Mono", Menlo, "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei",
    ui-monospace, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131416;
    --surface: #1b1d20;
    --surface-2: #24272b;
    --ink: #e6e4df;
    --ink-2: #aab0b7;
    --ink-3: #80868e;
    --line: #2d3035;
    --accent: #5aaea5;
    --accent-ink: #0d1413;
    --accent-soft: #1d302e;
    --accent-soft-ink: #92d2c9;
    --danger: #e27561;
    --danger-soft: #3a211c;
    --mark: #6b5a1c;
    --toast: #e6e4df;
    --toast-ink: #16181a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -14px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
html { scrollbar-gutter: stable; } /* 放大时锁住背后的滚动，页面不会左右跳 */
html.zoom-open { overflow: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ── 顶栏 ── */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.bar-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand { font-weight: 650; font-size: 17px; letter-spacing: -.01em; }
.device-slot { margin-left: auto; display: flex; align-items: center; gap: 4px; min-width: 0; }
.dev-label { color: var(--ink-3); font-size: 13px; white-space: nowrap; }
.dev-name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.dev-input { width: 200px; }

/* ── 通用 ── */
.page { max-width: 880px; margin: 0 auto; padding: 16px 16px 64px; }
.btn {
  font: inherit;
  font-size: 14px;
  line-height: 20px;
  padding: 6px 14px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  color: var(--ink-2);
  background: transparent;
}
.btn:focus-visible, .chip:focus-visible, .tag:focus-visible, .link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.accent { background: var(--accent-soft); color: var(--accent-soft-ink); }
.btn.accent:hover { filter: brightness(.97); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.btn.soft { background: var(--surface-2); color: var(--ink-2); }
.btn.soft:hover { color: var(--ink); filter: brightness(.97); }
.btn.on-dark { background: rgba(255, 255, 255, .14); color: #fff; }
.btn.on-dark:hover { background: rgba(255, 255, 255, .24); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.link {
  font: inherit;
  font-size: 13px;
  border: 0;
  background: none;
  padding: 0 2px;
  color: var(--accent-soft-ink);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.field {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  min-width: 0;
}
.field::placeholder, textarea::placeholder { color: var(--ink-3); }
.field:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ── 输入区：上面一行标签 + 保存（靠右），下面一整块文字框；和下面每一条的排法一致 ── */
.compose-head { display: flex; align-items: flex-start; gap: 10px; margin: 0 2px 6px; }
.compose-tags { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 30px; }
.compose-chips { display: contents; } /* 标签和新标签输入框在同一行里一起换行 */
.tag-new { flex: 1; min-width: 150px; max-width: 240px; padding: 3px 8px; font-size: 13px; }
.compose-box {
  display: block;
  width: 100%;
  min-height: 96px;
  resize: vertical;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.65;
}
.compose-box::placeholder { font-family: var(--font); }
.compose-box:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

/* 分隔线：「添加」和「搜索」之间、「搜索」和下面的条目之间 */
.divider { border: 0; border-top: 1px solid var(--line); margin: 20px 0 16px; }

/* ── 筛选 ── */
.filters { display: flex; flex-direction: column; gap: 10px; }
.search { width: 100%; font-size: 15px; padding: 9px 12px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row-label { color: var(--ink-3); font-size: 12.5px; margin-right: 4px; white-space: nowrap; }
.chip {
  font: inherit;
  font-size: 13px;
  line-height: 20px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 0;
  background: var(--surface-2);
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
}
.chip .n { color: var(--ink-3); margin-left: 5px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.chip[aria-pressed="true"] .n { color: inherit; opacity: .75; }
/* 选了多个标签时：同时包含 / 包含任一 */
.seg { display: inline-flex; margin-left: 6px; padding: 2px; border-radius: 8px; background: var(--surface-2); }
.seg-btn {
  font: inherit;
  font-size: 12.5px;
  line-height: 18px;
  padding: 2px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
}
.seg-btn[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.summary { display: flex; gap: 12px; align-items: baseline; color: var(--ink-3); font-size: 13px; }

/* ── 列表：每条两行，第一行时间 / 机器 / 标签，第二行内容框 ── */
.list { margin-top: 0; }
/* 容器查询：100cqw = 这一条的宽度。框最高到 16:9（56.25cqw），再多的内容在框里滑 */
.item { container-type: inline-size; margin-bottom: 18px; }
.item.pending { opacity: .65; }

/* 第一行：时间 / 机器 / 标签在左（放不下就换行），按钮固定在右上 */
.meta { display: flex; align-items: flex-start; gap: 10px; margin: 0 2px 6px; }
.meta-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  min-height: 26px;
  color: var(--ink-3);
  font-size: 12.5px;
}
.actions { flex: none; display: flex; gap: 4px; }
.actions .btn, .compose-head .btn { font-size: 12.5px; line-height: 18px; padding: 4px 10px; border-radius: 7px; }
.compose-head .btn { padding: 5px 14px; font-size: 13px; }
.meta .when { color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.meta .who, .meta .edited { white-space: nowrap; }
.meta .bad { color: var(--danger); }
.tags { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.tag {
  font: inherit;
  font-size: 12.5px;
  line-height: 18px;
  padding: 1px 8px;
  border: 0;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-soft-ink);
  cursor: pointer;
}

/* 内容框：唯一的一层框 */
.box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.item.failed .box { border-color: var(--danger); }
.scroll {
  max-height: calc(56.25cqw - 2px); /* 加上框的上下边框，整个框正好不超过 16:9 */
  overflow: auto;
  padding: 10px 14px;
  scrollbar-width: thin;
}
.code {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.note { color: var(--ink-3); font-size: 12.5px; margin-top: 6px; font-family: var(--font); }

.pic { padding: 8px; }
/* 图片一律居中：先限制在 16:9 以内，再把最长边贴到框的边 */
.media { display: block; width: 100%; border: 0; padding: 0; background: none; cursor: zoom-in; }
.media.still { cursor: default; }
.thumb {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(56.25cqw - 18px);
  margin: 0 auto;
  object-fit: contain;
  object-position: center;
  border-radius: 6px;
}

.empty { text-align: center; color: var(--ink-3); padding: 56px 16px; }
.empty-title { color: var(--ink-2); font-size: 16px; margin-bottom: 6px; }
.sentinel { height: 1px; }

/* ── 编辑：原地展开，标签输入和按钮都在第一行，框里只放要改的文字 ── */
.tag-input { flex: 1; min-width: 160px; padding: 3px 8px; font-size: 13px; }
.code-edit {
  display: block;
  width: 100%;
  min-height: 96px;
  max-height: calc(56.25cqw - 2px); /* 和看的时候一样，最高到 16:9 */
  resize: vertical;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 14px;
  background: transparent;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.65;
}
.code-edit:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ── 放大查看：整屏看一条，其他部分变暗 ── */
.zoom {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3vh 3vw;
}
.zoom-backdrop { position: absolute; inset: 0; background: rgba(12, 13, 15, .68); backdrop-filter: blur(2px); }
.zoom-panel { position: relative; display: flex; flex-direction: column; width: min(1200px, 94vw); max-height: 94vh; }
.zoom-panel.image { width: auto; min-width: min(560px, 94vw); max-width: 94vw; }
.zoom-head { display: flex; align-items: flex-start; gap: 10px; min-height: 48px; padding: 0 2px 10px; }
.zoom-head .meta-info { color: rgba(255, 255, 255, .72); }
.zoom-head .when { color: #fff; font-variant-numeric: tabular-nums; white-space: nowrap; }
.zoom-head .tag { cursor: default; }
.zoom-body { min-height: 0; display: flex; justify-content: center; }
.zoom-text {
  width: 100%;
  max-height: calc(94vh - 56px);
  overflow: auto;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 64px -24px rgba(0, 0, 0, .6);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  scrollbar-width: thin;
}
.zoom-img {
  display: block;
  max-width: 100%;
  max-height: calc(94vh - 56px);
  height: auto;
  border-radius: 8px;
  background: var(--surface-2);
  box-shadow: 0 24px 64px -24px rgba(0, 0, 0, .7);
}

/* ── 拖拽 / 提示 ── */
.drop-hint {
  position: fixed;
  inset: 10px;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  color: var(--accent-soft-ink);
  font-size: 18px;
  pointer-events: none;
}
body.dropping .drop-hint { display: flex; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 40;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 9px 16px;
  border-radius: 10px;
  background: var(--toast);
  color: var(--toast-ink);
  font-size: 14px;
  box-shadow: var(--shadow);
  transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast .btn { color: var(--toast-ink); background: color-mix(in srgb, var(--toast-ink) 16%, transparent); padding: 3px 10px; }

@media (max-width: 600px) {
  .page { padding: 12px 12px 56px; }
  .bar-inner { padding: 8px 12px; }
  .dev-label { display: none; }
  .dev-name { max-width: 150px; }
  .dev-input { width: 150px; }
  .scroll, .code-edit, .compose-box { padding: 9px 12px; }
  .tag-new { max-width: none; }
}
