:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --border: #dde3ec;
  --text: #1d2433;
  --muted: #6b7489;
  --accent: #0b7285;
  --accent-ink: #ffffff;
  --warn-bg: #fff4e5;
  --warn-ink: #8a4b00;
  --code-bg: #1f232b;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { height: 38px; width: auto; display: block; flex: none; }
.title { font-weight: 600; font-size: 17px; line-height: 1.1; }
.subtitle { font-size: 12px; color: var(--muted); }
.actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }
button, select, input {
  font: inherit; font-size: 14px; color: var(--text);
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; padding: 6px 11px; cursor: pointer;
}
input { cursor: text; }
button:hover, select:hover { border-color: #b7c2d3; background: #f8fafc; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover { background: #095c6b; }
button:disabled { opacity: .5; cursor: default; }

/* ---------- layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.workspace { flex: 1 1 60%; position: relative; min-width: 300px; }
#blocklyDiv { position: absolute; inset: 0; }
.splitter { width: 6px; cursor: col-resize; background: var(--border); flex: none; }
.splitter:hover, .splitter.drag { background: var(--accent); }
.panel {
  flex: 0 0 38%; min-width: 280px; display: flex; flex-direction: column;
  background: var(--code-bg); color: #e6e6e6;
}
.tabs { display: flex; background: #171a20; }
.tab {
  flex: 1; border: 0; border-radius: 0; background: transparent; color: #a9b1c2; padding: 10px;
  border-bottom: 2px solid transparent;
}
.tab:hover { background: #22262e; color: #fff; }
.tab.active { color: #fff; border-bottom-color: #3bc9db; }
.tabpane { display: none; flex: 1; min-height: 0; flex-direction: column; }
.tabpane.active { display: flex; }

.code { margin: 0; flex: 1; overflow: auto; padding: 0; }
.code code {
  display: block; padding: 14px 16px; min-height: 100%;
  font-family: 'JetBrains Mono', Consolas, monospace; font-size: 13px; line-height: 1.55;
  background: transparent !important; white-space: pre;
}
.warnings, .libs { font-size: 13px; padding: 8px 14px; line-height: 1.5; }
.warnings { background: var(--warn-bg); color: var(--warn-ink); }
.warnings div::before { content: '⚠ '; }
.libs { background: #243040; color: #cfe3ff; }
.libs b { color: #fff; }
.libs code { background: #33445a; padding: 1px 6px; border-radius: 5px; font-size: 12px; }

/* ---------- serial ---------- */
.serial-bar, .serial-send { display: flex; gap: 6px; padding: 8px; background: #171a20; flex-wrap: wrap; align-items: center; }
.serial-bar select, .serial-bar button, .serial-send input, .serial-send select, .serial-send button {
  background: #2a2f39; color: #e6e6e6; border-color: #3a404c;
}
.serial-bar button.primary { background: var(--accent); border-color: var(--accent); }
.serial-bar button.connected { background: #c92a2a; border-color: #c92a2a; }
.chk { font-size: 13px; color: #a9b1c2; display: flex; align-items: center; gap: 4px; }
.chk input { width: auto; }
.serial-out {
  flex: 1; margin: 0; overflow: auto; padding: 12px 14px; white-space: pre-wrap; word-break: break-all;
  font-family: 'JetBrains Mono', Consolas, monospace; font-size: 13px; line-height: 1.45; color: #b2f2bb;
}
.serial-send input { flex: 1; min-width: 120px; }

/* ---------- dialog / toast ---------- */
dialog {
  border: 0; border-radius: 14px; padding: 22px 26px; max-width: 560px; width: calc(100% - 32px);
  box-shadow: 0 20px 60px rgba(0,0,0,.3); color: var(--text); background: var(--surface);
}
dialog::backdrop { background: rgba(15, 20, 30, .45); }
dialog h2 { margin-top: 0; font-size: 19px; }
dialog li { margin-bottom: 6px; line-height: 1.55; }
.muted { color: var(--muted); font-size: 13px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1d2433; color: #fff; padding: 9px 18px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); z-index: 100;
}

/* board picker */
.board-pick {
  display: flex; align-items: center; gap: 6px; margin-left: 10px;
  padding: 3px 4px 3px 10px; border-radius: 10px; background: #e3f4f6; border: 1px solid #b6e0e6;
}
.board-pick span { font-size: 13px; font-weight: 600; color: var(--accent); }
.board-pick select { font-weight: 600; border-color: #b6e0e6; }
.warnings .fix { margin-top: 6px; font-size: 13px; padding: 4px 10px; background: #fff; border-color: #f0c48a; color: var(--warn-ink); }
.warnings .fix::before, .warnings .fixrow::before { content: none; }

.proj-name { width: 120px; }
dialog.small { max-width: 400px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* pin map dialog */
dialog.wide { max-width: 820px; }
.pin-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; font-size: 13px; }
.pin-meta span { background: #eef3f8; border-radius: 999px; padding: 3px 10px; }
.pin-table-wrap { max-height: 50vh; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.pin-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.pin-table th, .pin-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: center; }
.pin-table th { position: sticky; top: 0; background: #f4f6fa; font-weight: 600; }
.pin-table td:first-child, .pin-table th:first-child { text-align: left; white-space: nowrap; }
.pin-table td.note { text-align: left; color: var(--muted); }
.yes { color: #2b8a3e; font-weight: 700; }
.no { color: #ced4da; }
.pin-notes { font-size: 13px; line-height: 1.6; padding-left: 20px; }

/* Blockly tweaks */
.blocklyToolboxDiv { background: #eef1f6 !important; font-family: 'IBM Plex Sans Thai', sans-serif; }
.blocklyTreeLabel { font-family: 'IBM Plex Sans Thai', sans-serif !important; font-size: 14px !important; }
.blocklyText, .blocklyHtmlInput { font-family: 'IBM Plex Sans Thai', sans-serif !important; }

@media (max-width: 860px) {
  body { overflow: auto; }
  .layout { flex-direction: column; }
  .workspace { flex: none; height: 65vh; min-width: 0; }
  .splitter { display: none; }
  .panel { flex: none; height: 60vh; min-width: 0; }
  .subtitle { display: none; }
}
