:root {
  --bg:       #0f172a;
  --panel:    #1e293b;
  --panel-2:  #334155;
  --text:     #e2e8f0;
  --muted:    #94a3b8;
  --blue:     #38bdf8;
  --green:    #4ade80;
  --orange:   #fb923c;
  --red:      #f87171;
  --border:   #334155;
  --code-bg:  #0b1220;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI',
    'Sukhumvit Set', 'Noto Sans Thai', sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

/* ══════════════════════════════════════════
   Header
══════════════════════════════════════════ */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.header-left h1 {
  margin: 0;
  font-size: 20px;
  color: var(--blue);
  line-height: 1.2;
}

.header-left .subtitle { font-size: 12px; color: var(--muted); }

.header-right { display: flex; gap: 10px; align-items: center; }

.badge {
  background: var(--panel-2);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
}

.badge.sync.ok  { color: var(--green); }
.badge.sync.err { color: var(--red); }

/* ══════════════════════════════════════════
   Modal (shared)
══════════════════════════════════════════ */

/* ══════════════════════════════════════════
   Login screen
══════════════════════════════════════════ */
#login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#login-screen.hidden { display: none; }

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 44px 48px 40px;
  width: 400px;
  max-width: 90vw;
  text-align: center;
}

.login-logo {
  font-size: 40px;
  margin-bottom: 12px;
  line-height: 1;
}

.login-title {
  margin: 0 0 6px;
  font-size: 26px;
  color: var(--blue);
  text-transform: none;
  letter-spacing: normal;
}

.login-sub {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 14px;
}

.login-label {
  display: block;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.login-input {
  width: 100%;
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 16px;
  text-align: center;
  margin-bottom: 8px;
}

.login-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(56,189,248,.15);
}

.login-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 20px;
}

/* ── login: รหัส + ชื่อ + นามสกุล ── */
.login-card .login-label { margin-top: 2px; }
.login-input-mono {
  font-family: 'JetBrains Mono', Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
}
.login-name-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
  text-align: left;
}
.login-name-row .login-input { text-align: left; font-size: 15px; }
.login-error {
  font-size: 13px;
  color: var(--red);
  font-weight: 600;
  margin: 12px 0 0;
  background: rgba(248,113,113,.1);
  border-radius: 6px;
  padding: 8px 12px;
  text-align: left;
}
.login-error.hidden { display: none; }

.login-btn {
  width: 100%;
  background: var(--blue);
  color: #0f172a;
  font-weight: 700;
  font-size: 16px;
  padding: 12px;
  border: none;
  border-radius: 8px;
}

/* ── Who badge — คลิกเปลี่ยนชื่อ ── */
.who-badge {
  cursor: pointer;
  transition: background 0.15s;
}

/* เครื่องเป็นของโรงเรียน ใช้ร่วมกัน — ทางออกต้องเห็นชัด ไม่ใช่ซ่อนใน tooltip ของชื่อ */
.btn-signout {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s;
}
.btn-signout:hover {
  color: var(--red);
  border-color: var(--red);
  background: rgba(248,113,113,.1);
}

.who-badge:hover {
  background: #475569;
  color: var(--text);
}

.who-badge .who-sid {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 11px;
  color: var(--blue);
  background: rgba(56,189,248,.12);
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 6px;
}

/* ══════════════════════════════════════════
   Main tab nav
══════════════════════════════════════════ */
.main-tabs {
  display: flex;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  gap: 2px;
}

.main-tab {
  padding: 13px 22px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 0;
  margin-bottom: -1px;
  transition: color 0.15s;
}

.main-tab:hover { color: var(--text); }

.main-tab.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

/* ══════════════════════════════════════════
   Layout
══════════════════════════════════════════ */
main {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 16px;
  padding: 16px 24px 40px;
  align-items: start;
}

/* แท็บ view: ตารางต้องการพื้นที่เต็ม — ซ่อน sidebar log */
body[data-tab="view"] main { grid-template-columns: 1fr; }
body[data-tab="view"] .log-section { display: none; }

