/* ==========================================================================
   Python 比赛练习 · 设计系统
   设计依据：ui-ux-pro-max「Minimalism & Swiss Style」+ Quiz blue / 金色排行榜
   浅色为主、可切深色；所有颜色走 CSS 变量，改主题只需改这两段
   ========================================================================== */

/* Outfit 可变字体（自托管，覆盖 400–700，离线可用；中文自动回退到系统字体） */
@font-face {
  font-family: "Outfit";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("/assets/fonts/outfit-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212,
    U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Outfit";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("/assets/fonts/outfit-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* 表面与文字 */
  --bg: #eff6ff;
  --bg-soft: #e6eefc;
  --panel: #ffffff;
  --panel-2: #f1f5fd;
  --ink: #0f172a;
  --ink-2: #334155;
  --sub: #475569;          /* 正文次级文字，对白底 7.0:1 */
  --line: #e4ecfc;
  --line-2: #edf2fe;

  /* 品牌：Quiz blue + 紫罗兰副色 + 金色（排行榜/名次） */
  --brand: #2563eb;
  --brand-2: #7c3aed;
  --brand-soft: #e8efff;
  --accent: #f59e0b;
  --accent-soft: #fef3d7;
  --on-accent: #0f172a;

  /* 语义色 */
  --ok: #166534;   /* 绿字压在浅绿底上也够 4.5:1 */
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf1d9;
  --err: #dc2626;
  --err-soft: #fdeceb;

  /* 代码区（始终深色，与主题无关） */
  --code-bg: #0f172a;
  --code-ink: #cbd5e1;

  /* 阴影：Swiss 风格用锐利低扩散阴影，不用大范围柔光 */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 2px 8px rgba(15, 23, 42, .08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .16);

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;

  /* 间距节奏 4/8 */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  --ring: #2563eb;
  --mono: "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --bg-soft: #121d33;
  --panel: #111a2e;
  --panel-2: #16213a;
  --ink: #e8eef9;
  --ink-2: #c3cfe4;
  --sub: #9aabc4;          /* 对 #111a2e 约 8.4:1 */
  --line: #26324d;
  --line-2: #1d2843;
  --brand: #60a5fa;
  --brand-2: #a78bfa;
  --brand-soft: #1b2a4a;
  --accent: #fbbf24;
  --accent-soft: #33280d;
  --on-accent: #0f172a;
  --ok: #4ade80;
  --ok-soft: #10281c;
  --warn: #fbbf24;
  --warn-soft: #2a2210;
  --err: #f87171;
  --err-soft: #2a1416;
  --ring: #93c5fd;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow: 0 2px 10px rgba(0, 0, 0, .5);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, .6);
}

/* 深色下品牌标签用亮蓝，保证对比度 */
[data-theme="dark"] .pill.brand { color: var(--brand); }


* { box-sizing: border-box; margin: 0; padding: 0; }

/* ---------------------------- 无障碍与动效基线 ---------------------------- */
/* 键盘焦点必须在所有可交互元素上可见（High 优先级规范） */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: 6px;
}
/* 鼠标点击不显示焦点环，避免视觉噪音 */
:where(a, button, [tabindex]):focus:not(:focus-visible) { outline: none; }

/* 尊重系统的「减少动态效果」设置 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* 线性图标（替代 emoji）：统一 1.8 描边、currentColor */
.ico {
  width: 16px; height: 16px; flex: none; display: inline-block; vertical-align: -3px;
  stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.ico-sm { width: 14px; height: 14px; vertical-align: -2px; }
.ico-lg { width: 20px; height: 20px; vertical-align: -4px; }
/* 纯图标按钮：保证 36px 以上点击区域 */
.btn.icon-only { padding: 7px 9px; }
.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;
}

html, body { height: 100%; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background .25s, color .25s;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }

