/* =========================================================
   เครื่องจำลองรถเฮี๊ยบ 3D - ธีมอุตสาหกรรมโทนมืด
   ========================================================= */
:root {
  --bg: #0b0f14;
  --bg2: #111821;
  --panel: #151d28;
  --panel2: #1b2533;
  --line: #263346;
  --line2: #33445c;
  --text: #e6edf5;
  --muted: #8ea0b6;
  --accent: #ffb020;
  --accent2: #ff8a00;
  --ok: #3ddc97;
  --warn: #ffc542;
  --danger: #ff4d6d;
  --info: #4aa3ff;
  --glass: rgba(14, 20, 29, 0.72);
  --glass-line: rgba(255, 255, 255, 0.09);
  --radius: 12px;
  --font: 'Sarabun', 'Noto Sans Thai', 'Leelawadee UI', 'Tahoma', sans-serif;
  --mono: 'JetBrains Mono', 'Consolas', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 70% -10%, #1a2534 0%, var(--bg) 60%);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
kbd {
  font-family: var(--mono); font-size: 10px; padding: 1px 5px; border-radius: 4px;
  background: #0b1118; border: 1px solid var(--line2); color: var(--muted); margin-left: 4px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- แถบหัวเรื่อง ---------- */
.topbar {
  height: 58px; display: flex; align-items: center; gap: 24px; padding: 0 18px;
  background: linear-gradient(180deg, #121a25, #0e141c);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 20;
}
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: repeating-linear-gradient(135deg, var(--accent) 0 12px, #111 12px 24px); opacity: .55;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 260px; }
.brand-icon { width: 38px; height: 38px; color: var(--accent); }
.brand-icon svg { width: 100%; height: 100%; }
.brand-title { font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.main-nav { display: flex; gap: 6px; flex: 1; }
.nav-btn {
  background: transparent; border: 1px solid transparent; padding: 8px 16px; border-radius: 8px;
  color: var(--muted); cursor: pointer; font-weight: 600; transition: all .2s;
}
.nav-btn:hover { color: var(--text); background: rgba(255,255,255,.04); }
.nav-btn.active { color: #111; background: var(--accent); }
.topbar-right { display: flex; gap: 8px; }
.icon-btn {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px;
  cursor: pointer; transition: all .2s;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.on { border-color: var(--ok); color: var(--ok); }

main { height: calc(100vh - 58px); position: relative; }
.page { display: none; height: 100%; }
.page.active { display: block; }

/* ---------- ผังเครื่องจำลอง ---------- */
.sim-layout { display: grid; grid-template-columns: 1fr 420px; height: 100%; }
.viewport-wrap { position: relative; overflow: hidden; background: #0d141c; }
#viewport { position: absolute; inset: 0; }
#viewport canvas { display: block; }

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-line);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.hud { position: absolute; z-index: 5; padding: 12px 14px; }
.hud-tl { top: 12px; left: 12px; width: 300px; }
.hud-tr { top: 12px; right: 12px; width: 260px; }
.hud-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent); font-weight: 700; margin-bottom: 8px; }
.hud-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.hud-item { display: flex; flex-direction: column; }
.hud-item span { font-size: 11px; color: var(--muted); }
.hud-item b { font-family: var(--mono); font-size: 15px; }
.hud-rows > div { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px dashed rgba(255,255,255,.06); font-size: 12px; }
.hud-rows span { color: var(--muted); }
.hud-rows b { font-family: var(--mono); font-size: 12.5px; text-align: right; }

.status-badge {
  text-align: center; font-weight: 700; padding: 6px 10px; border-radius: 8px; letter-spacing: .3px;
  background: rgba(61,220,151,.15); color: var(--ok); border: 1px solid rgba(61,220,151,.4);
  transition: all .25s;
}
.status-badge.warn { background: rgba(255,197,66,.15); color: var(--warn); border-color: rgba(255,197,66,.45); }
.status-badge.danger { background: rgba(255,77,109,.2); color: #ff8fa3; border-color: var(--danger); animation: pulse .6s infinite alternate; }
.status-badge.tip { background: var(--danger); color: #fff; border-color: #fff; animation: pulse .3s infinite alternate; }
@keyframes pulse { from { box-shadow: 0 0 0 rgba(255,77,109,0); } to { box-shadow: 0 0 18px rgba(255,77,109,.7); } }

.gauge-wrap { position: relative; height: 120px; margin: 6px 0 4px; }
.gauge-wrap canvas { width: 100%; height: 120px; }
.gauge-label { position: absolute; left: 0; right: 0; bottom: 4px; text-align: center; }
.gauge-label b { font-family: var(--mono); font-size: 26px; display: block; line-height: 1; }
.gauge-label span { font-size: 11px; color: var(--muted); }

.alert-stack { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 6; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; max-width: 46%; }
.alert {
  padding: 7px 14px; border-radius: 8px; font-weight: 600; font-size: 13px; text-align: center;
  background: rgba(20,26,36,.88); border: 1px solid var(--line2); backdrop-filter: blur(8px);
  animation: slideIn .25s ease;
}
.alert.warn { border-color: var(--warn); color: var(--warn); }
.alert.danger { border-color: var(--danger); color: #ff8fa3; background: rgba(60,10,20,.85); }
.alert.info { border-color: var(--info); color: #9fd0ff; }
.alert.ok { border-color: var(--ok); color: var(--ok); }
@keyframes slideIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.cam-bar { position: absolute; left: 12px; bottom: 12px; z-index: 5; padding: 6px; display: flex; gap: 4px; flex-wrap: wrap; max-width: 300px; }
.chip {
  background: rgba(255,255,255,.05); border: 1px solid var(--glass-line); padding: 4px 10px;
  border-radius: 999px; cursor: pointer; font-size: 12px; transition: all .2s;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); color: #111; border-color: var(--accent); }

.joy {
  position: absolute; right: 12px; bottom: 12px; z-index: 5; padding: 10px; display: grid;
  grid-template-columns: repeat(4, auto); gap: 8px 10px; align-items: end;
}
.joy-group { display: flex; flex-direction: column; gap: 4px; }
.joy-group > span { font-size: 11px; color: var(--muted); text-align: center; }
.hold {
  background: linear-gradient(180deg, #243145, #1a2433); border: 1px solid var(--line2); border-radius: 8px;
  padding: 7px 10px; cursor: pointer; font-weight: 600; font-size: 12px; user-select: none; touch-action: none;
  transition: background .1s, border-color .1s;
}
.hold:hover { border-color: var(--accent); }
.hold.pressed { background: var(--accent); color: #111; border-color: var(--accent); }
.fine { grid-column: 1 / -1; font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

.mission-hud { left: 12px; top: 300px; width: 300px; border-color: rgba(255,176,32,.35); }
.mh-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.mh-head b { font-size: 13px; line-height: 1.3; }
.mh-tag { background: var(--accent); color: #111; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; flex-shrink: 0; }
.mh-steps { list-style: none; margin: 0 0 8px; padding: 0; font-size: 12.5px; }
.mh-steps li { padding: 3px 0 3px 22px; position: relative; color: var(--muted); }
.mh-steps li::before { content: '○'; position: absolute; left: 4px; color: var(--muted); }
.mh-steps li.done { color: var(--text); }
.mh-steps li.done::before { content: '✔'; color: var(--ok); }
.mh-steps li.bad { color: #ff8fa3; }
.mh-steps li.bad::before { content: '✖'; color: var(--danger); }
.mh-stats { font-size: 12px; font-family: var(--mono); color: var(--muted); margin-bottom: 8px; }
.mh-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.overlay-msg { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; background: rgba(40,0,10,.35); }
.card-danger { padding: 22px 28px; max-width: 520px; border-color: var(--danger); text-align: center; }
.card-danger h2 { color: var(--danger); margin: 0 0 8px; font-size: 26px; }

.loading { position: absolute; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--muted); }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- แถบด้านข้าง ---------- */
.sidebar { background: var(--bg2); border-left: 1px solid var(--line); overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.sidebar::-webkit-scrollbar, .chart-wrap::-webkit-scrollbar, .manual-body::-webkit-scrollbar, .manual-toc::-webkit-scrollbar, .modal-box::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb, .chart-wrap::-webkit-scrollbar-thumb, .manual-body::-webkit-scrollbar-thumb, .manual-toc::-webkit-scrollbar-thumb, .modal-box::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 4px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card h3 { margin: 0; font-size: 14px; color: var(--accent); }
.card h4 { margin: 4px 0 8px; font-size: 13px; color: var(--muted); }
.mini-toggle { font-size: 12px; color: var(--muted); display: flex; gap: 4px; align-items: center; cursor: pointer; }

.boom-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 8px; }
.boom-tabs button {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 0; cursor: pointer;
  font-family: var(--mono); font-size: 12px; transition: all .2s;
}
.boom-tabs button.active { border-color: var(--accent); color: var(--accent); background: rgba(255,176,32,.1); }
.boom-tabs button.live::after { content: ' ●'; color: var(--ok); }

.chart-wrap { max-height: 300px; overflow-y: auto; border-radius: 8px; border: 1px solid var(--line); }
.load-chart { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12px; }
.load-chart th { position: sticky; top: 0; background: #1d2938; color: var(--muted); font-weight: 600; padding: 6px 4px; font-family: var(--font); font-size: 11px; line-height: 1.25; z-index: 1; }
.load-chart th.col-active { color: #111; background: var(--accent); }
.load-chart td { text-align: center; padding: 5px 4px; border-top: 1px solid var(--line); transition: background .2s, color .2s; }
.load-chart tr.row-active td { background: rgba(255,176,32,.12); }
.load-chart td.col-active { background: rgba(255,176,32,.08); }
.load-chart td.cell-active { background: var(--accent) !important; color: #111; font-weight: 700; box-shadow: inset 0 0 0 2px #fff; }
.load-chart td.cell-active.over { background: var(--danger) !important; color: #fff; }
.load-chart td.insufficient { color: #ff8fa3; }
.load-chart td.na { color: #4d5d72; }
.chart-note { margin-top: 8px; font-size: 12px; color: var(--muted); line-height: 1.45; }
.chart-note b { color: var(--text); }

.side-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.side-tab { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 4px; cursor: pointer; font-weight: 600; font-size: 12.5px; color: var(--muted); transition: all .2s; }
.side-tab.active { color: var(--accent); border-color: var(--accent); }
.side-panel { display: none; }
.side-panel.active { display: block; }

.ctrl { margin-bottom: 12px; }
.ctrl > label { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.ctrl > label b { color: var(--text); font-family: var(--mono); }
.ctrl.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ctrl.two label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=number], input[type=text], input[type=search], select {
  width: 100%; background: #0e151e; border: 1px solid var(--line2); border-radius: 7px; padding: 6px 8px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.snap-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 6px; }
.snap-row button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; font-family: var(--mono); font-size: 11.5px; padding: 3px 0; cursor: pointer; }
.snap-row button:hover { border-color: var(--accent); }

.outrig-grid { display: grid; grid-template-columns: 34px 1fr; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line2); border-radius: 7px; overflow: hidden; }
.seg button { background: transparent; border: none; border-right: 1px solid var(--line2); padding: 5px 2px; cursor: pointer; font-size: 11.5px; transition: all .2s; }
.seg button:last-child { border-right: none; }
.seg button.active { background: var(--accent); color: #111; font-weight: 700; }
.seg button:disabled { opacity: .3; cursor: not-allowed; text-decoration: line-through; }

.toggles { display: flex; flex-direction: column; gap: 7px; margin: 6px 0 12px; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 12.5px; cursor: pointer; }
.switch input { display: none; }
.switch span { width: 34px; height: 18px; border-radius: 10px; background: #2a3647; position: relative; flex-shrink: 0; transition: background .2s; }
.switch span::after { content: ''; position: absolute; width: 14px; height: 14px; border-radius: 50%; background: #cfd8e3; top: 2px; left: 2px; transition: left .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { left: 18px; }
.switch input:disabled + span { opacity: .4; }

.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  background: var(--panel2); border: 1px solid var(--line2); border-radius: 8px; padding: 7px 14px; cursor: pointer;
  font-weight: 600; transition: all .2s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: linear-gradient(180deg, var(--accent), var(--accent2)); color: #111; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }

#rangeCanvas, #topCanvas { width: 100%; background: #0c121a; border-radius: 8px; border: 1px solid var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 11.5px; color: var(--muted); margin: 6px 0 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

.formula { margin-top: 12px; padding: 10px; border-radius: 8px; background: #0e151e; border: 1px dashed var(--line2); font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.formula b { color: var(--accent); }

/* ---------- หน้าภารกิจ / แบบทดสอบ ---------- */
.page-inner { height: 100%; overflow-y: auto; padding: 28px 40px; }
.page-inner.narrow { max-width: 900px; margin: 0 auto; }
.page-head h1 { margin: 0 0 6px; font-size: 26px; }
.page-head p { margin: 0 0 22px; color: var(--muted); }
.mission-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.mission-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: flex; flex-direction: column; gap: 10px; transition: transform .2s, border-color .2s; position: relative; overflow: hidden; }
.mission-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.mission-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); }
.mission-card .mc-id { font-family: var(--mono); color: var(--accent); font-size: 12px; }
.mission-card h3 { margin: 0; font-size: 16px; line-height: 1.35; }
.mission-card p { margin: 0; color: var(--muted); font-size: 13px; }
.diff { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 6px; border: 1px solid; width: fit-content; }
.diff.d1 { color: var(--ok); border-color: var(--ok); }
.diff.d2 { color: var(--info); border-color: var(--info); }
.diff.d3 { color: var(--warn); border-color: var(--warn); }
.diff.d4 { color: var(--danger); border-color: var(--danger); }
.mc-result { font-size: 12.5px; font-weight: 600; }
.mc-result.pass { color: var(--ok); }
.mc-result.fail { color: var(--danger); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.kv div { background: #0e151e; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.kv span { display: block; font-size: 11px; color: var(--muted); }
.kv b { font-family: var(--mono); font-size: 13.5px; }

.quiz-progress { height: 6px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin-bottom: 14px; }
.qp-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--ok)); transition: width .4s; }
.quiz-card { padding: 24px; }
.quiz-card h2 { margin: 0 0 16px; font-size: 19px; line-height: 1.45; }
.q-num { color: var(--accent); font-family: var(--mono); font-size: 13px; margin-bottom: 6px; }
.q-opts { display: flex; flex-direction: column; gap: 10px; }
.q-opt {
  text-align: left; background: var(--panel2); border: 1px solid var(--line2); border-radius: 10px; padding: 12px 14px;
  cursor: pointer; display: flex; gap: 12px; align-items: flex-start; transition: all .2s; line-height: 1.5;
}
.q-opt:hover:not(:disabled) { border-color: var(--accent); }
.q-opt .k { flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%; background: #0e151e; border: 1px solid var(--line2); display: flex; align-items: center; justify-content: center; font-weight: 700; }
.q-opt.correct { border-color: var(--ok); background: rgba(61,220,151,.1); }
.q-opt.correct .k { background: var(--ok); color: #111; }
.q-opt.wrong { border-color: var(--danger); background: rgba(255,77,109,.1); }
.q-opt.wrong .k { background: var(--danger); color: #fff; }
.q-opt:disabled { cursor: default; }
.q-exp { margin-top: 16px; padding: 14px; border-radius: 10px; background: #0e151e; border-left: 4px solid var(--info); line-height: 1.65; animation: slideIn .3s; }
.q-exp.good { border-left-color: var(--ok); }
.q-exp.bad { border-left-color: var(--danger); }
.q-foot { display: flex; justify-content: flex-end; margin-top: 16px; gap: 8px; }
.score-big { font-size: 56px; font-family: var(--mono); font-weight: 700; text-align: center; color: var(--accent); }
.review-item { padding: 10px 12px; border-radius: 8px; background: #0e151e; border: 1px solid var(--line); margin-bottom: 8px; font-size: 13px; }
.review-item.ok { border-left: 4px solid var(--ok); }
.review-item.no { border-left: 4px solid var(--danger); }

/* ---------- หน้าคู่มือ ---------- */
.manual-layout { display: grid; grid-template-columns: 300px 1fr; gap: 14px; padding: 14px; height: 100%; }
.manual-toc { overflow-y: auto; }
.manual-toc input { margin: 8px 0 10px; }
.manual-toc nav a { display: block; color: var(--muted); text-decoration: none; padding: 4px 8px; border-radius: 6px; font-size: 13px; line-height: 1.4; }
.manual-toc nav a:hover { background: var(--panel2); color: var(--text); }
.manual-toc nav a.h2 { color: var(--text); font-weight: 600; margin-top: 6px; }
.manual-toc nav a.h3 { padding-left: 20px; font-size: 12.5px; }
.manual-toc nav a.active { color: var(--accent); background: rgba(255,176,32,.08); }
.manual-body { overflow-y: auto; padding: 26px 40px; font-size: 15.5px; line-height: 1.8; }
.manual-body h1 { font-size: 26px; color: var(--accent); border-bottom: 2px solid var(--line); padding-bottom: 10px; line-height: 1.4; }
.manual-body h2 { font-size: 22px; margin-top: 34px; padding: 8px 12px; background: linear-gradient(90deg, rgba(255,176,32,.14), transparent); border-left: 4px solid var(--accent); border-radius: 4px; }
.manual-body h3 { font-size: 18px; margin-top: 24px; color: #ffd27a; }
.manual-body h4 { font-size: 16px; margin-top: 18px; color: var(--info); }
.manual-body p { margin: 10px 0; }
.manual-body strong { color: #fff; }
.manual-body code { font-family: var(--mono); background: #0e151e; padding: 1px 6px; border-radius: 4px; font-size: 13px; }
.manual-body pre { background: #0a0f15; border: 1px solid var(--line); border-radius: 10px; padding: 14px; overflow-x: auto; font-size: 13px; line-height: 1.45; }
.manual-body pre code { background: none; padding: 0; font-family: 'Sarabun', var(--mono), monospace; white-space: pre; }
.manual-body table { border-collapse: collapse; margin: 12px 0; width: 100%; font-size: 14px; }
.manual-body th, .manual-body td { border: 1px solid var(--line2); padding: 6px 10px; }
.manual-body th { background: #1d2938; }
.manual-body tr:nth-child(even) td { background: rgba(255,255,255,.02); }
.manual-body blockquote { margin: 12px 0; padding: 10px 16px; border-left: 4px solid var(--info); background: rgba(74,163,255,.07); border-radius: 4px; }
.manual-body hr { border: none; border-top: 1px solid var(--line); margin: 24px 0; }
.manual-body mark { background: rgba(255,176,32,.4); color: #fff; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(4,7,11,.7); display: flex; align-items: center; justify-content: center; padding: 20px; animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box { position: relative; width: min(920px, 100%); max-height: 92vh; overflow-y: auto; padding: 26px 30px; background: rgba(17,24,33,.96); }
.modal-box.small { width: min(600px, 100%); }
.modal-box h2 { margin: 0 0 10px; font-size: 21px; line-height: 1.4; }
.modal-box h3 { color: var(--accent); font-size: 15px; margin: 18px 0 8px; }
.modal-box p { line-height: 1.7; }
.modal-close { position: absolute; top: 12px; right: 14px; background: transparent; border: none; font-size: 20px; color: var(--muted); cursor: pointer; }
.modal-close:hover { color: var(--text); }
.steps-ind { display: flex; gap: 6px; margin-bottom: 14px; }
.steps-ind span { flex: 1; text-align: center; font-size: 12px; padding: 5px; border-radius: 6px; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.steps-ind span.on { background: rgba(255,176,32,.15); color: var(--accent); border-color: var(--accent); }
.challenge { padding: 12px 14px; border-radius: 10px; background: rgba(255,197,66,.07); border: 1px solid rgba(255,197,66,.3); line-height: 1.7; }
.opt-list { display: flex; flex-direction: column; gap: 10px; }
.opt-list .q-opt { width: 100%; }
.result-banner { padding: 16px; border-radius: 12px; text-align: center; margin-bottom: 14px; }
.result-banner.pass { background: rgba(61,220,151,.12); border: 1px solid var(--ok); }
.result-banner.fail { background: rgba(255,77,109,.12); border: 1px solid var(--danger); }
.result-banner h2 { margin: 0; }
.result-banner .score { font-family: var(--mono); font-size: 40px; font-weight: 700; }
.fb-list { margin: 0; padding-left: 20px; line-height: 1.8; }
.fb-list li.good { color: var(--ok); }
.fb-list li.bad { color: #ff8fa3; }
.fb-list li.warn { color: var(--warn); }
table.keys { width: 100%; border-collapse: collapse; }
table.keys td { padding: 7px 6px; border-bottom: 1px solid var(--line); }
table.keys td:first-child { white-space: nowrap; width: 46%; }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .sim-layout { grid-template-columns: 1fr 360px; }
  .hud-tl { width: 260px; }
  .hud-tr { width: 230px; }
  .joy { grid-template-columns: repeat(2, auto); }
  .mission-hud { top: 290px; width: 260px; }
}
@media (max-width: 980px) {
  body { overflow: auto; }
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .brand { min-width: 0; }
  main { height: auto; }
  .sim-layout { grid-template-columns: 1fr; height: auto; }
  .viewport-wrap { height: 70vh; }
  .sidebar { border-left: none; }
  .hud-tl { width: 220px; font-size: 12px; }
  .hud-tl .hud-grid { grid-template-columns: 1fr; }
  .hud-tr { width: 200px; }
  .joy { left: 12px; right: 12px; bottom: 54px; grid-template-columns: repeat(4, 1fr); }
  .cam-bar { max-width: none; right: 12px; }
  .mission-hud { position: relative; left: auto; top: auto; width: auto; margin: 8px; }
  .manual-layout { grid-template-columns: 1fr; height: auto; }
  .manual-toc { max-height: 240px; }
  .page-inner { padding: 18px; }
}

/* ---------- Mobile (<=768px): canvas ไม่ถูกบัง, ปุ่มควบคุมอยู่ใต้ canvas ---------- */
@media (max-width: 768px) {
  .topbar { padding: 6px 10px; gap: 6px; }
  .topbar-right span { display: none; }
  .main-nav { overflow-x: auto; flex: 1 1 100%; order: 3; -webkit-overflow-scrolling: touch; }
  .nav-btn { white-space: nowrap; padding: 8px 12px; }
  .viewport-wrap { height: auto; display: flex; flex-direction: column; overflow: visible; background: var(--bg); }
  #viewport { position: relative; inset: auto; order: 0; height: 46vh; height: 46svh; min-height: 260px; background: #0d141c; touch-action: none; }
  #viewport canvas { touch-action: none; width: 100% !important; height: 100% !important; }
  .loading, .overlay-msg { bottom: auto; height: 46vh; height: 46svh; min-height: 260px; }
  .hud, .joy, .cam-bar { position: static; width: auto; max-width: none; margin: 8px 10px 0; }
  .joy { order: 1; grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 8px; }
  .joy-group { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .joy-group > span { grid-column: 1 / -1; }
  .hold { min-height: 48px; font-size: 13px; padding: 6px 4px; -webkit-tap-highlight-color: transparent; }
  .hold kbd, .joy kbd, .fine kbd { display: none; }
  .fine { grid-column: 1 / -1; }
  .cam-bar { order: 2; justify-content: center; }
  .chip { min-height: 38px; }
  .hud-tr { order: 3; }
  .hud-tl { order: 4; }
  .hud-tl .hud-grid { grid-template-columns: 1fr 1fr; }
  .mission-hud { order: 5; }
  .gauge-wrap { height: 100px; }
  .gauge-wrap canvas { height: 100px; }
}