.tab-area {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tab-panel        { display: flex; flex-direction: column; gap: 16px; }
.tab-panel.hidden { display: none; }

/* ══════════════════════════════════════════
   Card (shared section wrapper)
══════════════════════════════════════════ */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 18px 16px;
}

h2 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--blue);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hidden { display: none !important; }

/* ══════════════════════════════════════════
   Buttons
══════════════════════════════════════════ */
button {
  font-family: inherit;
  font-size: 14px;
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: filter 0.15s;
}

button:hover { filter: brightness(1.15); }

.btn-primary {
  background: var(--blue);
  color: #0f172a;
  font-weight: 700;
  font-size: 15px;
  padding: 8px 28px;
}

.btn-sm { padding: 7px 22px; font-size: 14px; }

/* ══════════════════════════════════════════
   Template buttons (SQL tab)
══════════════════════════════════════════ */
.template-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.tpl-label { font-size: 12px; color: var(--muted); }

.tpl-btn {
  font-family: 'JetBrains Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 14px;
  letter-spacing: 0.05em;
  border: 1px solid;
}

.tpl-select { color: var(--blue);   border-color: var(--blue);   background: rgba(56,189,248,.1); }
.tpl-where  { color: var(--green);  border-color: var(--green);  background: rgba(74,222,128,.1); }
.tpl-join   { color: #c084fc;       border-color: #c084fc;       background: rgba(192,132,252,.12); }

/* ══════════════════════════════════════════
   SQL Textarea
══════════════════════════════════════════ */
textarea#sql {
  width: 100%;
  min-height: 150px;
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-family: 'JetBrains Mono', Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.7;
  resize: vertical;
}

textarea#sql:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(56,189,248,.12);
}

.run-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }

kbd {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 11px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid #475569;
}

/* ══════════════════════════════════════════
   Result (SQL tab)
══════════════════════════════════════════ */
#result-content { min-height: 36px; }

.msg { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.msg.ok    { color: var(--green); }
.msg.error { color: var(--red); font-family: 'JetBrains Mono', Menlo, monospace; font-size: 13px; white-space: pre-wrap; }
.msg.muted { color: var(--muted); }

.null { color: #475569; font-style: italic; }

/* ══════════════════════════════════════════
   Shared table
══════════════════════════════════════════ */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

th, td { padding: 7px 14px; border-bottom: 1px solid var(--border); text-align: left; }

th {
  background: var(--code-bg);
  color: var(--blue);
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

tbody tr:hover  { background: rgba(255,255,255,.04); }
tbody tr:last-child td { border-bottom: none; }

.table-empty { text-align: center; color: var(--muted); padding: 32px; font-size: 14px; }

/* ══════════════════════════════════════════
   Form tabs (inside tab-form)
══════════════════════════════════════════ */

/* ══════════════════════════════════════════
   Field grid (forms)
══════════════════════════════════════════ */

.field input,

.field input:focus,

/* ── SQL preview ── */

/* ── Lookup row ── */

/* ── Form footer & status ── */

/* ── Student card (delete) ── */

/* ══════════════════════════════════════════
   View tab
══════════════════════════════════════════ */
.view-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.view-search {
  flex: 1;
  min-width: 160px;
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 13px;
}

.view-search:focus { outline: none; border-color: var(--blue); }

.view-count {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.live-dot {
  font-size: 12px;
  color: var(--green);
  font-weight: 600;
}

/* ══════════════════════════════════════════
   Activity log (always visible sidebar)
══════════════════════════════════════════ */
.log-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 18px 16px;
  position: sticky;
  top: 112px;     /* below header + main-tabs */
}

ul#log {
  margin: 0; padding: 0;
  list-style: none;
  max-height: calc(100vh - 230px);
  overflow-y: auto;
  font-size: 12px;
}

ul#log li {
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  line-height: 1.4;
}

ul#log li:last-child { border-bottom: none; }
ul#log li.empty { color: var(--muted); text-align: center; padding: 24px; font-size: 13px; }

ul#log .at   { display: block; color: var(--muted); font-size: 11px; margin-bottom: 2px; }
ul#log .who  { color: var(--blue); font-weight: 700; }
ul#log code  {
  display: block;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 11px;
  background: var(--code-bg);
  padding: 4px 8px;
  border-radius: 4px;
  margin: 4px 0;
  white-space: pre-wrap;
  word-break: break-all;
  color: #cbd5e1;
}

