:root {
    --bg: #f4f6fa;
    --card: #fff;
    --text: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #2563eb;
    --primary-d: #1d4ed8;
    --danger: #dc2626;
    --ok: #16a34a;
    --warn: #b45309;
    --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font: 15px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 8px; }
h2 { font-size: 18px; margin: 16px 0 10px; }
.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 20px; padding-bottom: 20px; }
.front main.wrap { max-width: 760px; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; }

.topbar { background: #1e293b; color: #fff; }
.topbar .wrap { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding-top: 10px; padding-bottom: 10px; }
.topbar .brand { color: #fff; font-weight: 600; }
.topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.topbar nav a, .topbar nav .link { color: #cbd5e1; }
.topbar nav a:hover, .topbar nav .link:hover { color: #fff; text-decoration: none; }
.topbar nav a.active { color: #fff; font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.card.narrow { max-width: 420px; margin: 40px auto; }
.row-between { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
form.inline { display: inline; margin: 0; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input:not([type=hidden]) { flex: 1; min-width: 180px; margin: 0; }

label { display: block; margin-bottom: 14px; font-weight: 500; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: normal; }
input:not([type=checkbox]):not([type=hidden]), select, textarea {
    display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit;
    border: 1px solid #d1d5db; border-radius: 8px; background: #fff;
    font-size: 16px; -webkit-appearance: none; appearance: none;
}
select {
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236b7280' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 12px center;
    padding-right: 34px;
}
label.check input { width: auto; margin: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 14px; padding: 10px 14px 0; }
legend { padding: 0 6px; color: var(--muted); }

.btn {
    display: inline-block; padding: 8px 16px; border: 1px solid #d1d5db; border-radius: 8px;
    background: #fff; color: var(--text); font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.block { display: block; width: 100%; padding: 12px; font-size: 16px; }
button.link { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.alert.ok { background: #f0fdf4; color: #166534; }
.alert.error { background: #fef2f2; color: #991b1b; }
.alert.warn { background: #fffbeb; color: var(--warn); }
.notice { background: #eff6ff; color: #1e40af; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }

.tag { display: inline-block; font-size: 12px; font-weight: normal; padding: 1px 8px; border-radius: 99px; background: #f3f4f6; color: var(--muted); vertical-align: middle; }
.tag.ok { background: #dcfce7; color: #166534; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; margin: 8px 0; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { background: #f9fafb; font-weight: 600; color: #374151; }
table.kv th { width: 130px; background: none; }
table.kv td { white-space: normal; }
table.scores td, table.scores th { text-align: center; }
table.scores td:first-child, table.scores th:first-child { text-align: left; }

.total { display: flex; flex-wrap: wrap; gap: 16px; align-items: stretch; margin: 12px 0 16px; }
.total-score {
    flex: 0 0 auto; min-width: 140px; padding: 16px 20px; border-radius: var(--radius);
    background: linear-gradient(135deg, #2563eb, #4f46e5); color: #fff; display: flex; flex-direction: column; justify-content: center;
}
.total-score .num { font-size: 40px; font-weight: 700; line-height: 1.1; }
.total-score .label { opacity: .85; }
.ranks { flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.rank { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.rank .label { display: block; font-size: 13px; color: var(--muted); }
.rank .num { font-size: 20px; font-weight: 600; }
.exam-switch { margin: 8px 0; }
.help ul { padding-left: 20px; margin: 4px 0; }
.confirm-form { margin-top: 16px; }
details { margin: 8px 0; }
summary { cursor: pointer; color: var(--muted); }
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 20px 16px 30px; }

@media (max-width: 600px) {
    .card { padding: 16px; }
    .card.narrow { margin: 16px auto; }
    .total-score { width: 100%; }
    th, td { padding: 6px 8px; }
}

/* ---------- 编辑页 ---------- */
.grid-4 { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 14px; }
table.edit input { margin: 0; padding: 6px 8px; min-width: 80px; }
.danger-zone { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }
h3 { margin: 12px 0 4px; }

/* ---------- 统计页 ---------- */
.viz-root {
    --series-1: #2a78d6;
    --grid: #e7e6e2;
    --text-secondary: #52514e;
}
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.tile .label { display: block; font-size: 13px; color: var(--muted); }
.tile .num { display: block; font-size: 24px; font-weight: 700; line-height: 1.3; }
.tile .sub { display: block; font-size: 12px; color: var(--muted); }
.num-table td, .num-table th { text-align: right; }
.num-table td:first-child, .num-table th:first-child { text-align: left; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.two-col .card { margin-bottom: 16px; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }

/* 悬停 / 聚焦提示 */
.col, .bar-row { position: relative; outline: none; }
.tip {
    display: none; position: absolute; z-index: 5; left: 50%; bottom: 100%; transform: translateX(-50%);
    background: #1f2937; color: #fff; font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none;
}
.col:hover .tip, .col:focus .tip, .bar-row:hover .tip, .bar-row:focus .tip { display: block; }

/* 柱状图：柱宽 ≤24px，顶端 4px 圆角，底部平直 */
.colchart { display: flex; align-items: flex-end; gap: 2px; height: 220px; padding-top: 22px; border-bottom: 1px solid var(--grid); margin: 8px 0 30px; }
.col { flex: 1; height: 100%; display: flex; flex-direction: column; align-items: center; }
.col-plot { flex: 1; width: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.col-bar { width: 100%; max-width: 24px; background: var(--series-1); border-radius: 4px 4px 0 0; min-height: 0; }
.col:hover .col-bar, .col:focus .col-bar { filter: brightness(1.12); }
.col-val { font-size: 12px; color: var(--text-secondary); line-height: 1.6; }
.col-label { position: relative; top: 4px; height: 0; font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.col .tip { bottom: auto; top: 0; }

/* 条形图：条高 16px，末端 4px 圆角，数值在末端 */
.barchart { display: grid; gap: 10px; margin: 8px 0; }
.bar-row { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 10px; }
.bar-label { font-size: 13px; color: var(--text-secondary); text-align: right; }
.bar-track { display: flex; align-items: center; gap: 8px; border-left: 1px solid var(--grid); }
.bar { height: 16px; flex: none; background: var(--series-1); border-radius: 0 4px 4px 0; }
.bar-row:hover .bar, .bar-row:focus .bar { filter: brightness(1.12); }
.bar-val { font-size: 13px; color: var(--text-secondary); white-space: nowrap; }


/* ---------- 通用补充 ---------- */
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
a, button, select, summary, label.check { -webkit-tap-highlight-color: rgba(37, 99, 235, .12); }
.btn:disabled { opacity: .6; cursor: default; }
.result-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.result-head .btn { flex: none; }
.del-text { display: none; }
.scroll-hint { display: none; }
td.del label.check { margin: 0; justify-content: center; }
/* 宽表格：首列固定，横向滚动时仍能看到科目/班级 */
.num-table th:first-child, .num-table td:first-child { position: sticky; left: 0; background: var(--card); z-index: 1; }
.num-table thead th:first-child { background: #f9fafb; }

/* ---------- 手机端 ---------- */
@media (max-width: 600px) {
    body { font-size: 15px; }
    main.wrap { padding: 12px 12px calc(16px + env(safe-area-inset-bottom)); }
    h1 { font-size: 20px; }
    h2 { font-size: 17px; margin-top: 4px; }
    .card { padding: 14px; border-radius: 12px; margin-bottom: 12px; }
    .card.narrow { margin: 12px auto; }
    .front .card.narrow { margin-top: 8vh; }
    .btn { min-height: 42px; padding: 9px 14px; }
    .btn.small { min-height: 34px; padding: 5px 12px; }
    label.check { min-height: 36px; }
    input[type=checkbox] { width: 20px; height: 20px; }
    .foot { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

    /* 后台顶栏：导航单行横向滑动 */
    .topbar .wrap { display: block; padding: 10px 12px 0; }
    .topbar .brand { display: block; margin-bottom: 6px; }
    .topbar nav { flex-wrap: nowrap; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 8px; margin: 0 -12px; padding-left: 8px; padding-right: 8px; }
    .topbar nav::-webkit-scrollbar { display: none; }
    .topbar nav a, .topbar nav .link { flex: none; padding: 6px 12px; border-radius: 99px; white-space: nowrap; }
    .topbar nav a.active { background: rgba(255,255,255,.14); }

    /* 按钮组：等宽铺满 */
    .row-between { gap: 10px; }
    .actions { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .actions > form.inline { display: flex; }
    .actions > form.inline-form { display: flex; }
    .actions > form.inline-form select { width: 100%; }
    .actions > form.inline .btn, .actions > .btn { width: 100%; text-align: center; }
    .page-head .actions > form.inline-form select { margin: 0; }
    .inline-form input:not([type=hidden]) { min-width: 0; }

    /* 学生成绩页：总分与排名 */
    .total { gap: 10px; margin: 10px 0 12px; }
    .total-score { width: 100%; flex-direction: row; align-items: baseline; justify-content: space-between; padding: 14px 18px; }
    .total-score .num { font-size: 36px; }
    .ranks { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .rank { padding: 8px 12px; }
    .rank .num { font-size: 18px; }

    /* 学生成绩页：各科改为卡片 */
    table.scores thead { display: none; }
    table.scores, table.scores tbody { display: block; }
    table.scores tr { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
    table.scores td { border: 0; padding: 0; text-align: left !important; white-space: normal; }
    table.scores td.subj { grid-column: 1 / 3; font-size: 16px; font-weight: 600; align-self: center; }
    table.scores td.score { grid-column: 3; text-align: right !important; font-size: 22px; line-height: 1.2; }
    table.scores td.score::before { content: none; }
    table.scores td.rk { font-size: 15px; font-weight: 600; }
    table.scores td.rk::before { content: attr(data-label); display: block; font-size: 12px; font-weight: normal; color: var(--muted); }

    /* 通用：表格堆叠为卡片 */
    table.stack thead { display: none; }
    table.stack, table.stack tbody { display: block; }
    table.stack tr { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
    table.stack td { border: 0; padding: 0; white-space: normal; word-break: break-all; }
    table.stack td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); }
    table.stack td.stack-title { grid-column: 1 / -1; order: -1; font-size: 16px; font-weight: 600; padding-right: 80px; }
    table.stack td.stack-wide { grid-column: 1 / -1; }
    table.stack td.stack-action { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
    table.stack tr:has(td.stack-title) { position: relative; }
    table.stack td.stack-action { position: absolute; top: 8px; right: 2px; }

    /* 编辑页 */
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; }
    table.edit thead { display: none; }
    table.edit, table.edit tbody { display: block; }
    table.edit tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
    table.edit td { border: 0; padding: 0; white-space: normal; }
    table.edit td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
    table.edit td.subj { font-size: 16px; font-weight: 600; align-self: center; }
    table.edit td.del { justify-self: end; align-self: center; grid-row: 1; grid-column: 2; }
    table.edit td.del label.check { color: var(--danger); white-space: nowrap; }
    table.edit input { width: 100%; min-width: 0; padding: 8px 10px; }
    .del-text { display: inline; }
    .save-bar { position: sticky; bottom: 0; z-index: 10; background: var(--bg); padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); margin: 0 -12px; padding-left: 12px; padding-right: 12px; box-shadow: 0 -4px 12px rgba(0,0,0,.06); }

    /* 统计页 */
    .stat-tiles { grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
    .tile { padding: 10px 12px; }
    .tile .label { font-size: 12px; }
    .tile .num { font-size: 18px; }
    .tile .sub { font-size: 11px; }
    .colchart { height: 180px; }
    .col-label { font-size: 11px; }
    .bar-row { grid-template-columns: 44px 1fr; gap: 8px; }
    .num-table th, .num-table td { padding: 6px 8px; font-size: 14px; }
    table.kv th { width: 96px; }
    .scroll-hint { display: block; margin: -4px 0 4px; font-size: 12px; color: var(--muted); text-align: right; }
}