/* ------------------------------- 基础组件 ------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--panel); color: var(--ink-2); font-weight: 600; font-size: 14px;
  transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; border-color: transparent; box-shadow: var(--shadow-sm);
}
.btn-primary:hover { color: #fff; filter: brightness(1.06); }
/* 深色主题下主按钮为浅色渐变，必须用深色文字才够对比度（白字只有 2.5:1） */
[data-theme="dark"] .btn-primary { color: var(--on-accent); }
[data-theme="dark"] .btn-primary:hover { color: var(--on-accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--sub); }
.btn-ghost:hover { background: var(--bg-soft); color: var(--ink); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; border-radius: 7px; }
.btn-danger { color: var(--err); border-color: var(--line); }
.btn-danger:hover { border-color: var(--err); background: var(--err-soft); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--bg-soft); color: var(--ink-2);
}
.pill.brand { background: var(--brand-soft); color: #1d4ed8; }
/* 题库名可能较长，超出用省略号而不是硬切 */
#bankPill, #chapterPill {
  flex: none; max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.err { background: var(--err-soft); color: var(--err); }

.tag { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.tag.easy { color: var(--ok); background: var(--ok-soft); }
.tag.mid { color: var(--warn); background: var(--warn-soft); }
.tag.hard { color: var(--err); background: var(--err-soft); }
.tag.chapter { color: var(--brand); background: var(--brand-soft); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input {
  width: 100%; padding: 10px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--panel); transition: .15s;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-sm);
}

.muted { color: var(--sub); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 提示条固定在右下角、由下往上堆叠：不遮挡工具栏按钮 */
.toast-wrap { position: fixed; bottom: 54px; right: 18px; z-index: 70; display: flex; flex-direction: column-reverse; gap: 8px; align-items: flex-end; }
.toast {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--brand);
  padding: 10px 14px; border-radius: var(--r-sm); box-shadow: var(--shadow);
  font-size: 13.5px; max-width: 320px; animation: slideIn .2s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
@keyframes slideIn { from { transform: translateX(16px); opacity: 0; } }

/* ================================ 登录页 ================================ */
.auth-wrap {
  min-height: 100%; display: grid; grid-template-columns: 1.05fr .95fr;
}
.auth-hero {
  position: relative; overflow: hidden; padding: 52px 56px;
  background: linear-gradient(150deg, #1e1b4b 0%, #312e81 45%, #0c4a6e 100%);
  color: #fff; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-hero::after {
  content: ""; position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 82% 18%, rgba(14, 165, 233, .35), transparent 42%),
    radial-gradient(circle at 12% 82%, rgba(129, 140, 248, .35), transparent 45%);
}
.auth-hero > * { position: relative; z-index: 1; }
.auth-hero h1 { font-size: 34px; line-height: 1.25; font-weight: 800; letter-spacing: -.5px; }
.auth-hero h1 em { font-style: normal; background: linear-gradient(90deg, #67e8f9, #a5b4fc); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-hero p.lead { margin-top: 14px; color: rgba(255, 255, 255, .78); font-size: 15px; max-width: 460px; }
.hero-points { margin-top: 30px; display: grid; gap: 12px; }
.hero-points div { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: rgba(255, 255, 255, .85); }
.hero-points i {
  flex: none; width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center;
  background: rgba(255, 255, 255, .14); font-size: 12px; font-style: normal;
}
.hero-stat { display: flex; gap: 26px; margin-top: 34px; }
.hero-stat b { display: block; font-size: 26px; font-weight: 800; }
.hero-stat span { font-size: 12px; color: rgba(255, 255, 255, .6); }

.auth-panel { display: grid; place-items: center; padding: 40px 24px; }
.auth-box { width: min(400px, 100%); }
.auth-box h2 { font-size: 24px; font-weight: 800; margin-bottom: 6px; }
.auth-box .sub { color: var(--sub); font-size: 14px; margin-bottom: 24px; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--bg-soft); border-radius: 10px; margin-bottom: 22px; }
.tabs button {
  flex: 1; padding: 8px; border: 0; border-radius: 7px; background: transparent;
  color: var(--sub); font-weight: 700; font-size: 14px; transition: .15s;
}
.tabs button.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow-sm); }
.form-msg { font-size: 13px; padding: 9px 12px; border-radius: var(--r-sm); margin-bottom: 12px; }
.form-msg.err { background: var(--err-soft); color: var(--err); }
.form-msg.ok { background: var(--ok-soft); color: var(--ok); }
.auth-foot { margin-top: 18px; font-size: 12.5px; color: var(--sub); text-align: center; line-height: 1.8; }

@media (max-width: 880px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-hero { padding: 34px 26px; }
  .auth-hero h1 { font-size: 26px; }
  .hero-points, .hero-stat { display: none; }
}

/* ================================ 答题页 ================================ */
.app { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  flex: none; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 15.5px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
  font-size: 14px; font-weight: 800; letter-spacing: -.5px;
}
.spacer { flex: 1; }
.timer {
  display: flex; align-items: center; gap: 8px; padding: 5px 13px; border-radius: 999px;
  background: var(--bg-soft); font-weight: 700; font-size: 13.5px; font-variant-numeric: tabular-nums;
}
.timer.urgent { background: var(--err-soft); color: var(--err); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .62; } }
.score-chip {
  display: flex; align-items: center; gap: 8px; padding: 5px 13px; border-radius: 999px;
  background: linear-gradient(135deg, rgba(79, 70, 229, .12), rgba(14, 165, 233, .12));
  border: 1px solid rgba(79, 70, 229, .25); font-size: 13px; color: var(--sub);
}
.score-chip b { font-size: 16px; font-weight: 800; color: var(--brand); font-variant-numeric: tabular-nums; }
.progress-wrap { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--sub); }
.progress-bar { width: 110px; height: 6px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; }
.progress-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--ok)); transition: width .4s; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); font-weight: 800; font-size: 13px;
}