ul#log .summary { color: var(--green); font-size: 11px; }
ul#log .errtxt  { color: var(--red);   font-size: 11px; }
ul#log li.err code { color: var(--red); opacity: .8; }

/* ══════════════════════════════════════════
   Schema reference
══════════════════════════════════════════ */
.schema-card { padding: 12px 16px; }

.schema-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  list-style: none;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  user-select: none;
}

.schema-summary::-webkit-details-marker { display: none; }
.schema-summary code { font-size: 12px; color: var(--orange); background: rgba(251,146,60,.1); padding: 1px 6px; border-radius: 3px; }
.schema-tip { font-size: 11px; color: var(--muted); font-weight: 400; letter-spacing: 0; text-transform: none; }

.schema-body { margin-top: 10px; }

.schema-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.1s;
}
.schema-row:hover { background: rgba(56,189,248,.08); }

.schema-col-name {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--blue);
  min-width: 130px;
  font-weight: 600;
}

.schema-col-pk { color: var(--orange); font-size: 10px; margin-left: 2px; }

.schema-col-type {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--orange);
  background: rgba(251,146,60,.1);
  padding: 1px 7px;
  border-radius: 3px;
  min-width: 52px;
  text-align: center;
}

.schema-col-sample {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.schema-copy-hint { font-size: 10px; color: var(--panel-2); }
.schema-row:hover .schema-copy-hint { color: var(--blue); }

/* ── แผนผังความสัมพันธ์ตาราง (สำหรับ JOIN) ── */
.schema-map {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.schema-map .map-t {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--blue);
  background: rgba(56,189,248,.12);
  padding: 3px 10px;
  border-radius: 5px;
}
.schema-map .map-mid {
  color: #c084fc;
  background: rgba(192,132,252,.14);
}
.schema-map .map-arrow { color: var(--muted); font-size: 13px; }
.schema-map .map-hint {
  font-size: 11px;
  color: var(--muted);
  margin-left: auto;
}

/* ── กลุ่มคอลัมน์ต่อ 1 ตาราง ── */
.schema-table { margin-bottom: 16px; }
.schema-table:last-child { margin-bottom: 0; }

.schema-table-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 0 8px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.schema-tname {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
}
.schema-tname:hover { color: var(--blue); }
.schema-tnote { font-size: 11px; color: var(--muted); }

.schema-col-pk {
  color: var(--orange);
  font-size: 9px;
  margin-left: 5px;
  border: 1px solid var(--orange);
  padding: 0 4px;
  border-radius: 3px;
  vertical-align: 1px;
}
.schema-col-fk {
  color: #c084fc;
  font-size: 10px;
  margin-left: 6px;
  font-weight: 400;
}

/* ══════════════════════════════════════════
   Data note — เตือนว่าเป็นข้อมูลสมมติ
══════════════════════════════════════════ */
.data-note {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  background: rgba(56,189,248,.06);
  border: 1px solid rgba(56,189,248,.2);
  border-radius: 7px;
  padding: 9px 13px;
  margin: 0 0 14px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
}
.data-note b { color: var(--text); font-weight: 600; }
.data-note code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  background: var(--code-bg);
  padding: 1px 6px;
  border-radius: 3px;
  color: var(--orange);
}
.data-note-ico {
  color: var(--blue);
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
  line-height: 1.5;
}

/* ══════════════════════════════════════════
   View tab — ตัวเลือกตาราง
══════════════════════════════════════════ */
.vt-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.vt-tab {
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.vt-tab:hover  { color: var(--text); }
.vt-tab.active {
  color: var(--blue);
  border-color: var(--blue);
  background: rgba(56,189,248,.12);
}
.vt-count {
  font-size: 10px;
  opacity: .7;
  margin-left: 4px;
}

/* ══════════════════════════════════════════
   Exercises
══════════════════════════════════════════ */
.ex-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.ex-progress-wrap { display: flex; align-items: center; gap: 10px; }

.ex-prog-text { font-size: 13px; color: var(--muted); white-space: nowrap; }

.progress-track {
  width: 130px; height: 6px;
  background: var(--panel-2);
  border-radius: 99px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 99px;
  transition: width 0.4s ease;
}

/* Exercise card */
.ex-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
  transition: border-color 0.2s;
}

