/* c.css — สไตล์หน้านักเรียน C Sandbox (ทับ/เสริม style.css ที่ยกมาจาก SQL Sandbox)
 *
 * ⚠ style.css มีกฎ element selector และกฎ ID อย่าง `#login-screen { display:flex }`
 *   ที่แผ่มาถึงที่นี่ด้วย (gotcha ข้อ 13 ของโปรเจกต์เดิม) — เวลาเขียน flex container
 *   ใหม่ต้องระบุ justify-content เองเสมอ */

/* ⚠ ต้องมี — กฎ ID ใน style.css specificity สูงกว่า `[hidden]{display:none}` ของเบราว์เซอร์
 *   ทำให้ `el.hidden = true` ไม่ซ่อน (เคยทำให้หน้า login ค้างบังแอพหลังล็อกอินสำเร็จ) */
[hidden] { display: none !important; }

body { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
#app { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; width: 100%; }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; }
.header-right { display: flex; align-items: center; gap: 12px; }
.who { color: var(--blue); font-weight: 600; }
.muted { color: var(--muted); }
.sm { font-size: 12px; }
.menu-btn { display: none; }

/* ── โครง 3 คอลัมน์ ── */
.shell {
  flex: 1 1 auto; min-height: 0;
  display: grid; grid-template-columns: 232px minmax(0, 1fr) 400px;
}

/* ── ไซด์บาร์ ── */
.side {
  border-right: 1px solid var(--border); overflow: auto;
  display: flex; flex-direction: column; gap: 4px; padding: 8px 6px;
}
.side-sec { display: flex; flex-direction: column; }
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px 4px; color: var(--muted); font-size: 12px; font-weight: 600;
}
.side-list { display: flex; flex-direction: column; }
.side-empty { color: var(--muted); font-size: 12px; padding: 6px 10px; }
.side-group {
  padding: 8px 8px 3px; color: var(--muted); font-size: 11.5px; font-weight: 600;
  border-top: 1px solid var(--border);
}
.side-group:first-child { border-top: none; padding-top: 2px; }

.side-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13.5px;
}
.side-row:hover { background: var(--panel); }
.side-row.active { background: var(--panel-2); }
.row-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-acts { display: none; gap: 2px; }
.side-row:hover .row-acts { display: flex; }
/* จอสัมผัสไม่มี hover — ปุ่มเปลี่ยนชื่อ/ลบต้องโชว์ตลอด ไม่งั้นกดไม่ได้เลย */
@media (hover: none) { .row-acts { display: flex; } }
.row-act {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 12px; padding: 2px 5px; border-radius: 4px; font-family: inherit;
}
.row-act:hover { background: var(--panel-2); color: var(--text); }
.row-check { color: var(--green); }

.ex-no {
  flex: 0 0 22px; height: 20px; line-height: 20px; text-align: center;
  background: var(--panel-2); border-radius: 5px; font-size: 11px; font-weight: 700;
}
.side-row.done .ex-no { background: var(--green); color: var(--on-accent); }
.badge { background: var(--panel-2); border-radius: 10px; padding: 1px 8px; font-size: 11px; font-weight: 400; }

/* ── กลาง: หัวแถบ + โจทย์ + editor ── */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.io { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--border); }

.pane-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--muted); flex: 0 0 auto;
}
.pane-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
/* จอ 1024px (โปรเจกเตอร์ห้องคอม) คอลัมน์กลางเหลือ ~490px — ปุ่มตกเป็นสองบรรทัด ให้ชื่อไฟล์ถูกตัดแทน */
.pane-actions .btn-primary, .pane-actions .btn-ghost, .save-status { white-space: nowrap; }
.open-name { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; }
.open-icon {
  background: var(--panel-2); color: var(--muted); border-radius: 4px;
  padding: 1px 7px; font-size: 11px; flex: 0 0 auto;
}
#open-title { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.prob {
  flex: 0 0 auto; max-height: 42%; overflow: auto;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.prob > summary {
  cursor: pointer; padding: 8px 12px; font-size: 13px; color: var(--blue);
  position: sticky; top: 0; background: var(--panel); user-select: none;
}
.prob-body { padding: 4px 14px 14px; }
.prob-body { font-size: var(--code-fs, 14px); }
.prob-body p { margin: 0 0 6px; line-height: 1.7; }

