/* ==========================================================================
   SQL 闯关训练场 · 样式
   调性：数据库客户端 / 终端。等宽字体只用于代码与数据。
   双主题：深色（默认）/ 浅色，由 <html data-theme="…"> 切换。
   ========================================================================== */

/* ---------------------------------------------------------- 深色（默认） */
:root,
[data-theme='dark'] {
  color-scheme: dark;

  /* 表面 */
  --bg:            #0f1115;
  --surface:       #16191f;
  --surface-2:     #1c2028;
  --surface-3:     #232833;
  --border:        #262b34;
  --border-strong: #343b47;

  /* 文字 */
  --text:    #e6e9ef;
  --text-2:  #a8b0be;
  --muted:   #7d8798;   /* 在 --surface 上对比度 4.9:1，满足正文 4.5:1 */

  /* 强调与语义 */
  --accent:       #f0b429;
  --accent-soft:  rgba(240, 180, 41, 0.12);
  --accent-line:  rgba(240, 180, 41, 0.35);
  --accent-ink:   #1a1405;   /* 落在强调色上的文字 */
  --accent-hover: #f7c445;
  --ok:          #34d399;
  --ok-soft:     rgba(52, 211, 153, 0.12);
  --ok-text:     #9ff0d0;
  --ok-title:    #c9fbe5;
  --err:         #f87171;
  --err-soft:    rgba(248, 113, 113, 0.12);
  --err-text:    #ffc0c0;
  --err-title:   #ffd9d9;
  --info:        #60a5fa;

  /* 语法高亮（编辑器内） */
  --syn-kw:  #f0b429;   /* 关键字 */
  --syn-fn:  #6cb6ff;   /* 内置函数 */
  --syn-str: #5fd39a;   /* 字符串 */
  --syn-num: #ff9e64;   /* 数字 */
  --syn-com: #767f8e;   /* 注释 */
  --syn-tbl: #4ec9b0;   /* 表名 */

  --scroll-thumb: #454d5c;
  --row-line:     rgba(38, 43, 52, 0.55);
  --shadow-pop:   0 14px 40px rgba(0, 0, 0, 0.55);
  --shadow-modal: 0 24px 70px rgba(0, 0, 0, 0.6);
  --backdrop:     rgba(6, 8, 11, 0.74);
  --code-bg:      #0f1115;
  --toast-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

/* ---------------------------------------------------------------- 浅色 */
[data-theme='light'] {
  color-scheme: light;

  --bg:            #f7f8fa;
  --surface:       #ffffff;
  --surface-2:     #f1f3f6;
  --surface-3:     #e5e8ee;
  --border:        #e2e5ea;
  --border-strong: #c8cfd9;

  --text:    #14181f;
  --text-2:  #454e5c;
  --muted:   #6a7380;

  /* 琥珀在白底上要压暗才够对比度 */
  --accent:       #9a6200;
  --accent-soft:  rgba(154, 98, 0, 0.1);
  --accent-line:  rgba(154, 98, 0, 0.3);
  --accent-ink:   #ffffff;
  --accent-hover: #7f5000;
  --ok:          #0f8f5f;
  --ok-soft:     rgba(15, 143, 95, 0.1);
  --ok-text:     #0a6b47;
  --ok-title:    #075237;
  --err:         #b3261e;
  --err-soft:    rgba(179, 38, 30, 0.08);
  --err-text:    #8c1d17;
  --err-title:   #6f1712;
  --info:        #1f6feb;

  /* 语法高亮：白底上压暗，保证 4.5:1 以上 */
  --syn-kw:  #9a6200;
  --syn-fn:  #1f6feb;
  --syn-str: #0a7f4f;
  --syn-num: #b25000;
  --syn-com: #6a7380;
  --syn-tbl: #0f7b8a;

  --scroll-thumb: #c2c8d2;
  --row-line:     rgba(226, 229, 234, 0.9);
  --shadow-pop:   0 10px 30px rgba(20, 24, 31, 0.14);
  --shadow-modal: 0 20px 60px rgba(20, 24, 31, 0.2);
  --backdrop:     rgba(20, 24, 31, 0.42);
  --code-bg:      #f7f8fa;
  --toast-shadow: 0 6px 20px rgba(20, 24, 31, 0.16);
}

/* ------------------------------------------------------ 与主题无关的令牌 */
:root {
  /* 字体 */
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas,
          "Liberation Mono", monospace;

  /* 字号阶梯（5 级） */
  --fs-xs:   12px;
  --fs-sm:   14px;
  --fs-base: 15px;
  --fs-lg:   20px;
  --fs-xl:   27px;
  --fs-code: 15px;   /* 编辑器 / 数据表等等宽内容 */

  /* 间距（8pt 基准） */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px;

  --radius:    8px;
  --radius-sm: 5px;
  --header-h:  56px;
  --sbw:       10px;   /* 滚动条宽度：编辑器的两层要按它对齐 */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; overflow: hidden; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }

::selection { background: var(--accent-soft); color: var(--text); }

/* 滚动条 */
::-webkit-scrollbar { width: var(--sbw); height: var(--sbw); }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 5px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb); }