.ex-card.ex-done { border-color: rgba(74,222,128,.35); }

.ex-header-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  background: var(--panel-2);
  border: none;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  border-radius: 0;
  font-family: inherit;
}

.ex-card.ex-done .ex-header-btn { background: rgba(74,222,128,.07); }
.ex-header-btn:hover { filter: brightness(1.1); }

.ex-num {
  font-size: 12px; font-weight: 700;
  background: var(--panel);
  color: var(--muted);
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.ex-card.ex-done .ex-num { background: var(--green); color: #0f172a; }

.ex-info { flex: 1; min-width: 0; }
.ex-title { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.ex-tags  { display: flex; gap: 6px; }

.tag {
  font-size: 11px; font-weight: 700;
  padding: 2px 9px; border-radius: 99px;
  letter-spacing: 0.03em;
}
.tag-topic  { background: rgba(56,189,248,.15); color: var(--blue); }
.tag-easy   { background: rgba(74,222,128,.15);  color: var(--green); }
.tag-medium { background: rgba(251,146,60,.15);  color: var(--orange); }
.tag-hard   { background: rgba(248,113,113,.15); color: var(--red); }

.ex-check-icon { font-size: 16px; color: var(--muted); font-weight: 700; flex-shrink: 0; }
.ex-card.ex-done .ex-check-icon { color: var(--green); }

.ex-body {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.ex-desc { font-size: 14px; margin: 0 0 12px; line-height: 1.65; }

.ex-textarea {
  width: 100%;
  min-height: 72px;
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 13px;
  resize: vertical;
  margin-bottom: 10px;
}

.ex-textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(56,189,248,.12);
}

.ex-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.ex-feedback {
  font-size: 13px; font-weight: 600;
  padding: 5px 12px; border-radius: 6px;
}

.fb-ok  { color: var(--green); background: rgba(74,222,128,.1); }
.fb-err { color: var(--red);   background: rgba(248,113,113,.1); }

/* ══════════════════════════════════════════
   Toast (แจ้งเตือนทั่วไป)
══════════════════════════════════════════ */
.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--blue);
  color: var(--text);
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(0,0,0,.4);
  z-index: 400;
  transition: opacity .25s, transform .25s;
}

.toast.hidden { opacity: 0; pointer-events: none; transform: translate(-50%, -8px); }
.toast.warn { border-color: var(--orange); color: var(--orange); }

/* ══════════════════════════════════════════
   Error block (hint + raw details)
══════════════════════════════════════════ */
.err-block {
  background: rgba(248,113,113,.06);
  border: 1px solid rgba(248,113,113,.25);
  border-left: 3px solid var(--red);
  border-radius: 6px;
  padding: 10px 14px;
}

.err-hint { color: var(--red); font-weight: 600; font-size: 14px; margin: 0; }

.err-raw {
  margin-top: 8px;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
}

.err-raw summary {
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  color: var(--muted);
  user-select: none;
}

.err-raw[open] summary { color: var(--text); }

/* ══════════════════════════════════════════
   Sticky table header (view tab)
══════════════════════════════════════════ */
#tab-view .table-wrapper {
  max-height: 70vh;
  overflow: auto;
}

#tab-view thead th {
  position: sticky;
  top: 0;
  background: var(--code-bg);
  z-index: 1;
}

/* ══════════════════════════════════════════
   Log: คลิกได้ + replay hint
══════════════════════════════════════════ */
ul#log li.clickable      { cursor: pointer; transition: background .12s; }
ul#log li.clickable:hover { background: rgba(56,189,248,.06); }
ul#log li.clickable code  { transition: color .12s; }
ul#log li.clickable:hover code { color: var(--blue); }