.CodeMirror { flex: 1 1 auto; min-height: 0; font-size: var(--code-fs, 14px); line-height: 1.55; }

/* ── ขวา: stdin + ผลลัพธ์ ── */
.io-box {
  flex: 0 0 120px; resize: none; background: var(--code-bg); color: var(--text);
  border: none; border-bottom: 1px solid var(--border); padding: 10px 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px;
}
.io-box:focus { outline: 1px solid var(--blue); outline-offset: -1px; }

/* ชี้ให้เห็นตอนโค้ดมี scanf แต่ยังไม่ได้ใส่ข้อมูล — กับดักที่เงียบที่สุดของโหมด batch */
.stdin-hint { color: var(--orange); font-size: 11px; }
body.needs-stdin .io-box { outline: 1px solid var(--orange); outline-offset: -1px; }
body.needs-stdin .io-box::placeholder { color: var(--orange); opacity: .75; }

.output { flex: 1 1 auto; overflow: auto; padding: 12px; min-height: 0; }
.placeholder { color: var(--muted); font-size: 13px; padding: 6px 0; }

pre.stdout, pre.stderr {
  background: var(--code-bg); border-radius: 6px; padding: 10px 12px; margin: 0 0 10px;
  white-space: pre-wrap; word-break: break-word; font-size: calc(var(--code-fs, 14px) - 1px); line-height: 1.5;
  max-height: 340px; overflow: auto;
}
pre.stderr { color: var(--orange); border-left: 3px solid var(--orange); }

.msg { border-radius: 6px; padding: 8px 12px; margin-bottom: 10px; font-size: calc(var(--code-fs, 14px) - .5px); line-height: 1.6; }
.msg.ok   { background: var(--green-2); color: var(--green);  border-left: 3px solid var(--green); }
.msg.err  { background: var(--red-2); color: var(--red);   border-left: 3px solid var(--red); }
.msg.warn { background: var(--orange-2); color: var(--orange); border-left: 3px solid var(--orange); }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0; line-height: 1.6; }