.hide-sm { display: inline; }
.top-actions { display: flex; align-items: center; gap: 8px; }

/* 中等宽度：把顶栏压成整齐两行（品牌/题库/计时/得分/进度 一行，操作按钮 一行） */
@media (max-width: 1100px) {
  .topbar { padding: 8px 12px; gap: 8px; row-gap: 8px; }
  .topbar .spacer { display: none; }
  .topbar .brand { margin-right: auto; }
  .topbar #chapterPill { display: none; }      /* 章节在题面里已显示，顶栏不重复占位 */
  .topbar #bankPill { max-width: 170px; }
  .topbar .timer { order: 3; }
  .topbar .score-chip { order: 4; }
  .topbar .progress-wrap { order: 6; }
  .topbar .progress-bar { width: 84px; }
  /* 操作按钮整体占第二行并右对齐，避免只剩一两个按钮孤零零挂在末行 */
  .topbar .top-actions { order: 7; flex: 1 1 100%; justify-content: flex-end; }
}

@media (min-width: 761px) and (max-width: 1100px) {
  .topbar .top-actions { margin-top: 2px; }
}

@media (max-width: 760px) {
  .topbar { padding: 7px 10px; gap: 6px; row-gap: 6px; }
  .topbar .brand { font-size: 14px; gap: 7px; }
  .topbar .brand .logo { width: 26px; height: 26px; font-size: 12px; }
  .topbar .pill { font-size: 11px; padding: 2px 8px; }
  .topbar #bankPill { max-width: 128px; }
  .topbar .timer, .topbar .score-chip { font-size: 12px; padding: 3px 9px; }
  .topbar .score-chip b { font-size: 14px; }
  .topbar .progress-wrap { font-size: 11.5px; }
  .topbar .progress-bar { display: none; }
  .topbar .btn-sm { padding: 4px 8px; font-size: 12px; }
  .topbar .avatar { display: none; }      /* 小屏省掉头像，让操作按钮留在同一行 */
  /* 触控目标：小屏上主要操作 ≥44px（ui-ux-pro-max 清单要求） */
  .btn-sm { min-height: 36px; }
  #runBtn, #finishBtn { min-height: 44px; padding: 10px 16px; font-size: 14px; }
  .qnav-btn { height: 40px; font-size: 13.5px; }
  .qnav-grid { grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); }
  .topbar .top-actions { flex: 0 1 auto; justify-content: flex-start; gap: 6px; }
  .hide-sm { display: none; }
  .edhead { padding: 6px 10px; gap: 6px; }
  .edhead .fname { display: none; }
}