/* ══════════════════════════════════════════
   Exercise result — ตารางผลลัพธ์ของคำสั่งที่นักเรียนพิมพ์
══════════════════════════════════════════ */
.ex-result {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.ex-result.hidden { display: none; }
.ex-res-label {
  margin: 0 0 8px;
  font-size: 11.5px;
  color: var(--muted);
}
.ex-res-label b { color: var(--text); font-variant-numeric: tabular-nums; }
/* จำกัดความสูง — บางข้อได้ 21 แถว ถ้าปล่อยยาวการ์ดจะดันจนหาช่องพิมพ์ไม่เจอ */
.ex-result .table-wrapper {
  max-height: 260px;
  overflow: auto;
}
.ex-result table { font-size: 12.5px; }
.ex-result thead th {
  position: sticky;         /* เลื่อนดูแถวล่างแล้วยังเห็นชื่อคอลัมน์ */
  top: 0;
  background: var(--panel-2);
  z-index: 1;
}

/* ══════════════════════════════════════════
   Exercise explain (อธิบายหลัง pass)
══════════════════════════════════════════ */
.ex-explain {
  margin-top: 10px;
  padding: 10px 14px;
  background: rgba(74,222,128,.07);
  border-left: 3px solid var(--green);
  border-radius: 4px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.7;
}

.ex-explain code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  background: rgba(0,0,0,.25);
  padding: 1px 6px;
  border-radius: 3px;
  color: var(--blue);
}

/* ══════════════════════════════════════════
   แท็บสอบจับเวลา
══════════════════════════════════════════ */
.btn-secondary-soft {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); padding: 7px 16px; font-size: 13px;
}
.btn-secondary-soft:disabled { opacity: .35; cursor: not-allowed; }
.btn-danger-soft {
  background: transparent; color: var(--red);
  border: 1px solid rgba(248,113,113,.45); padding: 7px 16px; font-size: 13px;
}
.btn-danger-soft:hover { background: rgba(248,113,113,.1); }

/* ปุ่มขอต่อเวลา — สีส้ม "ระวัง" ไม่ใช่สีฟ้าชวนกด เพราะมันมีราคา (โดนหักคะแนน) */
.btn-extend {
  background: transparent; color: var(--orange);
  border: 1px solid rgba(251,146,60,.5);
  border-radius: 7px; padding: 7px 14px;
  font-size: 12.5px; font-weight: 600; font-family: inherit;
  cursor: pointer; white-space: nowrap;
}
.btn-extend:hover { background: rgba(251,146,60,.12); }
.btn-extend.hidden { display: none; }

/* ── หน้าก่อนเริ่ม ── */
.exam-intro {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px 18px; margin-bottom: 18px;
}
.exam-rules-title { margin: 0 0 8px; font-size: 13px; font-weight: 700; color: var(--blue); }
.exam-rules { margin: 0; padding-left: 20px; font-size: 13px; line-height: 1.9; color: var(--muted); }
.exam-rules b { color: var(--text); }

.exam-token-input {
  width: 200px;
  background: var(--code-bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 16px; margin-bottom: 4px;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 22px; font-weight: 700;
  letter-spacing: 0.28em; text-align: center; text-transform: uppercase;
}
.exam-token-input:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(56,189,248,.15);
}
.exam-start-btn { display: block; margin-top: 16px; }

/* ── แถบบนระหว่างสอบ ── */
.exam-topbar {
  display: flex; align-items: center; gap: 20px;
  flex-wrap: wrap; margin-bottom: 16px;
  padding-bottom: 14px; border-bottom: 1px solid var(--border);
}
.exam-timer-wrap { display: flex; flex-direction: column; gap: 2px; }
.exam-timer-label { font-size: 11px; color: var(--muted); }
.exam-timer {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 30px; font-weight: 700; line-height: 1;
  color: var(--green); font-variant-numeric: tabular-nums;
}
.exam-timer.warn   { color: var(--orange); }
.exam-timer.danger { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.exam-progress-wrap { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 160px; }
.exam-prog-text {
  font-size: 13px; color: var(--muted); white-space: nowrap;
  font-family: 'JetBrains Mono', monospace;
}
.exam-progress-wrap .progress-track { flex: 1; width: auto; max-width: 260px; }
#exam-progress-fill { height: 100%; background: var(--green); border-radius: 99px; transition: width .35s; }

/* ── ตารางเลขข้อ ── */
.exam-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 6px; margin-bottom: 20px;
}
.exam-cell {
  aspect-ratio: 1; padding: 0;
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  font-family: 'JetBrains Mono', monospace; font-size: 12px; font-weight: 700;
  cursor: pointer; transition: transform .1s;
}
.exam-cell:hover   { transform: translateY(-1px); color: var(--text); }
.exam-cell.tried   { border-color: rgba(251,146,60,.5); color: var(--orange); }
.exam-cell.solved  { background: rgba(74,222,128,.16); border-color: var(--green); color: var(--green); }
.exam-cell.current { box-shadow: 0 0 0 2px var(--blue); border-color: var(--blue); color: var(--blue); }
.exam-cell.solved.current { color: var(--green); }