/* ==========================================================================
   顶栏
   ========================================================================== */
.topbar {
  height: var(--header-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: 0 var(--s4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: var(--s3); flex: 0 0 auto; }

.brand-mark {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-title { font-size: var(--fs-base); font-weight: 600; letter-spacing: -0.01em; }
.brand-sub { font-size: var(--fs-xs); color: var(--muted); }

.topbar-spacer { flex: 1 1 auto; }

/* 总体进度 */
.progress-wrap { display: flex; align-items: center; gap: var(--s3); flex: 0 0 auto; }
.progress-meta { text-align: right; line-height: 1.25; }
.progress-num { font-size: var(--fs-base); font-weight: 600; font-variant-numeric: tabular-nums; }
.progress-num .dim { color: var(--muted); font-weight: 400; }
.progress-label { font-size: var(--fs-xs); color: var(--muted); }

.progress-bar {
  width: 160px; height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ==========================================================================
   主体三栏
   ========================================================================== */
.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr) 372px;
  min-height: 0;
}

.panel { min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.panel + .panel { border-left: 1px solid var(--border); }

.panel-head {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--s2);
  height: 40px;
  padding: 0 var(--s4);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel-head .spacer { flex: 1; }

/* ==========================================================================
   左：关卡列表
   ========================================================================== */
.levels-panel { background: var(--surface); }
.levels-scroll { overflow-y: auto; padding: var(--s2) 0 var(--s5); }

.chapter { margin-top: var(--s2); }
.chapter:first-child { margin-top: 0; }

.chapter-head {
  display: flex; align-items: baseline; gap: var(--s2);
  padding: var(--s3) var(--s4) var(--s2);
  position: sticky; top: 0;
  background: var(--surface);
  z-index: 2;
}
.chapter-name { font-size: var(--fs-sm); font-weight: 600; }
.chapter-count {
  margin-left: auto;
  font-size: var(--fs-xs);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.chapter-count.done { color: var(--ok); }
.chapter-desc {
  padding: 0 var(--s4) var(--s2);
  font-size: var(--fs-xs);
  color: var(--muted);
  line-height: 1.45;
}

.level-item {
  display: flex; align-items: center; gap: var(--s3);
  width: calc(100% - var(--s3) * 2);
  margin: 1px var(--s3);
  padding: var(--s2) var(--s3);
  border-radius: var(--radius-sm);
  text-align: left;
  color: var(--text-2);
  transition: background 0.12s, color 0.12s;
}
.level-item:hover { background: var(--surface-2); color: var(--text); }
.level-item.active { background: var(--surface-3); color: var(--text); }
.level-item.active .level-name { font-weight: 600; }
.level-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.level-dot {
  flex: 0 0 auto;
  width: 18px; height: 18px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  color: transparent;
}
.level-item.done .level-dot {
  background: var(--ok);
  border-color: var(--ok);
  color: var(--accent-ink);
}
.level-item.active .level-dot { border-color: var(--accent); }

.level-name {
  flex: 1;
  font-size: var(--fs-sm);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.level-item.done .level-name { color: var(--text-2); }

/* ==========================================================================
   中：工作区
   ========================================================================== */
.work-panel { background: var(--bg); }
.work-scroll { flex: 1 1 auto; overflow-y: auto; padding: var(--s5) var(--s6) var(--s6); }
.work-inner { max-width: 760px; margin: 0 auto; }

.level-head { margin-bottom: var(--s5); }
.level-kicker {
  display: flex; align-items: center; gap: var(--s2);
  font-size: var(--fs-xs);
  color: var(--muted);
  margin-bottom: var(--s2);
}
.level-kicker .sep { color: var(--border-strong); }
.level-title {
  font-size: var(--fs-xl);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.25;
  display: flex; align-items: center; gap: var(--s3);
}
.level-done-tag {
  display: none;
  align-items: center; gap: 4px;
  padding: 2px var(--s2);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--ok);
  background: var(--ok-soft);
  border-radius: 100px;
}
.level-head.is-done .level-done-tag { display: inline-flex; }

.brief {
  margin-top: var(--s3);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text-2);
}
.brief strong { color: var(--text); font-weight: 600; }
.brief code {
  font-family: var(--mono);
  font-size: 0.88em;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-3);
  color: var(--accent);
  white-space: nowrap;
}

/* 提示条 */
.hint-box {
  display: none;
  gap: var(--s3);
  margin-top: var(--s4);
  padding: var(--s3) var(--s4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  color: var(--text-2);
  line-height: 1.6;
}
.hint-box.show { display: flex; }
.hint-box svg { flex: 0 0 auto; color: var(--accent); margin-top: 2px; }
.hint-box code {
  font-family: var(--mono);
  font-size: 0.9em;
  color: var(--accent);
}

/* 编辑器 */
.editor-block { margin-top: var(--s5); }

.block-label {
  display: flex; align-items: center; gap: var(--s2);
  margin-bottom: var(--s2);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.block-label .spacer { flex: 1; }
.block-label .hintkey {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--muted);
}

.editor-shell {
  position: relative;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.15s;
}
.editor-shell:focus-within { border-color: var(--accent-line); }
.editor-shell.is-err { border-color: var(--err); }

/* --------------------------------------------------------------------------
   编辑器：textarea 文字透明，真正显示的是底下那层语法高亮 <pre>。
   两层必须共享完全相同的字体 / 行高 / 内边距 / 换行规则，否则会错位，
   所以排版规则只写一处、两层共用。
   -------------------------------------------------------------------------- */
.editor-stack { position: relative; }

#editor,
.hl {
  margin: 0;
  padding: var(--s4);
  font-family: var(--mono);
  font-size: var(--fs-code);
  line-height: 1.7;
  letter-spacing: normal;
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.hl {
  position: absolute;
  inset: 0;
  z-index: 0;
  color: var(--text);
  pointer-events: none;
  overflow: hidden;
  /* textarea 用 scrollbar-gutter 常驻预留滚动条槽位，
     高亮层补上同样的右内边距，两层内容盒等宽、换行位置才会一致 */
  padding-right: calc(var(--s4) + var(--sbw));
}

#editor {
  display: block;
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 120px;
  background: transparent;
  border: none;
  resize: none;
  outline: none;
  /* 文字透明，靠底层高亮显示；光标单独给色 */
  color: transparent;
  caret-color: var(--accent);
  overflow-y: hidden;
  scrollbar-gutter: stable;
}
/* 选中时文字仍保持透明，让底层着色透出来，只显示选区底色 */
#editor::selection { background: var(--accent-soft); color: transparent; }
#editor::placeholder { color: var(--muted); }

/* ------------------------------------------------------------ 语法着色 */
.hl .t-kw  { color: var(--syn-kw); font-weight: 600; }
.hl .t-fn  { color: var(--syn-fn); }
.hl .t-str { color: var(--syn-str); }
.hl .t-num { color: var(--syn-num); }
.hl .t-com { color: var(--syn-com); font-style: italic; }
.hl .t-tbl { color: var(--syn-tbl); }

/* 按钮 */
.actions {
  display: flex; align-items: center; gap: var(--s2);
  margin-top: var(--s3);
  flex-wrap: wrap;
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px;
  padding: 0 var(--s4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); color: var(--text); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }

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

.btn .kbd {
  font-family: var(--mono);
  font-size: 11px;
  opacity: 0.65;
  padding-left: 2px;
}

.actions .spacer { flex: 1; }

/* 结果区 */
.result-block { margin-top: var(--s5); }

.verdict {
  display: none;
  align-items: flex-start; gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  line-height: 1.6;
  margin-bottom: var(--s4);
}
.verdict.show { display: flex; }
.verdict svg { flex: 0 0 auto; margin-top: 2px; }
.verdict.ok  { background: var(--ok-soft);  color: var(--ok-text); border: 1px solid var(--ok-soft); }
.verdict.err { background: var(--err-soft); color: var(--err-text); border: 1px solid var(--err-soft); }
.verdict.info{ background: var(--surface);  color: var(--text-2); border: 1px solid var(--border); }
.verdict .vtitle { font-weight: 600; color: var(--text); display: block; margin-bottom: 2px; }
.verdict.ok .vtitle { color: var(--ok-title); }
.verdict.err .vtitle { color: var(--err-title); }
.verdict code {
  font-family: var(--mono);
  font-size: 0.9em;
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--surface-3);
}

/* 差异表 */
.diff-block {
  display: none;
  margin-bottom: var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.diff-block.show { display: block; }
.diff-head {
  padding: var(--s2) var(--s4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.diff-body { max-height: 260px; overflow: auto; background: var(--surface); }
.diff-row {
  display: flex; align-items: baseline; gap: var(--s2);
  padding: 5px var(--s4);
  font-family: var(--mono);
  font-size: 13px;
  border-bottom: 1px solid var(--row-line);
}
.diff-row:last-child { border-bottom: none; }
.diff-sign { flex: 0 0 auto; width: 12px; font-weight: 700; }
.diff-row.miss { color: var(--err-text); }
.diff-row.miss .diff-sign { color: var(--err); }
.diff-row.extra { color: #ffe0a8; }
.diff-row.extra .diff-sign { color: var(--accent); }
.diff-more { padding: 6px var(--s4); font-size: var(--fs-xs); color: var(--muted); }

/* 数据表 */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: 340px;
  background: var(--surface);
}
table.grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: auto;
  font-family: var(--mono);
  font-size: 13.5px;
}

table.grid thead th {
  position: sticky; top: 0;
  z-index: 1;
  padding: var(--s2) var(--s3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-strong);
  text-align: left;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}

table.grid tbody td {
  padding: 6px var(--s3);
  border-bottom: 1px solid var(--row-line);
  text-align: left;
  color: var(--text-2);
  white-space: nowrap;
}

/* 弹性列：吸收表格剩余宽度，让真实列都保持内容宽度 */
table.grid th.flex { width: 100%; }

/* 数值列：表头和数据必须是同一种对齐方式，
   否则表头会飘在数字上方错位（表头 left、数据 right 时差得最多） */
table.grid th.num,
table.grid td.num { text-align: right; }
table.grid td.num { font-variant-numeric: tabular-nums; }

/* max-width 对 table cell 不生效，截断只能压在内层 span 上 */
table.grid td .cell {
  display: block;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 全数值表时的兜底吸收列（正常情况由 .flex 承担）。
   作用：表格 width:100% 时多余空间会按比例摊给每列、把短列撑得很宽，
   有了吸收列，真实列才保持内容宽度；内容超宽时它缩到 0，表格照常横向滚动。 */
table.grid th.fill { width: 100%; padding: 0; }
table.grid td.fill { padding: 0; border-bottom: 1px solid var(--row-line); }

table.grid tbody tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover td { background: var(--surface-2); color: var(--text); }
table.grid td.null { color: var(--muted); font-style: italic; }

.table-meta {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s3);
  font-size: var(--fs-xs);
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.table-meta .spacer { flex: 1; }

.empty-note {
  padding: var(--s5);
  text-align: center;
  color: var(--muted);
  font-size: var(--fs-sm);
}

/* 参考结果（折叠） */
details.ref {
  margin-top: var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
details.ref > summary {
  padding: var(--s3) var(--s4);
  cursor: pointer;
  font-size: var(--fs-sm);
  color: var(--text-2);
  list-style: none;
  display: flex; align-items: center; gap: var(--s2);
  user-select: none;
}
details.ref > summary::-webkit-details-marker { display: none; }
details.ref > summary:hover { color: var(--text); }
details.ref > summary .chev { transition: transform 0.18s; color: var(--muted); }
details.ref[open] > summary .chev { transform: rotate(90deg); }
details.ref > summary .spacer { flex: 1; }
details.ref .ref-body { padding: 0 var(--s4) var(--s4); }

pre.code {
  margin: 0;
  padding: var(--s3) var(--s4);
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--accent);
  overflow-x: auto;
  white-space: pre;
}

/* ==========================================================================
   右：表结构
   ========================================================================== */
.schema-panel { background: var(--surface); }
.schema-scroll { flex: 1 1 auto; overflow-y: auto; padding: var(--s3) var(--s3) var(--s6); }

.tbl { margin-bottom: var(--s2); border-radius: var(--radius-sm); overflow: hidden; }

.tbl-head {
  display: flex; align-items: center; gap: var(--s2);
  width: 100%;
  padding: var(--s2) var(--s3);
  border-radius: var(--radius-sm);
  text-align: left;
  transition: background 0.12s;
}
.tbl-head:hover { background: var(--surface-2); }
.tbl-head .chev { color: var(--muted); transition: transform 0.18s; flex: 0 0 auto; }
.tbl.open .tbl-head .chev { transform: rotate(90deg); }
.tbl-name {
  font-family: var(--mono);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--accent);
}
.tbl-rows {
  margin-left: auto;
  font-size: var(--fs-xs);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* 字段列表 */
.cols-block { padding: 0 var(--s3) var(--s3) 26px; }

.col-row {
  display: flex; align-items: baseline; gap: var(--s2);
  padding: 2px 0;
  font-family: var(--mono);
  font-size: 13px;
}
.col-name { color: var(--text-2); }
.col-type { color: var(--muted); font-size: 11.5px; margin-left: auto; }
.col-flag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0 4px;
  border-radius: 3px;
  background: var(--accent-soft);
  color: var(--accent);
}
.col-flag.fk { background: rgba(96, 165, 250, 0.14); color: var(--info); }

/* 真实数据块 */
.tbl-body { display: none; }
.tbl.open .tbl-body { display: block; }

.data-block {
  margin: 0 var(--s3) var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
}
.data-head {
  display: flex; align-items: center; gap: var(--s2);
  padding: 5px var(--s3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.data-head .spacer { flex: 1; }

.mini-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  transition: background 0.12s, color 0.12s;
}
.mini-btn:hover { background: var(--surface-3); color: var(--text); }
.mini-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.grid-scroll { overflow: auto; max-height: 260px; }

.data-foot {
  padding: 4px var(--s3);
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.empty-note.sm { padding: var(--s4); font-size: var(--fs-xs); }

/* ==========================================================================
   自动补全候选弹层
   ========================================================================== */
.autocomplete {
  position: fixed;
  z-index: 150;
  width: 322px;
  max-height: 268px;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: var(--shadow-pop);
  overflow: hidden;
  animation: ac-in 0.12s cubic-bezier(0.2, 0.9, 0.25, 1);
}
.autocomplete[hidden] { display: none; }

.ac-list {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  overflow-y: auto;
}

.ac-item {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 6px var(--s2);
  border-radius: 5px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.45;
}
.ac-item.active { background: var(--accent-soft); }

.ac-label {
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ac-label b { font-weight: 700; color: var(--text); }
.ac-item.active .ac-label,
.ac-item.active .ac-label b { color: var(--accent); }

.ac-detail {
  flex: 0 0 auto;
  margin-left: auto;
  font-family: var(--sans);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.ac-foot {
  flex: 0 0 auto;
  padding: 5px var(--s3);
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 11px;
  color: var(--muted);
}
.ac-foot b {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--text-2);
  padding: 0 3px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  margin-right: 1px;
}

@keyframes ac-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 紧凑型数据表格（右侧面板用） */
table.grid.compact { font-size: 12px; }
table.grid.compact thead th { padding: 4px var(--s2); font-size: 11.5px; }
table.grid.compact tbody td { padding: 3px var(--s2); }
table.grid.compact td .cell { max-width: 132px; }

/* ==========================================================================
   表数据放大浮层
   ========================================================================== */
.modal { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; }
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute; inset: 0;
  background: var(--backdrop);
  animation: fade-in 0.16s ease;
}

.modal-panel {
  position: relative;
  width: min(1080px, 92vw);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow-modal);
  animation: modal-in 0.2s cubic-bezier(0.2, 0.9, 0.25, 1);
}

.modal-head {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
}
.modal-head .spacer { flex: 1; }
.modal-title {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}
.modal-meta { font-size: var(--fs-xs); color: var(--muted); }

.modal-body { flex: 1 1 auto; overflow: auto; background: var(--bg); }
.modal-body table.grid tbody td { max-width: 340px; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ==========================================================================
   设置面板
   ========================================================================== */
.settings-panel { width: min(460px, 92vw); }

.settings-title { font-size: var(--fs-lg); font-weight: 650; letter-spacing: -0.01em; }

.settings-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--s2) var(--s4) var(--s4);
  background: var(--surface);
}

.setting { padding: var(--s4) 0; }
.setting + .setting { border-top: 1px solid var(--border); }

.setting-label { margin-bottom: var(--s3); }
.setting-name {
  display: block;
  font-size: var(--fs-base);
  font-weight: 600;
  margin-bottom: 2px;
}
.setting-desc {
  display: block;
  font-size: var(--fs-xs);
  color: var(--muted);
  line-height: 1.55;
}

/* 主题选择：两张带预览的卡片 */
.theme-picker { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }

.theme-card {
  padding: var(--s2);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
  text-align: center;
}
.theme-card:hover { background: var(--surface-2); }
.theme-card[aria-checked='true'] {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.theme-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.theme-preview {
  display: block;
  height: 62px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 9px 10px;
  margin-bottom: var(--s2);
  overflow: hidden;
}
.preview-dark  { background: #0f1115; border-color: #343b47; }
.preview-light { background: #f7f8fa; border-color: #c8cfd9; }

.tp-bar { display: block; height: 6px; border-radius: 3px; margin-bottom: 7px; }
.preview-dark  .tp-bar { background: #f0b429; width: 46%; }
.preview-light .tp-bar { background: #9a6200; width: 46%; }

.tp-block { display: block; height: 7px; border-radius: 4px; margin-bottom: 6px; }
.tp-block.short { width: 62%; }
.preview-dark  .tp-block { background: #232833; }
.preview-light .tp-block { background: #e5e8ee; }
.preview-dark  .tp-block.short { background: #2c323d; }
.preview-light .tp-block.short { background: #dde1e8; }

.theme-name { font-size: var(--fs-sm); font-weight: 600; }
.theme-card[aria-checked='true'] .theme-name { color: var(--accent); }

/* 分段控件 */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.seg-btn {
  padding: 6px var(--s4);
  border-radius: 5px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-2);
  transition: background 0.14s, color 0.14s;
  white-space: nowrap;
}
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-checked='true'] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16);
}
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.settings-foot {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.settings-foot .spacer { flex: 1; }
.settings-note { font-size: var(--fs-xs); color: var(--muted); }

@media (max-width: 620px) {
  .settings-body { padding: var(--s1) var(--s3) var(--s3); }
  .seg { width: 100%; }
  .seg-btn { flex: 1; padding: 6px var(--s2); }
}

.schema-tip {
  margin: var(--s4) var(--s2) 0;
  padding: var(--s3);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  color: var(--muted);
  line-height: 1.6;
}
.schema-tip code {
  font-family: var(--mono);
  color: var(--text-2);
}

/* ==========================================================================
   通关弹层
   ========================================================================== */
.toast-layer {
  position: fixed;
  right: var(--s5);
  bottom: var(--s5);
  display: flex; flex-direction: column; gap: var(--s2);
  align-items: flex-end;
  z-index: 100;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s3) var(--s5);
  background: var(--surface-2);
  border: 1px solid var(--accent-line);
  border-radius: 100px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text);
  box-shadow: var(--toast-shadow);
  animation: toast-in 0.3s cubic-bezier(0.2, 0.9, 0.25, 1);
}
.toast svg { color: var(--accent); }
.toast.out { animation: toast-out 0.28s ease forwards; }
.toast.alert { border-color: rgba(248, 113, 113, 0.5); }
.toast.alert svg { color: var(--err); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px) scale(0.97); }
}

/* 全部通关横幅 */
.finish-banner {
  display: none;
  margin-bottom: var(--s5);
  padding: var(--s4) var(--s5);
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  border-radius: var(--radius);
}
.finish-banner.show { display: block; }
.finish-banner h3 { font-size: var(--fs-lg); font-weight: 650; margin-bottom: var(--s1); }
.finish-banner p { font-size: var(--fs-sm); color: var(--text-2); }

/* ==========================================================================
   移动端 / 窄屏
   ========================================================================== */
.mobile-tabs {
  display: none;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.mobile-tabs button {
  flex: 1;
  height: 40px;
  font-size: var(--fs-sm);
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.mobile-tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 240px minmax(0, 1fr) 300px; }
  .work-scroll { padding: var(--s5) var(--s5) var(--s6); }
}

@media (max-width: 980px) {
  .mobile-tabs { display: flex; }
  .layout { grid-template-columns: 1fr; position: relative; }
  .panel { display: none; border-left: none !important; }
  .panel.mobile-active { display: flex; }
  .work-scroll { padding: var(--s5) var(--s4) var(--s7); }
  .progress-bar { display: none; }
}

@media (max-width: 620px) {
  :root { --fs-xl: 20px; }
  .brand-sub { display: none; }
  .progress-meta { display: none; }
  .actions .btn .kbd { display: none; }
  .btn { padding: 0 var(--s3); }
}

/* 打印/无 JS 兜底 */
.noscript {
  padding: var(--s7);
  text-align: center;
  color: var(--text-2);
}