.workspace { flex: 1; display: grid; grid-template-columns: 430px 1fr; min-height: 0; }
@media (max-width: 1020px) { .workspace { grid-template-columns: 1fr; grid-template-rows: 46% 54%; } }

.left-col { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--line); }

/* 题目导航 */
.qnav { flex: none; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.qnav-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 12px; color: var(--sub); }
.qnav-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 6px; max-height: 118px; overflow-y: auto; }
.qnav-btn {
  position: relative; height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--ink-2); font-weight: 700; font-size: 12.5px; transition: .15s;
}
.qnav-btn:hover { border-color: var(--brand); color: var(--brand); }
.qnav-btn.active { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-color: transparent; }
.qnav-btn.done { border-color: rgba(22, 163, 74, .5); color: var(--ok); background: var(--ok-soft); }
.qnav-btn.done.active { color: #fff; background: linear-gradient(135deg, var(--ok), #22c55e); }
.qnav-btn .dot { position: absolute; top: -3px; right: -3px; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }

/* 题面 */
.qdetail { flex: 1; overflow-y: auto; padding: 18px 20px 28px; }
.qmeta { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.qtitle { font-size: 21px; font-weight: 800; letter-spacing: -.3px; margin-bottom: 8px; }
.qintro { font-size: 13.5px; color: var(--sub); margin-bottom: 16px; }
.sec { margin-bottom: 18px; }
.sec > h3 {
  font-size: 11.5px; font-weight: 800; letter-spacing: .8px; text-transform: uppercase;
  color: var(--brand); margin-bottom: 8px; display: flex; align-items: center; gap: 6px;
}
.sec > h3::before { content: ""; width: 3px; height: 12px; border-radius: 2px; background: var(--brand); }

.reqs { list-style: none; display: flex; flex-direction: column; gap: 8px; counter-reset: r; }
.reqs li {
  display: flex; gap: 9px; padding: 9px 11px; border-radius: var(--r-sm);
  background: var(--panel-2); border: 1px solid var(--line-2); font-size: 13.5px; line-height: 1.65;
}
.reqs li::before {
  counter-increment: r; content: counter(r); flex: none; width: 19px; height: 19px; margin-top: 1px;
  border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  font-size: 11.5px; font-weight: 800; display: grid; place-items: center;
}
code.inline {
  font-family: var(--mono); font-size: .9em; padding: 1px 5px; border-radius: 5px;
  background: var(--bg-soft); color: var(--brand); border: 1px solid var(--line-2);
}
.box {
  padding: 10px 12px; border-radius: var(--r-sm); font-size: 13px;
  background: var(--panel-2); border: 1px solid var(--line-2);
  white-space: pre-wrap; word-break: break-word; font-family: var(--mono); color: var(--ink-2);
}
.box.ok { background: var(--ok-soft); border-color: rgba(22, 163, 74, .25); }
.box.brand { background: var(--brand-soft); border-color: rgba(79, 70, 229, .22); }

/* 输入输出示例：每组用例一张卡片，全部同时展开（不做标签切换） */
.samples { display: flex; flex-direction: column; gap: 10px; }
.sample-case {
  border: 1px solid var(--line); border-radius: var(--r-sm);
  overflow: hidden; background: var(--panel);
}
.sample-case-head {
  padding: 5px 11px; background: var(--panel-2); border-bottom: 1px solid var(--line);
  font-size: 11px; font-weight: 800; letter-spacing: .4px; color: var(--ink-2);
}
.sample-io { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); }
/* 多行或较长内容：改成上下排列，避免挤在半栏里换行成一坨 */
.sample-io.stack { grid-template-columns: 1fr; }
.sample-cell { background: var(--panel); padding: 8px 11px; min-width: 0; }
.sample-cell h4 { font-size: 10px; letter-spacing: .6px; text-transform: uppercase; color: var(--sub); margin-bottom: 4px; }
.sample-cell pre { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto; color: var(--ink-2); }
.sec-note { margin-left: auto; font-size: 10.5px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--sub); }