/* ── ตัวข้อสอบ ── */
.exam-q-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.exam-q-num {
  background: var(--blue); color: #0f172a;
  font-size: 12px; font-weight: 700; padding: 3px 11px; border-radius: 999px;
}
.exam-q-title  { font-size: 15px; font-weight: 600; }
.exam-q-status { font-size: 12px; color: var(--muted); margin-left: auto; }
.exam-q-status.ok { color: var(--green); font-weight: 700; }
.exam-q-desc {
  font-size: 13.5px; color: var(--muted); line-height: 1.75;
  margin: 0 0 12px; white-space: pre-line;
}

.exam-textarea {
  width: 100%; min-height: 110px;
  background: var(--code-bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px;
  font-family: 'JetBrains Mono', Menlo, monospace; font-size: 14px;
  line-height: 1.7; resize: vertical; margin-bottom: 12px;
}
.exam-textarea:focus  { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(56,189,248,.12); }
.exam-textarea:disabled { opacity: .5; cursor: not-allowed; }

.exam-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.exam-feedback { font-size: 13px; font-weight: 600; padding: 6px 13px; border-radius: 6px; }
.exam-feedback.hidden { display: none; }

/* ── หน้าจบ ── */
.exam-result { text-align: center; padding: 24px 12px; }
.exam-result-icon  { font-size: 52px; line-height: 1; margin-bottom: 10px; }
.exam-result-title { margin: 0 0 22px; font-size: 21px; color: var(--text); text-transform: none; letter-spacing: 0; }
.exam-result.win .exam-result-title { color: var(--green); }
.exam-result-stats {
  display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px;
}
.exam-result-stats > div {
  background: var(--code-bg); border-radius: 9px; padding: 13px 24px; min-width: 108px;
}
.exam-result-stats .label { display: block; font-size: 11px; color: var(--muted); }
.exam-result-stats .value {
  display: block; font-size: 22px; font-weight: 700; margin-top: 3px;
  font-family: 'JetBrains Mono', monospace;
}
.exam-result-note { font-size: 13px; color: var(--muted); margin: 0 0 18px; }

/* ── กระดานผู้นำ ── */
#exam-leaderboard .lb-rank { font-size: 15px; }
#exam-leaderboard tr.lb-me { background: rgba(56,189,248,.09); }
#exam-leaderboard tr.lb-me td { color: var(--text); }
.lb-you {
  font-size: 10px; background: var(--blue); color: #0f172a;
  padding: 1px 7px; border-radius: 999px; font-weight: 700;
}
.rate-good { color: var(--green); }

/* ── login: ชั้น / ห้อง / ปี ── */
.login-class-row {
  display: grid; grid-template-columns: 1fr 1fr 1.2fr;
  gap: 10px; margin-top: 12px; text-align: left;
}
.login-select {
  text-align: left; font-size: 15px;
  appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 20px, calc(100% - 11px) 20px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.login-class-row .login-input { margin-bottom: 0; }
.who-badge .who-class {
  font-size: 11px; color: var(--orange);
  background: rgba(251,146,60,.14);
  padding: 1px 7px; border-radius: 3px; margin-left: 6px;
}

/* ── เลือกเดี่ยว / กลุ่ม ── */
.exam-mode-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 420px; }
.exam-mode input { position: absolute; opacity: 0; width: 0; height: 0; }
.exam-mode-box {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--code-bg); border: 1.5px solid var(--border);
  border-radius: 10px; padding: 14px 10px; cursor: pointer; transition: all .15s;
}
.exam-mode-box:hover { border-color: #475569; }
.exam-mode input:checked + .exam-mode-box {
  border-color: var(--blue); background: rgba(56,189,248,.1);
}
.exam-mode-ico  { font-size: 22px; line-height: 1; }
.exam-mode-name { font-size: 14px; font-weight: 700; color: var(--text); }
.exam-mode-sub  { font-size: 11px; color: var(--muted); }

.exam-members {
  margin-top: 14px; padding: 14px 16px;
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 9px;
  max-width: 420px;
}
.exam-members.hidden { display: none; }
.member-row { display: flex; gap: 8px; margin-bottom: 8px; }
.member-input {
  flex: 1; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 12px; font-family: inherit; font-size: 13.5px;
}
.member-input:focus { outline: none; border-color: var(--blue); }
.member-del {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 0 11px; cursor: pointer; font-size: 13px;
}
.member-del:hover { color: var(--red); border-color: var(--red); }

.exam-result-team {
  font-size: 13px; color: var(--blue); margin: 0 0 12px;
  background: rgba(56,189,248,.08); padding: 8px 14px;
  border-radius: 7px; display: inline-block;
}

/* ── แท่นรับรางวัล ── */
.lb-mode-tabs { display: flex; gap: 4px; }
.lb-mode {
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 13px; font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.lb-mode:hover  { color: var(--text); }
.lb-mode.active { color: var(--blue); border-color: var(--blue); background: rgba(56,189,248,.12); }

.podium {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 12px; align-items: end; margin: 8px 0 26px; padding: 0 4px;
}
.podium.hidden { display: none; }
.pod { text-align: center; display: flex; flex-direction: column; align-items: center; }
.pod-medal { font-size: 30px; line-height: 1; margin-bottom: 4px; }
.pod-name  { font-size: 13.5px; font-weight: 700; color: var(--text); line-height: 1.35; }
.pod-meta  { font-size: 11px; color: var(--muted); margin-top: 2px; min-height: 14px; }
.pod-team  { color: var(--blue); }
.pod-time  {
  font-family: 'JetBrains Mono', monospace; font-size: 16px; font-weight: 700;
  margin: 5px 0 7px; color: var(--text);
}
.pod-stand {
  width: 100%; border-radius: 8px 8px 0 0;
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 7px; font-weight: 800;
}
.pod-rank { font-size: 19px; color: rgba(15,23,42,.55); }

/* ที่ 1 สูงสุด สีทอง · ที่ 2 เงิน · ที่ 3 ทองแดง */
.pod-1 .pod-stand { height: 84px; background: linear-gradient(180deg,#fbbf24,#d97706); }
.pod-2 .pod-stand { height: 60px; background: linear-gradient(180deg,#cbd5e1,#94a3b8); }
.pod-3 .pod-stand { height: 44px; background: linear-gradient(180deg,#d8a26a,#a16207); }
.pod-1 .pod-medal { font-size: 40px; }
.pod-1 .pod-name  { font-size: 15px; color: #fbbf24; }
.pod-me .pod-name { text-decoration: underline; text-underline-offset: 3px; }

/* ── ตารางอันดับ ── */
#exam-leaderboard tr.lb-top1 td { background: rgba(251,191,36,.09); }
#exam-leaderboard tr.lb-top2 td { background: rgba(203,213,225,.07); }
#exam-leaderboard tr.lb-top3 td { background: rgba(216,162,106,.08); }
.lb-team {
  font-size: 10.5px; color: var(--blue);
  background: rgba(56,189,248,.13); padding: 1px 7px; border-radius: 999px;
}
.lb-members { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ══════════════════════════════════════════
   Responsive
══════════════════════════════════════════ */
@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; }
  .log-section { position: static; }
  ul#log { max-height: 260px; }
  .main-tab { padding: 11px 14px; font-size: 13px; }
  /* บนหน้าจอแคบ ก็ยังซ่อน log ใน view tab อยู่ */
}