/* ── ข้อความ error ที่แปลไทยแล้ว ── */
.diags { display: flex; flex-direction: column; gap: 8px; }
.diag { background: var(--panel); border-radius: 6px; padding: 8px 10px; border-left: 3px solid var(--red); }
.diag.warning { border-left-color: var(--orange); }
.diag-head { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.diag-loc { color: var(--blue); font-size: 12px; font-weight: 600; }
.diag-kind { color: var(--muted); font-size: 11px; }
.diag-thai { font-size: 13.5px; line-height: 1.65; margin-bottom: 5px; }
.diag-raw {
  display: block; color: var(--muted); font-size: 11.5px; background: var(--code-bg);
  padding: 4px 8px; border-radius: 4px; white-space: pre-wrap; word-break: break-word;
}

.save-status { font-size: 12px; color: var(--muted); }
.save-status.ok    { color: var(--green); }
.save-status.dirty { color: var(--orange); }
.save-status.err   { color: var(--red); }

/* ── โจทย์ / ผลตรวจ ── */
.sample { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 8px 0; }
.sample-label { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.sample pre, .test-grid pre {
  background: var(--code-bg); border-radius: 6px; padding: 8px 10px; margin: 0;
  font-size: calc(var(--code-fs, 14px) - 1px); white-space: pre-wrap; word-break: break-word; max-height: 180px; overflow: auto;
}
.ex-explain {
  background: var(--blue-1); border-left: 3px solid var(--blue);
  padding: 10px 12px; border-radius: 6px; line-height: 1.7; margin-bottom: 12px; font-size: 13.5px;
}
.tests { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.test { background: var(--panel); border-radius: 6px; padding: 10px 12px; border-left: 3px solid var(--panel-2); }
.test.ok  { border-left-color: var(--green); }
.test.bad { border-left-color: var(--red); }
.test-head { font-size: 13px; cursor: pointer; user-select: none; }
.test[open] > .test-head { margin-bottom: 6px; }
.test.ok > .test-head::after { content: '  · กดดูรายละเอียด'; color: var(--muted); font-size: 11.5px; }
.test.ok[open] > .test-head::after { content: ''; }
.test-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 6px 0; }
.test-grid > div { min-width: 0; }

/* ── ปุ่ม ── */
.btn-primary, .btn-ghost {
  font-family: inherit; font-size: 14px; border-radius: 6px; cursor: pointer;
  padding: 7px 14px; border: 1px solid transparent;
}
.btn-primary { background: var(--blue); color: var(--on-accent); font-weight: 600; }
/* ปุ่มที่เป็นลิงก์ (⏱ สอบ · ← หน้าฝึก) — หน้าตาเดียวกับปุ่ม ไม่มีขีดเส้นใต้ */
a.btn-primary, a.btn-ghost { text-decoration: none; display: inline-flex; align-items: center; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: none; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--panel-2); }
.btn-primary.sm, .btn-ghost.sm { padding: 4px 10px; font-size: 12.5px; }

/* ── login ── */
.login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 50; padding: 20px; overflow: auto;
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; width: min(460px, 100%); display: flex; flex-direction: column; gap: 12px;
  text-align: left;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-sub { margin: 0; color: var(--muted); font-size: 13.5px; }
.login-prev {
  background: var(--orange-2); color: var(--orange); border-radius: 6px;
  padding: 8px 10px; font-size: 12.5px; line-height: 1.5;
}
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input, .login-card select {
  background: var(--code-bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 8px 10px; font-family: inherit; font-size: 14px;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
/* โหมดอบรม: เหลือช่องชื่อช่องเดียว */
.login-card.quick .row2 { grid-template-columns: 1fr; }
.login-card.quick label:has(#login-sid), .login-card.quick label:has(#login-lastname), .login-card.quick .row3 { display: none; }
.login-error { color: var(--red); font-size: 13px; margin: 0; }

/* ── toast ── */
/* ⚠ style.css (ของกลาง) ตั้ง top:80px ไว้ — ต้อง top:auto ไม่งั้นได้ทั้ง top และ bottom
   กล่องจะยืดสูงเต็มจอเป็นแท่งเขียวกลางหน้า (เจอบน prod 3 ต.ค. 2569) */
.toast {
  position: fixed; top: auto; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); color: var(--text); padding: 10px 18px;
  border-radius: 8px; font-size: 14px; z-index: 100; box-shadow: 0 4px 20px var(--shadow);
}
.toast.ok { background: var(--green); color: var(--on-accent); }

/* ── จอแคบ: ไซด์บาร์กลายเป็น drawer · io ลงมาข้างล่าง ── */
@media (max-width: 1100px) {
  .shell { grid-template-columns: 200px minmax(0, 1fr) 330px; }
}
@media (max-width: 880px) {
  .menu-btn { display: inline-block; }
  #sys-info { display: none; }          /* ชื่อคอมไพเลอร์ยาว ดันหัวเว็บสูงเป็นคอลัมน์บนมือถือ */
  .shell { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .side {
    position: fixed; top: 0; bottom: 0; left: 0; width: 250px; z-index: 60;
    background: var(--bg); transform: translateX(-100%); transition: transform .18s;
  }
  .side.open { transform: none; box-shadow: 4px 0 24px var(--shadow); }
  .io { border-left: none; border-top: 1px solid var(--border); max-height: 45vh; }
  .row3 { grid-template-columns: 1fr; }
}

/* ── terminal โหมดโต้ตอบ ──
 * ต้องพิมพ์ "ต่อท้าย prompt" ในสายข้อความเดียวกัน ไม่ใช่กล่องแยกข้างล่าง
 * เพราะโปรแกรมเมนูจะพิมพ์ "เลือก: " แล้วรอ — ถ้าแยกกล่อง เด็กจะไม่เห็นว่ากำลังตอบอะไร */
.term { flex: 1 1 auto; min-height: 0; position: relative; display: flex; }
#term-out {
  flex: 1 1 auto; margin: 0; padding: 12px; overflow: auto; min-height: 0;
  background: var(--code-bg); color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: calc(var(--code-fs, 14px) - 1px); line-height: 1.55; white-space: pre-wrap; word-break: break-word;
  cursor: text;
}
/* input จริงต้องอยู่ใน DOM และ focus ได้ (เพื่อให้ IME ไทย + paste ทำงาน)
   แต่ต้องมองไม่เห็น — ใช้ opacity:0 ไม่ใช่ display:none เพราะ display:none จะ focus ไม่ได้ */
.term-key {
  position: absolute; opacity: 0; width: 1px; height: 1px;
  border: none; padding: 0; left: 0; bottom: 0;
}
.caret {
  display: inline-block; width: 7px; height: 1.05em; vertical-align: text-bottom;
  background: var(--blue); animation: blink 1.1s step-end infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* บอกว่า "กำลังรอข้อมูล" — จำเป็นเพราะโจทย์บังคับไม่ให้พิมพ์ prompt
   จอจะว่างสนิท เด็กแยกไม่ออกว่ารอข้อมูล กับ โปรแกรมค้าง */
.term-wait {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--orange-2); color: var(--orange);
  padding: 5px 12px; font-size: 12px; border-top: 1px solid var(--orange-br);
}

/* ── สี syntax ธีมสว่าง ──
   ธีม neo ของ CodeMirror ไม่มีสีของ ชนิดข้อมูล (int/double) · #include · builtin (printf/cout)
   ทั้งหมดเลยเป็นสีดำเท่ากับข้อความธรรมดา และระบายชื่อตัวแปรทุกตัวเป็นสีเขียว (ดูรกกว่าช่วย)
   → ใช้ชุดสีแบบ GitHub light แทนทั้งชุด · `span.` เพิ่ม specificity ให้ชนะ neo.css ที่โหลดทีหลัง
   ธีมมืด (material-darker) มีครบอยู่แล้ว ไม่ต้องแก้ */
.cm-s-neo span.cm-keyword    { color: #cf222e; }
.cm-s-neo span.cm-type,
.cm-s-neo span.cm-variable-3 { color: #8250df; }
.cm-s-neo span.cm-builtin    { color: #953800; }
.cm-s-neo span.cm-meta       { color: #116329; }
.cm-s-neo span.cm-string     { color: #0a3069; }
.cm-s-neo span.cm-string-2   { color: #0a3069; }
.cm-s-neo span.cm-number,
.cm-s-neo span.cm-atom       { color: #0550ae; }
.cm-s-neo span.cm-comment    { color: #6e7781; font-style: italic; }
.cm-s-neo span.cm-def        { color: #8250df; }
.cm-s-neo span.cm-variable,
.cm-s-neo span.cm-qualifier  { color: #24292f; }

/* ══ หน้าสอบ (exam.html) ═══════════════════════════════════════
   หน้านี้เลื่อนทั้งหน้าได้ (ต่างจากหน้าฝึกที่ล็อกความสูงเท่าจอ) — โจทย์ + ตัวอย่างยาวไม่เท่ากัน
   คลาสของแถบเวลา/ตารางข้อ/กล่องยืนยัน/กระดานผู้นำ มาจาก style.css (ชุดเดียวกับหน้าสอบ SQL) */
body.exam-page { height: auto; min-height: 100vh; overflow: auto; display: block; }
.xp-wrap { max-width: 1440px; margin: 0 auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.xp-narrow { width: 100%; max-width: 820px; margin: 0 auto; }
#exam-live:not([hidden]) { display: flex; flex-direction: column; gap: 12px; }
/* แถบเวลาติดขอบบนเสมอ — โจทย์ยาว/เลื่อนลงไปดู editor แล้วต้องยังเห็นนาฬิกา */
#exam-live .exam-topbar { margin: 0; position: sticky; top: 0; z-index: 20; box-shadow: 0 4px 14px var(--shadow); }
#exam-live .exam-grid { margin: 0; }
.xp-shell { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 12px; align-items: start; }
.xp-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.xp-main .exam-q-desc { margin: 0; color: var(--text-2); }
.xp-editor { height: 48vh; min-height: 320px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.xp-editor .CodeMirror { height: 100%; font-size: 14px; }
.xp-samples { display: flex; flex-direction: column; gap: 8px; }
.xp-sample { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.xp-sample-head { display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.xp-sample-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.xp-sample-grid > div { min-width: 0; }
.xp-sample pre {
  background: var(--code-bg); border-radius: 6px; padding: 8px 10px; margin: 0;
  font-size: 13px; white-space: pre-wrap; word-break: break-word; max-height: 180px; overflow: auto;
}
.xp-io { display: flex; flex-direction: column; gap: 8px; position: sticky; top: 12px; }
.xp-io-head { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--text-2); }
.xp-stdin { width: 100%; min-height: 96px; resize: vertical; box-sizing: border-box;
  font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; color: var(--text);
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; }
.xp-out { min-height: 180px; max-height: 52vh; flex: none; border: 1px solid var(--border); border-radius: 6px; }
#exam-live.time-danger .xp-editor { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-2); }
/* จอมือถือ: แถบเวลาสูงเกือบหนึ่งในสี่ของจอ ถ้าติดขอบบนจะบัง editor — ปล่อยให้เลื่อนตามปกติ */
@media (max-width: 640px) {
  #exam-live .exam-topbar { position: static; box-shadow: none; }
}
@media (max-width: 1000px) {
  .xp-shell { grid-template-columns: 1fr; }
  .xp-io { position: static; }
  .xp-sample-grid { grid-template-columns: 1fr; }
}

/* ══ ขนาดตัวอักษร (A− / A+) ══════════════════════════════════
   --code-fs ตั้งที่ <html> โดย app.js (applyFont) — ค่าเริ่ม 14px · editor/terminal/ผลลัพธ์/โจทย์ ใช้ตัวนี้ */
.font-ctl { display: inline-flex; align-items: center; gap: 2px; }
.font-ctl .btn-ghost.sm { padding: 2px 7px; min-width: 28px; }
.font-ctl .btn-ghost:disabled { opacity: .4; cursor: default; }
.font-size { min-width: 22px; text-align: center; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ══ ป้ายระดับความยาก ══════════════════════════════════════════
   ⚠ ใช้ตัวแปรสีที่มีชุดธีมสว่างแยก (--green-2 ฯลฯ) — สีดิบจะจางจนมองไม่เห็นบนพื้นขาว */
.diff {
  flex: 0 0 auto; font-size: 10.5px; font-weight: 600; line-height: 1;
  padding: 3px 6px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap;
}
.diff-easy { background: var(--green-2);  color: var(--green);  border-color: var(--green-br); }
.diff-mid  { background: var(--orange-2); color: var(--orange); border-color: var(--orange-br); }
.diff-hard { background: var(--red-2);    color: var(--red);    border-color: var(--red-br); }
.prob > summary .diff { margin-left: 4px; vertical-align: 1px; }

/* ══ ตารางไล่ค่าตัวแปร ══════════════════════════════════════════ */
.trace { margin: 10px 0 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.trace > summary {
  cursor: pointer; padding: 8px 12px; font-size: 13px; font-weight: 600; color: var(--text-2);
  user-select: none; list-style-position: inside;
}
.trace[open] > summary { border-bottom: 1px solid var(--border); }
.trace-wrap { overflow-x: auto; }
/* style.css ตั้ง table ทั้งเว็บเป็น nowrap — ตารางนี้มีคำอธิบายยาว ต้องตัดบรรทัดได้ */
.trace-table { white-space: normal; font-size: calc(var(--code-fs, 14px) - 1.5px); }
.trace-table th, .trace-table td { padding: 6px 10px; vertical-align: top; }
.trace-table th { font-family: inherit; letter-spacing: 0; color: var(--muted); white-space: nowrap; }
.trace-table td:first-child { color: var(--muted); white-space: nowrap; }
.trace-table code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; white-space: pre-wrap; }
.trace-table .trace-out { color: var(--green); font-family: ui-monospace, "SF Mono", Menlo, monospace; font-weight: 600; }
.trace-table th.trace-out { color: var(--green); font-family: inherit; }
.trace-nil { color: var(--dim); }
.trace-note { margin: 8px 12px 10px; }

/* ══ ตารางคะแนนสด ════════════════════════════════════════════ */
.sb-backdrop {
  position: fixed; inset: 0; z-index: 80; background: var(--backdrop);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px;
}
.sb-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  width: min(560px, 100%); max-height: 86vh; display: flex; flex-direction: column;
  box-shadow: 0 12px 40px var(--shadow);
}
.sb-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.sb-head strong { font-size: 16px; }
.sb-head .muted { flex: 1; min-width: 0; }
.sb-body { overflow: auto; padding: 6px 4px 10px; }
.sb-table { white-space: normal; }
.sb-table th { font-family: inherit; letter-spacing: 0; color: var(--muted); position: sticky; top: 0; background: var(--panel); }
.sb-table th, .sb-table td { padding: 8px 12px; }
.sb-rank { width: 52px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; }
.sb-name { word-break: break-word; }
.sb-you {
  margin-left: 6px; font-size: 10.5px; font-weight: 700; padding: 2px 6px; border-radius: 999px;
  background: var(--blue-2); color: var(--blue);
}
.sb-solved { white-space: nowrap; }
.sb-bar {
  display: inline-block; width: 90px; height: 6px; border-radius: 3px; background: var(--panel-2);
  vertical-align: middle; overflow: hidden; margin-right: 8px;
}
.sb-fill { display: block; height: 100%; background: var(--green); border-radius: 3px; }
.sb-num { font-variant-numeric: tabular-nums; font-weight: 600; }
.sb-time { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.sb-table tr.me td { background: var(--blue-1); }
.sb-body > .hint, .sb-body > .placeholder, .sb-body > .msg { margin: 10px 14px; }
@media (max-width: 520px) {
  .sb-bar { display: none; }
  .sb-table th, .sb-table td { padding: 7px 8px; }
}
/* จอมือถือ: หัวเว็บไม่พอใส่ปุ่มครบ (body ล็อก overflow — ปุ่มขวาสุดหลุดจอกดไม่ได้)
   ปุ่ม A−/A+ มีไว้ฉายจอหน้าห้อง มือถือไม่จำเป็น · 🏆 / ⏱ เหลือแค่ไอคอน */
@media (max-width: 880px) {
  .font-ctl { display: none; }
  .btn-lbl { display: none; }
  .header-right { gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  .header-right .btn-ghost { padding: 6px 10px; }
  .pane-actions .btn-primary, .pane-actions .btn-ghost, .save-status { white-space: normal; }
  /* ข้อความบันทึกปกติซ่อนไว้ประหยัดที่ — แต่ "⚠ บันทึกไม่สำเร็จ" ต้องเห็นเสมอ */
  #save-status:not(.err) { display: none; }
}

/* ══ กล่องถาม/ยืนยัน (askDialog) — ใช้ฉากหลังเดียวกับตารางคะแนน ══ */
.dlg-backdrop { z-index: 90; align-items: flex-start; padding-top: 18vh; }
.dlg-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  width: min(420px, 100%); padding: 20px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 12px 40px var(--shadow);
}
.dlg-title { margin: 0; font-size: 17px; word-break: break-word; }
.dlg-msg { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.6; }
.dlg-input {
  background: var(--code-bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 9px 11px; font-family: inherit; font-size: 15px;
}
.dlg-input:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.dlg-err { margin: -4px 0 0; color: var(--red); font-size: 12.5px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.dlg-actions .btn-primary.danger { background: var(--red); }

/* ── การ์ดหัวชุดโจทย์ (C++ ชุดผู้เริ่มต้น) — ดู partIntroCard ใน app.js ── */
.part-intro { margin: 0 0 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); overflow: hidden; }
.part-intro > summary { cursor: pointer; padding: 9px 12px; font-weight: 700; min-height: 40px; display: flex; align-items: center; }
.part-intro[open] > summary { border-bottom: 1px solid var(--border); }
.part-intro-cover { display: block; width: 100%; max-width: 100%; height: auto; max-height: 190px; object-fit: contain; background: #fff; }   /* รูปเป็นพื้นขาว — จำกัดความสูงไม่ให้ดันโจทย์ตกจอ */
.part-intro-heading { margin: 10px 12px 0; font-weight: 700; text-align: center; }
.part-intro-blurb { margin: 8px 12px 0; line-height: 1.7; }
.part-intro-table-title { margin: 12px 12px 4px; font-weight: 700; }
.part-intro-tablewrap { margin: 0 12px 12px; overflow-x: auto; }
.part-intro-table { border-collapse: collapse; min-width: 100%; }
.part-intro-table th, .part-intro-table td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; vertical-align: top; }
.part-intro-table th { background: var(--panel, rgba(127, 127, 127, .12)); }
.part-intro-table td:first-child { font-family: ui-monospace, Menlo, Consolas, monospace; white-space: nowrap; }