details.hint { border: 1px dashed var(--line); border-radius: var(--r-sm); padding: 0 12px; background: var(--panel-2); }
details.hint summary { cursor: pointer; padding: 8px 0; font-size: 12.5px; font-weight: 700; color: var(--warn); list-style: none; }
details.hint summary::-webkit-details-marker { display: none; }
details.hint p { padding-bottom: 10px; font-size: 13px; color: var(--sub); }

/* 右侧编辑器 */
.right-col { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.edhead {
  flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.edhead .fname { font-family: var(--mono); font-size: 12.5px; color: var(--sub); }

/* 右侧编辑器：CodeMirror 接管（行号 / 高亮 / 括号匹配都由它渲染） */
.editor-wrap { flex: 1; display: flex; min-height: 0; background: var(--code-bg); position: relative; overflow: hidden; }

.CodeMirror {
  flex: 1;
  height: 100%;
  background: var(--code-bg);
  color: var(--code-ink);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
}
.CodeMirror-scroll { padding-bottom: 8px; }
.CodeMirror-gutters {
  background: #0b1220;
  border-right: 1px solid rgba(148, 163, 184, .14);
}
.CodeMirror-linenumber { color: #475569; padding: 0 10px 0 6px; font-size: 12.5px; }
.CodeMirror-cursor { border-left: 2px solid #a5b4fc; }
/* 编辑器聚焦时给出整块可见指示（隐藏 textarea 的 focus ring 看不到） */
.CodeMirror-focused { box-shadow: inset 0 0 0 2px var(--ring); }
.CodeMirror-selected { background: rgba(99, 102, 241, .28) !important; }
.CodeMirror-focused .CodeMirror-selected { background: rgba(99, 102, 241, .34) !important; }
.CodeMirror-activeline-background { background: rgba(99, 102, 241, .08); }
.CodeMirror-matchingbracket {
  color: #fff !important;
  background: rgba(99, 102, 241, .45);
  border-radius: 3px;
  outline: 1px solid rgba(165, 180, 252, .5);
}
.CodeMirror-nonmatchingbracket { color: #f87171 !important; }
.CodeMirror-line { padding-left: 6px; }

/* 语法着色 —— 与右侧面板的深色底保持同一套色系 */
.cm-s-arena .cm-keyword { color: #c084fc; }
.cm-s-arena .cm-def { color: #60a5fa; }
.cm-s-arena .cm-builtin { color: #67e8f9; }
.cm-s-arena .cm-string { color: #7dd3a0; }
.cm-s-arena .cm-string-2 { color: #86efac; }
.cm-s-arena .cm-number { color: #fdba74; }
.cm-s-arena .cm-atom { color: #fdba74; }
.cm-s-arena .cm-comment { color: #64748b; font-style: italic; }
.cm-s-arena .cm-operator { color: #7dd3fc; }
.cm-s-arena .cm-variable { color: #cbd5e1; }
.cm-s-arena .cm-variable-2 { color: #fbbf24; }
.cm-s-arena .cm-property { color: #e2e8f0; }
.cm-s-arena .cm-meta { color: #94a3b8; }
.cm-s-arena .cm-qualifier { color: #fbbf24; }
.cm-s-arena .cm-bracket { color: #94a3b8; }
.cm-s-arena .cm-error { color: #f87171; border-bottom: 1px dashed #f87171; }

/* 搜索 / 替换对话框（Ctrl+F）适配深色 */
.CodeMirror-dialog {
  background: #111a2e;
  color: var(--code-ink);
  border-bottom: 1px solid rgba(148, 163, 184, .2);
  padding: 6px 10px;
  font-family: var(--sans);
  font-size: 13px;
}
.CodeMirror-dialog input {
  background: #0b1220;
  border: 1px solid rgba(148, 163, 184, .28);
  border-radius: 6px;
  color: var(--code-ink);
  padding: 3px 8px;
  font-family: var(--mono);
  outline: none;
}
.CodeMirror-dialog input:focus { border-color: #6366f1; }
.CodeMirror-dialog button {
  background: #1e293b;
  border: 1px solid rgba(148, 163, 184, .24);
  color: #cbd5e1;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}
.CodeMirror-search-hint { color: #64748b; }

/* 深色面板里的滚动条，避免亮白拖动块刺眼 */
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar { background: transparent; }
.CodeMirror-vscrollbar::-webkit-scrollbar, .CodeMirror-hscrollbar::-webkit-scrollbar { width: 10px; height: 10px; }
.CodeMirror-vscrollbar::-webkit-scrollbar-track, .CodeMirror-hscrollbar::-webkit-scrollbar-track { background: transparent; }
.CodeMirror-vscrollbar::-webkit-scrollbar-thumb, .CodeMirror-hscrollbar::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, .28); border-radius: 99px; border: 2px solid transparent; background-clip: content-box;
}
.CodeMirror-vscrollbar::-webkit-scrollbar-thumb:hover, .CodeMirror-hscrollbar::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, .45); background-clip: content-box;
}

/* 快捷键说明浮层 */
.kbd-wrap { position: relative; }
.kbd-pop {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 40; width: 268px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-lg); padding: 10px 12px; display: none;
}
.kbd-pop.open { display: block; }
.kbd-pop h5 { font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: var(--sub); margin-bottom: 8px; }
.kbd-pop div.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: 12.5px; }
.kbd-pop div.row span { color: var(--sub); }
.kbd-pop kbd {
  font-family: var(--mono); font-size: 11px; padding: 1px 6px; border-radius: 5px;
  background: var(--bg-soft); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap;
}

.results { flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border-top: 1px solid var(--line); max-height: 34%; min-height: 132px; }
@media (max-width: 720px) { .results { grid-template-columns: 1fr; max-height: 40%; } }
.rbox { background: var(--panel); padding: 10px 14px; overflow: auto; min-height: 0; }
.rbox h4 { font-size: 10.5px; letter-spacing: .7px; text-transform: uppercase; color: var(--sub); margin-bottom: 6px; }
.rbox pre { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word; color: var(--ink-2); }
.verdict { font-size: 13px; line-height: 1.7; }
.verdict .v-title { font-weight: 800; display: flex; align-items: center; gap: 7px; margin-bottom: 4px; }
.verdict.pass .v-title { color: var(--ok); }
.verdict.fail .v-title { color: var(--err); }
.verdict .v-detail { color: var(--sub); font-size: 12.5px; }

.envbar {
  flex: none; display: flex; align-items: center; gap: 8px; padding: 5px 14px;
  font-size: 12px; color: var(--sub); background: var(--panel); border-top: 1px solid var(--line);
}
.envbar .led { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.envbar.ok .led { background: var(--ok); }
.envbar.err .led { background: var(--err); }

/* 排行榜抽屉 */
.drawer {
  position: fixed; top: 0; right: 0; width: min(420px, 92vw); height: 100%;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg);
  transform: translateX(102%); transition: transform .26s ease; z-index: 60; display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1; overflow-y: auto; padding: 12px 18px 24px; }
.mask { position: fixed; inset: 0; background: rgba(16, 24, 40, .38); opacity: 0; pointer-events: none; transition: .25s; z-index: 50; }
.mask.open { opacity: 1; pointer-events: auto; }

.rank-row { display: flex; align-items: center; gap: 11px; padding: 9px 0; border-bottom: 1px solid var(--line-2); font-size: 13.5px; }
.rank-row .no { width: 22px; text-align: center; font-weight: 800; color: var(--sub); font-variant-numeric: tabular-nums; }
.rank-row.top1 .no { color: #d97706; }
.rank-row.top2 .no { color: #94a3b8; }
.rank-row.top3 .no { color: #b45309; }
.rank-row.me { background: var(--brand-soft); border-radius: 8px; padding-left: 8px; }
.rank-row .nm { flex: 1; font-weight: 600; }
.rank-row .sc { font-weight: 800; color: var(--brand); font-variant-numeric: tabular-nums; }

/* ================================ 后台页 ================================ */
.admin { min-height: 100vh; display: flex; flex-direction: column; }
.admin-top {
  display: flex; align-items: center; gap: 14px; padding: 12px 24px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.admin-body { flex: 1; padding: 20px 24px 40px; max-width: 1480px; width: 100%; margin: 0 auto; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { padding: 14px 16px; border-radius: var(--r); background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.kpi .k { font-size: 11.5px; color: var(--sub); font-weight: 600; letter-spacing: .3px; }
.kpi .v { font-size: 26px; font-weight: 800; letter-spacing: -.5px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .u { font-size: 12px; color: var(--sub); font-weight: 600; margin-left: 3px; }
.kpi.accent .v { background: linear-gradient(90deg, var(--brand), var(--brand-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); margin-bottom: 16px; overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h3 { font-size: 14.5px; font-weight: 800; }
.panel-body { padding: 14px 16px; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; padding: 9px 12px; font-size: 11.5px; letter-spacing: .4px; text-transform: uppercase;
  color: var(--sub); background: var(--panel-2); border-bottom: 1px solid var(--line); font-weight: 700; white-space: nowrap;
}
table.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.tbl td.nowrap, table.tbl th.nowrap { white-space: nowrap; }
table.tbl tbody tr:hover { background: var(--panel-2); }
table.tbl tr.clickable { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.bar-cell { display: flex; align-items: center; gap: 8px; }
.bar-cell .track { flex: 1; height: 6px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; min-width: 46px; }
.bar-cell .track i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
.bar-cell span { font-size: 12px; color: var(--sub); font-variant-numeric: tabular-nums; min-width: 38px; text-align: right; }

.dist { display: flex; align-items: flex-end; gap: 14px; height: 118px; padding: 6px 4px 0; }
.dist .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.dist .bar { width: 100%; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, var(--brand), var(--brand-2)); min-height: 3px; transition: height .4s; }
.dist .lab { font-size: 11px; color: var(--sub); }
.dist .cnt { font-size: 11.5px; font-weight: 700; color: var(--ink-2); }

.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px; background: rgba(16, 24, 40, .45); }
.modal-box { background: var(--panel); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); width: min(880px, 100%); max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px 18px; overflow: auto; }
.code-block {
  background: var(--code-bg); color: var(--code-ink); border-radius: var(--r-sm); padding: 11px 13px;
  font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto;
}
.empty { padding: 26px; text-align: center; color: var(--sub); font-size: 13.5px; }

/* 题库卡片（后台切换题库用） */
.bank-card {
  display: flex; align-items: center; gap: 14px; padding: 13px 15px;
  border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 10px;
  background: var(--panel-2); transition: .15s;
}
.bank-card.active { border-color: var(--brand); background: var(--brand-soft); }
.bank-card .info { flex: 1; min-width: 0; }
.bank-card h4 { font-size: 14.5px; font-weight: 800; margin-bottom: 3px; display: flex; align-items: center; gap: 8px; }
.bank-card .desc { font-size: 12.5px; color: var(--sub); line-height: 1.6; }
.bank-card .meta { font-size: 12px; color: var(--sub); margin-top: 5px; display: flex; gap: 12px; flex-wrap: wrap; }

@media (max-width: 720px) {
  .admin-body { padding: 14px; }
  .kpi .v { font-size: 21px; }
}
