/* Themes: "tea" (default, Thai-tea orange on light) and "arduino" (dark), chosen with data-theme on <html>
   by the head script in index.html and the theme menu. Accent shades a50…a900 follow the Tailwind scale. */
:root {
  --a50: #fff1e6; --a200: #fed7aa; --a300: #fdba74; --a500: #f97316;
  --a600: #ea580c; --a700: #c2410c; --a800: #9a3412; --a900: #7c2d12;
  --accent-2: #d97706;

  --bg: #f8fafc;
  --panel: #ffffff;
  --field: #ffffff;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --text: #1e293b;
  --muted: #64748b;
  --header: #0f172a;
  --track: #f1f5f9;
  --led-off: #d1d5db;
  --view-bg: #f5eee3;
  --warm: #fffbf5;
  --dark: #0f172a;
  --console: #0f172a;
  --console-field: #1e293b;
  --console-line: #334155;
  --ok: #16a34a;
  --err: #dc2626;

  --accent: var(--a600);
  --accent-hover: var(--a700);
  --accent-soft: var(--a50);
  --accent-line: var(--a200);
  --accent-ink: var(--a800);
  --tab-on: var(--a900);

  --cm-bg: #fffdf9; --cm-gutter: #fdf6ec; --cm-gutter-line: #f3e3cc; --cm-lineno: #c2a37c;
  --cm-keyword: var(--a700); --cm-meta: #7c3aed; --cm-string: #0f766e; --cm-number: #b45309;
  --cm-comment: #94a3b8; --cm-type: #0369a1; --cm-error: #fee2e2; --cm-select: #e2e8f0;
  --toast-bg: rgba(255, 255, 255, .42); --toast-edge: rgba(255, 255, 255, .7); --toast-text: #0b0b0f; --toast-sub: rgba(11, 11, 15, .55);

  --radius: 12px;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  color-scheme: light;
}
:root[data-theme=arduino] {
  /* dark, like the Arduino IDE 2 dark theme: charcoal panels with Arduino teal */
  --a50: #12393b; --a200: #1f5f62; --a300: #5fc6ca; --a500: #00a5ab;
  --a600: #00979d; --a700: #00878c; --a800: #006d71; --a900: #005c5f;
  --accent-2: #00979d;

  --bg: #171e21;
  --panel: #1f272a;
  --field: #171e21;
  --line: #2f3a3e;
  --line-strong: #44525a;
  --text: #dae3e3;
  --muted: #8a9a9e;
  --header: #12181a;
  --track: #2a3337;
  --led-off: #4b5a60;
  --view-bg: #232c30;
  --warm: #1a2225;
  --console: #12181a;
  --console-field: #1f272a;
  --console-line: #2f3a3e;

  --accent-soft: #163a3c;
  --accent-line: #24585b;
  --accent-ink: #7fd3d6;
  --tab-on: #00878c;

  --cm-bg: #1b2326; --cm-gutter: #1f272a; --cm-gutter-line: #2f3a3e; --cm-lineno: #5e6e73;
  --cm-keyword: #0ca1a6; --cm-meta: #c99ae6; --cm-string: #7fcbcd; --cm-number: #f39c12;
  --cm-comment: #7f8c8d; --cm-type: #f1c40f; --cm-error: rgba(220, 38, 38, .28); --cm-select: #2f3d42;
  --toast-bg: rgba(40, 40, 44, .38); --toast-edge: rgba(255, 255, 255, .18); --toast-text: #f5f5f7; --toast-sub: rgba(245, 245, 247, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Chakra Petch', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grow { flex: 1; }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px; background: var(--header); color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; min-width: 0; }
.brand img { height: 30px; width: auto; display: block; }
.brand span { display: flex; flex-direction: column; line-height: 1.2; }
.brand strong { font-size: 15px; font-weight: 700; letter-spacing: .2px; }
.brand small { color: #fbbf24; font-size: 12.5px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.pill { font-size: 12.5px; padding: 4px 10px; border-radius: 999px; background: #1e293b; color: #cbd5e1; }
.pill.on { background: #14532d; color: #bbf7d0; }

/* TH / EN switch: the current language is highlighted */
.lang-toggle {
  display: flex; padding: 3px; gap: 2px; border-radius: 999px; border: 1px solid #334155; background: transparent; cursor: pointer;
}
.lang-toggle span { padding: 3px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 700; color: #94a3b8; letter-spacing: .3px; }
:root[lang=th] .lang-toggle [data-lang=th], :root[lang=en] .lang-toggle [data-lang=en] { background: #fbbf24; color: #0f172a; }
.lang-toggle:hover { border-color: #fbbf24; }
.lang-toggle:focus-visible { outline: 2px solid #fbbf24; outline-offset: 2px; }

/* light / dark toggle: shows the moon in the light theme and the sun in the dark one */
.theme-toggle {
  width: 36px; height: 36px; display: grid; place-items: center; padding: 0; border-radius: 50%; cursor: pointer;
  border: 1px solid #334155; background: transparent; color: #e2e8f0;
}
.theme-toggle:hover { border-color: #fbbf24; color: #fbbf24; }
.theme-toggle:focus-visible { outline: 2px solid #fbbf24; outline-offset: 2px; }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .ic-moon { fill: currentColor; }
.theme-toggle .ic-sun { fill: currentColor; stroke: currentColor; stroke-width: 2; stroke-linecap: round; display: none; }
:root[data-theme=arduino] .theme-toggle .ic-moon { display: none; }
:root[data-theme=arduino] .theme-toggle .ic-sun { display: block; }

/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 6px 14px; cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 10px; font-size: 12.5px; }
.pill-btn { background: var(--panel); }
.pill-btn.accent { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-ink); }
.btn:focus-visible, .icon-btn:focus-visible, [role=tab]:focus-visible, .ok-btn:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* toolbar */
.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.toolbar .sep { width: 1px; height: 22px; background: var(--line); }
.board-label { font-size: 14px; }
.board-label small { color: var(--muted); }
.toolbar select { border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; background: var(--field); }

/* layout */
.layout {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 12px;
  padding: 12px 16px 16px; min-height: 0;
}
.editor-pane, .card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, .04);
}
.editor-pane { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.mode-bar { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.mode-tabs, .view-tabs { display: flex; gap: 4px; align-items: center; }
[role=tab] {
  border: 0; background: transparent; padding: 5px 14px; border-radius: 999px; cursor: pointer;
  font-weight: 600; font-size: 13.5px; color: var(--muted);
}
[role=tab][aria-selected=true] { background: var(--tab-on); color: #fff; }
[role=tab]:disabled { opacity: .45; cursor: not-allowed; }
[role=tab] .lock, .btn .lock { font-size: 11px; }
.view-tabs [role=tab][aria-selected=true] { background: var(--accent-soft); color: var(--accent-ink); }
.mode-body { flex: 1; position: relative; min-height: 120px; } /* gives way when the Serial Monitor is dragged taller */
.mode-panel { position: absolute; inset: 0; }
#blocklyDiv { position: absolute; inset: 0; }

#textPane { display: flex; flex-direction: column; }
.gen-notice {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 10px;
  background: var(--accent-soft); border-bottom: 1px solid var(--accent-line); font-size: 13px;
}
.gen-notice > span { flex: 1; min-width: 180px; }

/* sketch tabs above the code, like the Arduino IDE */
.file-tabs {
  display: flex; align-items: stretch; min-height: 36px; flex: none;
  background: var(--cm-gutter); border-bottom: 1px solid var(--cm-gutter-line);
}
.file-tab-list { flex: 1; min-width: 0; display: flex; align-items: stretch; overflow-x: auto; scrollbar-width: thin; }
.file-tab, .file-tab-add, .file-tab-more {
  border: 0; background: transparent; color: var(--muted); cursor: pointer; font-family: var(--mono); font-size: 13px; white-space: nowrap;
}
.file-tab { padding: 0 16px; border-top: 2px solid transparent; }
.file-tab:hover { color: var(--text); }
.file-tab[aria-selected=true] { background: var(--cm-bg); color: var(--text); border-top-color: var(--accent); font-weight: 600; }
.file-tab-add { padding: 0 12px; font-size: 18px; font-family: inherit; }
.file-tab-more { padding: 0 14px; font-size: 18px; font-family: inherit; letter-spacing: 1px; }
.file-tab-add:hover, .file-tab-more:hover { color: var(--accent); }
.file-tab:focus-visible, .file-tab-add:focus-visible, .file-tab-more:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.file-tab-input {
  width: 190px; margin: 4px 6px; padding: 2px 8px; border: 1px solid var(--accent); border-radius: 6px;
  background: var(--field); color: var(--text); font-family: var(--mono); font-size: 13px; outline: none;
}
.tab-menu {
  position: absolute; z-index: 20; min-width: 190px; padding: 6px; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 30px rgba(2, 6, 23, .2);
}
.tab-menu button {
  border: 0; background: transparent; color: var(--text); text-align: left; padding: 8px 10px; border-radius: 8px;
  cursor: pointer; font-size: 13.5px;
}
.tab-menu button:hover:not(:disabled), .tab-menu button:focus-visible { background: var(--accent-soft); outline: none; }
.tab-menu button:disabled { opacity: .4; cursor: not-allowed; }
.tab-menu .danger:not(:disabled) { color: var(--err); }

/* CodeMirror */
.CodeMirror {
  flex: 1; min-height: 0; height: auto; font-family: var(--mono); font-size: 14px; line-height: 1.55;
  background: var(--cm-bg); color: var(--text);
}
.CodeMirror-gutters { background: var(--cm-gutter); border-right: 1px solid var(--cm-gutter-line); }
.CodeMirror-linenumber { color: var(--cm-lineno); }
.CodeMirror-cursor { border-left-color: var(--text); }
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: var(--cm-select); }
.cm-s-default .cm-keyword { color: var(--cm-keyword); font-weight: 600; }
.cm-s-default .cm-meta { color: var(--cm-meta); }
.cm-s-default .cm-string { color: var(--cm-string); }
.cm-s-default .cm-number { color: var(--cm-number); }
.cm-s-default .cm-comment { color: var(--cm-comment); font-style: italic; }
.cm-s-default .cm-type, .cm-s-default .cm-variable-3 { color: var(--cm-type); }
.cm-s-default .cm-variable, .cm-s-default .cm-def, .cm-s-default .cm-property { color: var(--text); }
.cm-error-line { background: var(--cm-error); }

/* icons mode */
.icons-pane { overflow: auto; padding: 14px; background: var(--warm); }
.icons-palette { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-tile {
  display: flex; flex-direction: column; align-items: center; gap: 2px; width: 84px; padding: 8px 4px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel); cursor: pointer; font-size: 12px; font-weight: 600;
}
.icon-tile:hover { border-color: var(--c); box-shadow: 0 3px 10px rgba(0, 0, 0, .08); }
.icon-tile svg, .step svg { width: 34px; height: 34px; fill: var(--c); }
.icons-options { display: flex; align-items: center; gap: 18px; margin: 14px 0; flex-wrap: wrap; font-size: 14px; }
.icons-options label { display: flex; align-items: center; gap: 6px; }
.icons-strip {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: stretch; padding: 14px;
  background: var(--panel); border: 2px dashed var(--accent-line); border-radius: 14px; min-height: 120px;
}
.step {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  width: 92px; padding: 10px 6px 8px; border-radius: 12px; background: color-mix(in srgb, var(--c, #94a3b8) 10%, var(--panel));
  border: 2px solid var(--c, #cbd5e1); font-size: 12.5px; font-weight: 600; cursor: grab;
}
.step.dragging { opacity: .4; }
.step.start, .step.end { --c: var(--tab-on); font-size: 26px; cursor: default; width: 72px; color: var(--accent-ink); }
.step.start span, .step.end span { font-size: 12px; }
.step input { width: 58px; padding: 2px 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); text-align: center; font-size: 12.5px; }
.step input[type=text] { width: 78px; }
.step .del {
  position: absolute; top: -8px; right: -8px; width: 22px; height: 22px; border-radius: 50%; border: 0;
  background: var(--panel); box-shadow: 0 1px 4px rgba(0, 0, 0, .25); cursor: pointer; font-size: 15px; line-height: 1;
}
.icons-hint { color: var(--muted); font-size: 13px; }

/* console */
.console {
  position: relative; flex: none; border-top: 1px solid var(--line); display: flex; flex-direction: column; height: var(--console-h, 200px);
  overflow: hidden; transition: height .3s ease;
}
.console.dragging { transition: none; user-select: none; }
/* drag the top edge up / down to resize the Serial Monitor */
.console-grip { position: absolute; top: 0; left: 0; right: 0; height: 7px; z-index: 2; cursor: ns-resize; touch-action: none; }
.console-grip::after {
  content: ""; position: absolute; top: 2px; left: 50%; width: 36px; height: 3px; margin-left: -18px; border-radius: 3px;
  background: var(--line); opacity: 0; transition: opacity .15s;
}
.console-grip:hover::after, .console-grip:focus-visible::after, .console.dragging .console-grip::after { opacity: 1; background: var(--accent); }
.console-grip:focus-visible { outline: none; }
/* folded away by default: only the header bar shows */
.console.collapsed { height: 41px; }
.console-head { display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 6px; border-bottom: 1px solid var(--line); font-size: 13.5px; min-height: 40px; flex: none; }
.console-toggle {
  display: flex; align-items: center; gap: 8px; min-width: 0; padding: 3px 8px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); cursor: pointer; font-size: 13.5px; text-align: left;
}
.console-toggle:hover { background: var(--track); }
.console-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.console-toggle .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { display: inline-block; font-size: 11px; color: var(--muted); transition: transform .3s ease; }
.console:not(.collapsed) .chev { transform: rotate(90deg); }
.unread { font-size: 11.5px; font-weight: 700; color: #fff; background: var(--accent); border-radius: 99px; padding: 1px 8px; white-space: nowrap; }
.out {
  flex: 1; margin: 0; padding: 8px 12px; overflow: auto; font-family: var(--mono); font-size: 12.5px;
  white-space: pre-wrap; background: var(--console); color: #e2e8f0;
}
.out .ok { color: #86efac; }
.out .err { color: #fca5a5; }
.out .info { color: #fcd34d; }
.out-serial { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.serial-form { display: flex; gap: 6px; padding: 6px; background: var(--console); }
.serial-form input { flex: 1; border-radius: 8px; border: 1px solid var(--console-line); background: var(--console-field); color: #fff; padding: 4px 8px; }

/* notifications (js/toast.js): iPhone-style banners at the top right */
.toasts {
  position: fixed; top: 64px; right: 16px; z-index: 1000; width: min(360px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  /* Apple-style glass: see-through, heavily blurred, a bright hairline edge and a soft shadow */
  pointer-events: auto; display: flex; gap: 11px; align-items: center; padding: 12px 14px;
  border-radius: 24px; background: var(--toast-bg); color: var(--toast-text);
  border: 1px solid var(--toast-edge);
  backdrop-filter: blur(28px) saturate(1.9); -webkit-backdrop-filter: blur(28px) saturate(1.9);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 12px 40px rgba(0, 0, 0, .16), 0 2px 6px rgba(0, 0, 0, .06);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Chakra Petch', system-ui, sans-serif;
  cursor: pointer; user-select: none; touch-action: pan-y; overflow: hidden;
  animation: toast-in .5s cubic-bezier(.2, .9, .25, 1.12);
  transition: transform .35s ease, opacity .35s ease, height .3s ease .1s, padding .3s ease .1s, margin .3s ease .1s;
}
.toast.leaving { opacity: 0; transform: translateX(40%) scale(.96); height: 0 !important; padding-top: 0; padding-bottom: 0; margin-top: -8px; border-width: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateX(110%) scale(.96); } to { opacity: 1; transform: none; } }
.toast-icon {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-size: 16px; font-weight: 800; line-height: 1; color: #fff; background: #8e8e93;
}
.toast.ok .toast-icon { background: #34c759; }
.toast.err .toast-icon { background: #ff3b30; }
.toast.busy .toast-icon { background: var(--accent); }
.toast.info .toast-icon { font-family: Georgia, serif; font-style: italic; }
.toast-spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .4); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast-main { flex: 1; min-width: 0; }
.toast-head { display: flex; align-items: baseline; gap: 8px; }
.toast-head b { flex: 1; font-size: 15px; font-weight: 600; letter-spacing: -.1px; }
.toast-head time { font-size: 12.5px; color: var(--toast-sub); }
.toast p { margin: 1px 0 0; font-size: 14px; line-height: 1.35; color: var(--toast-text); opacity: .92; white-space: pre-line; overflow-wrap: anywhere; }
.toast-bar { margin-top: 8px; height: 4px; border-radius: 99px; background: rgba(120, 120, 128, .2); overflow: hidden; }
.toast-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; transition: opacity .2s; }
  .toast.leaving { transform: none; }
}

/* board pane */
.board-pane { min-height: 0; }
.card { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card h2 { margin: 0 0 6px; font-size: 15px; letter-spacing: .5px; }
.tag { font-size: 11px; background: var(--accent); color: #fff; border-radius: 6px; padding: 1px 6px; vertical-align: middle; }
.head-actions { display: flex; gap: 4px; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 16px; }
.view3d { position: relative; width: 100%; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden; background: var(--view-bg); }
.view3d canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.view3d:fullscreen { aspect-ratio: auto; border-radius: 0; }
.view-tools { position: absolute; top: 8px; right: 8px; z-index: 2; display: flex; gap: 4px; }
.vt-btn {
  min-width: 32px; height: 30px; padding: 0 9px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 700;
  border: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 85%, transparent); color: var(--text);
  backdrop-filter: blur(4px);
}
.vt-btn:hover { border-color: var(--accent); }
.vt-btn[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: #fff; }
.vt-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* A-Maze-ing run: time left, score, straights / turns done */
.run-hud {
  position: absolute; top: 8px; left: 8px; z-index: 2; display: grid; gap: 1px; padding: 6px 10px; border-radius: 10px;
  background: rgba(15, 23, 42, .72); color: #f8fafc; font-size: 12px; line-height: 1.3; backdrop-filter: blur(4px); pointer-events: none;
}
.run-hud b { font-size: 18px; font-variant-numeric: tabular-nums; }
.run-hud small { color: #cbd5e1; }
.run-hud.fell b { color: #f87171; }
.run-hud.done b { color: #4ade80; }
.view3d:not(:fullscreen) .run-hud { display: none; } /* time and score only in full screen */
/* track layout editor, over the left of the 3D view */
.track-panel {
  position: absolute; top: 46px; left: 8px; bottom: 8px; z-index: 3; width: min(260px, calc(100% - 16px)); overflow: auto;
  display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: 12px; font-size: 13px;
  background: color-mix(in srgb, var(--panel) 94%, transparent); color: var(--text); border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); backdrop-filter: blur(6px);
}
.track-panel[hidden] { display: none; }
.tp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tp-preset { display: flex; align-items: center; gap: 6px; }
.tp-preset select { flex: 1; min-width: 0; }
.tp-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.tp-list li { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 4px 6px; padding: 6px; border-radius: 8px; background: var(--bg); }
.tp-list li > select, .tp-list li > .tp-finish { grid-column: 1 / -1; }
.tp-list li > b { font-size: 12px; min-width: 56px; }
.tp-list input { width: 100%; }
.tp-list select { min-width: 0; }
.tp-list .tp-finish { color: var(--muted); font-size: 12px; }
.tp-list .tp-del { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); cursor: pointer; }
.tp-list .tp-del:disabled { opacity: .35; cursor: default; }
.tp-list input, .tp-list select, .tp-preset select { height: 28px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; padding: 0 4px; }
.tp-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tp-actions .btn { height: 32px; font-size: 13px; padding: 0 10px; }
.tp-info { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.tp-info .warn { color: var(--err); display: block; }
.view3d:has(.track-panel:not([hidden])) .run-hud { display: none; }
/* play buttons, only in full screen: at the top right, in front of the view buttons */
.fs-play { display: none; }
.view3d:fullscreen .fs-play { display: flex; align-items: center; gap: 6px; margin-right: 10px; }
.view3d:fullscreen .fs-play .btn { height: 38px; font-size: 15px; padding: 0 14px; }
.view3d:fullscreen .fs-play .btn.ghost { background: var(--panel); }
.view3d:fullscreen .fs-play .ok-btn { width: 46px; height: 46px; font-size: 11px; border-width: 3px; }
.view3d:fullscreen .view-tools { align-items: center; }
.view3d:fullscreen .track-panel { top: 66px; left: 16px; width: 320px; font-size: 15px; }
.view3d:fullscreen .run-hud { top: 16px; left: 16px; font-size: 15px; }
.view3d:fullscreen .run-hud b { font-size: 26px; }
.view3d:fullscreen .view-tools { top: 16px; right: 16px; }
.view3d:fullscreen .vt-btn { height: 38px; font-size: 15px; padding: 0 14px; }
.view3d:fullscreen #btnFull { background: var(--err); border-color: var(--err); color: #fff; }

/* the board pane slides away to give the editor the full width */
.layout { transition: grid-template-columns .3s ease, gap .3s ease; }
.board-pane { overflow: hidden; }
.board-pane > .card { width: 400px; }
body.board-collapsed .layout { grid-template-columns: minmax(0, 1fr) 0; gap: 0; }
body.board-collapsed .board-pane { visibility: hidden; transition: visibility 0s .3s; }
.board-expand {
  position: fixed; right: 0; top: 50%; z-index: 30; transform: translateY(-50%);
  writing-mode: vertical-rl; padding: 14px 7px; border: 0; border-radius: 10px 0 0 10px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13.5px; box-shadow: -2px 4px 14px rgba(0, 0, 0, .2);
}
.board-expand:hover { background: var(--accent-hover); }
.board-expand:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sim-controls { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { accent-color: var(--accent); }
.sim-state { display: flex; align-items: center; gap: 12px; }
.ok-btn {
  width: 64px; height: 64px; border-radius: 50%; border: 4px solid var(--a300); background: var(--accent); color: #fff;
  font-weight: 700; font-size: 13px; cursor: pointer; box-shadow: 0 4px 0 var(--a800); flex-shrink: 0; user-select: none;
}
.ok-btn:active:not(:disabled), .ok-btn.down { transform: translateY(3px); box-shadow: 0 1px 0 var(--a800); }
.ok-btn:disabled { filter: grayscale(.7); opacity: .5; cursor: not-allowed; }
.meters { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.meter { display: grid; grid-template-columns: 34px 1fr 38px; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; }
.meter b { text-align: right; font-family: var(--mono); font-weight: 400; }
.bar { position: relative; height: 10px; border-radius: 99px; background: var(--track); overflow: hidden; }
.bar::after { content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--line-strong); }
.bar i { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; background: #3b82f6; }
.bar i.rev { background: #f97316; }
.led-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; }
.led { width: 18px; height: 18px; border-radius: 50%; background: var(--led-off); box-shadow: inset 0 -2px 3px rgba(0, 0, 0, .2); }
.led.on { background: #22c55e; box-shadow: 0 0 12px #22c55e; }
.sensor { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.sensor input { flex: 1; accent-color: var(--accent); }
.sensor output { width: 36px; text-align: right; font-family: var(--mono); font-size: 12.5px; }
#simStatus { margin: 0; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .mode-body { min-height: 420px; }
  .board-pane > .card { width: auto; }
  body.board-collapsed .layout { grid-template-columns: 1fr; gap: 12px; }
  body.board-collapsed .board-pane { display: none; }
}
@media (max-width: 640px) {
  .brand img { height: 26px; }
  .brand strong { font-size: 14px; }
  .brand small { font-size: 11.5px; }
  #portStatus { display: none; }
}

/* class access code */
.class-chip { border: 0; cursor: pointer; background: #1e3a5f; color: #dbeafe; }
.class-chip:hover { background: #7f1d1d; color: #fee2e2; }
.gate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(15, 23, 42, .55); backdrop-filter: blur(6px); }
.gate[hidden] { display: none; }
.gate-card {
  width: min(360px, 100%); display: grid; gap: 10px; justify-items: center; text-align: center; padding: 28px 24px;
  border-radius: 18px; background: var(--panel); color: var(--text); box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
}
.gate-logo { height: 54px; }
.gate-card h2 { margin: 4px 0 0; font-size: 20px; }
.gate-card p { margin: 0; }
.gate-card input {
  width: 100%; height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font: 700 18px/1 inherit; letter-spacing: 2px; text-align: center; text-transform: uppercase;
}
.gate-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.gate-card .btn { width: 100%; height: 44px; justify-content: center; font-size: 16px; }
.gate-err { color: var(--err); font-size: 13px; }

/* admin page for the class codes */
.admin { z-index: 110; }
.admin-card { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; justify-items: stretch; text-align: left; }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 17px; }
.admin-login { display: grid; gap: 8px; }
.admin-card input { width: 100%; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; padding: 0 10px; text-align: left; letter-spacing: normal; text-transform: none; }
.admin-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.admin-add { display: grid; gap: 8px; padding: 12px; border-radius: 12px; background: var(--bg); }
.admin-add label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.admin-add input { background: var(--panel); }
.admin-code-row { display: flex; gap: 6px; }
.admin-code-row input { text-transform: uppercase; letter-spacing: 1px; }
.admin-code-row .btn { height: 40px; white-space: nowrap; }
.admin-card .btn { justify-content: center; }
.admin-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.admin-list li { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); }
.admin-list li.expired { opacity: .6; }
.admin-list code { font: 700 15px/1.2 ui-monospace, Menlo, monospace; letter-spacing: 1px; }
.admin-list small { display: block; color: var(--muted); font-size: 12px; }
.admin-list .btn { height: 32px; font-size: 13px; padding: 0 10px; }
.admin-list .del.armed { background: var(--err); border-color: var(--err); color: #fff; }
.admin-list .empty { display: block; border-style: dashed; color: var(--muted); text-align: center; }
.admin-logout { margin-top: 8px; width: 100%; }
