:root {
  --bg: #f7f4ee; --card: #fff; --ink: #2b2420; --muted: #7a6f66; --line: #e4ddd2;
  --accent: #8a3b12; --accent-soft: #f6e7dc; --ok: #2f7d4a; --warn: #b7791f; --bad: #b42318; --info: #1d5fa8;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Sarabun", system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 16px; }
a { color: var(--accent); }
main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 1.6rem; margin: 8px 0 16px; }
h2 { font-size: 1.2rem; margin: 24px 0 10px; }
.topbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--accent); color: #fff; }
.topbar a, .topbar .link { color: #fff; text-decoration: none; margin-left: 14px; font: inherit; }
.brand { font-weight: 700; font-size: 1.15rem; margin-left: 0 !important; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.narrow { max-width: 420px; margin: 40px auto; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
label { display: block; margin: 10px 0 4px; font-weight: 600; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; }
textarea { min-height: 70px; }
button, .btn { display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font: inherit; cursor: pointer; text-decoration: none; }
button.secondary, .btn.secondary { background: #fff; color: var(--accent); }
button.danger { background: var(--bad); border-color: var(--bad); }
button.small, .btn.small { padding: 3px 10px; font-size: .9rem; }
button.link { background: none; border: none; padding: 0; cursor: pointer; text-decoration: underline; }
button:disabled { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); font-size: .92rem; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #faf7f2; font-weight: 600; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: #e7f5ec; border: 1px solid #b6e0c4; }
.flash.err { background: #fdecea; border-color: #f5c2bd; }
.flash.info { background: #e8f0fb; border-color: #bcd3f2; font-size: 1.05rem; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .85rem; background: #eee; white-space: nowrap; }
.badge.done, .badge.confirmed, .badge.active { background: #e2f3e8; color: var(--ok); }
.badge.queued, .badge.processing, .badge.draft, .badge.pending { background: #fdf3dc; color: var(--warn); }
.badge.failed, .badge.rejected { background: #fdecea; color: var(--bad); }
.stat { font-size: 2rem; font-weight: 700; }
.levels td.lv { font-weight: 700; }
.lv0 { color: var(--ok); } .lv1 { color: #4b8a2f; } .lv2 { color: var(--warn); } .lv3 { color: var(--bad); }

/* ---- ผลตรวจ: timeline ---- */
.player { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0; }
audio { width: 100%; }
.timeline { position: relative; height: 54px; background: #fff; border: 1px solid var(--line); border-radius: 8px;
  margin-top: 6px; cursor: pointer; overflow: hidden; }
.timeline .mk { position: absolute; width: 3px; border-radius: 2px; }
.timeline .head { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); pointer-events: none; }
.mk.note { top: 4px; height: 14px; } .mk.time { top: 20px; height: 14px; } .mk.flow { top: 36px; height: 14px; }
.t-wrong, .t-missed, .t-extra { background: var(--bad); }
.t-octave, .t-missing_pair { background: #e07b39; }
.t-timing { background: var(--info); } .t-timing_minor { background: #7fa9db; }
.t-stumble, .t-restart, .t-slow { background: #7a3fb0; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .88rem; margin-top: 6px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px;
  background: var(--c); vertical-align: middle; }
tr.err-row { cursor: pointer; }
tr.err-row:hover { background: var(--accent-soft); }
tr.err-row.ignored td { text-decoration: line-through; color: var(--muted); }
tr.err-row.current { outline: 2px solid var(--accent); }
.filters label { display: inline-flex; align-items: center; gap: 4px; font-weight: 400; margin: 0 12px 0 0; }

/* ---- ตัวแก้ไขโน้ต ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.score-sheet { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.sec-title { font-weight: 700; color: var(--accent); margin: 14px 0 6px; display: flex; gap: 8px; align-items: center; }
.line { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); border-left: 1px solid #c9bfb2; margin-bottom: 6px; }
.bar { display: grid; grid-template-columns: repeat(4, 1fr); border-right: 1px solid #c9bfb2; position: relative; padding-top: 14px; }
.bar .num { position: absolute; top: 0; left: 3px; font-size: .7rem; color: var(--muted); cursor: pointer; }
.bar .num:hover { color: var(--accent); text-decoration: underline; }
.cell { position: relative; height: 46px; display: flex; align-items: center; justify-content: center; font-size: 1.15rem;
  cursor: pointer; user-select: none; border-radius: 4px; }
.cell:hover { background: #f3ede4; }
.cell.sel { background: var(--accent-soft); outline: 2px solid var(--accent); }
.cell.pair { font-weight: 700; color: var(--accent); }
.cell.pair::after { content: "คู่"; position: absolute; bottom: 1px; right: 2px; font-size: .55rem; color: var(--accent); }
.cell .dots { position: absolute; left: 0; right: 0; text-align: center; font-size: .8rem; line-height: 1; letter-spacing: 1px; }
.cell .dots.up { top: 2px; } .cell .dots.down { bottom: 2px; }
.cell.playing { background: #fff3c4; }
.help { font-size: .88rem; color: var(--muted); }
.help kbd { background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-family: inherit; }
@media (max-width: 760px) {
  .line { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .cell { height: 40px; font-size: 1rem; }
}
.progress { height: 10px; background: #eee; border-radius: 6px; overflow: hidden; margin-top: 8px; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.mk-dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.timeline .outside { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(45deg, #eee, #eee 4px, #f8f8f8 4px, #f8f8f8 8px); }

/* ---- กราฟสรุปผล ---- */
:root { --series-ai: #2a78d6; --series-teacher: #eb6834; --viz-neutral: #9b948b; --viz-track: #f1ece4; }
.viz-card h3 { margin: 0 0 8px; font-size: 1rem; }
.viz-legend { display: flex; gap: 16px; font-size: .88rem; color: var(--muted); margin-bottom: 8px; }
.viz-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.s-ai { background: var(--series-ai); } .s-teacher { background: var(--series-teacher); } .s-neutral { background: var(--viz-neutral); }
.viz-groups { display: grid; gap: 10px; }
.viz-group { display: grid; grid-template-columns: minmax(90px, 30%) 1fr; gap: 10px; align-items: center; }
.viz-cat { font-size: .9rem; color: var(--ink); line-height: 1.25; overflow-wrap: anywhere; }
.viz-bar-row { display: grid; grid-template-columns: 1fr 52px; gap: 8px; align-items: center; padding: 2px 0; }
.viz-track { height: 10px; background: var(--viz-track); border-radius: 4px; position: relative; }
.viz-bar { height: 100%; border-radius: 0 4px 4px 0; }
.viz-val { font-size: .85rem; color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }
.viz-val.muted { color: var(--muted); }
.viz-db { display: grid; gap: 2px; }
.viz-db-row { display: grid; grid-template-columns: minmax(90px, 30%) 1fr 44px; gap: 10px; align-items: center; min-height: 26px; }
.viz-db-track { position: relative; height: 20px; border-bottom: 1px dashed var(--line); }
.viz-db-line { position: absolute; top: 9px; height: 2px; background: #c9c2b8; }
.viz-dot { position: absolute; top: 5px; width: 10px; height: 10px; border-radius: 50%; margin-left: -5px; box-shadow: 0 0 0 2px #fff; }
.viz-axis { position: relative; height: 16px; font-size: .75rem; color: var(--muted); }
.viz-axis span { position: absolute; transform: translateX(-50%); }
.viz-tip { position: fixed; z-index: 50; background: #2b2420; color: #fff; padding: 6px 10px; border-radius: 6px; font-size: .85rem;
  pointer-events: none; max-width: 260px; line-height: 1.4; }
.rubric input[type=number] { width: 80px; padding: 4px 6px; }
.rubric td, .rubric th { vertical-align: middle; }
.rubric tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
