:root {
  color-scheme: light;
  --paper: #ffffff;
  --bg: #f4f6f5;
  --panel: #fafbf9;
  --chrome: #e9edeb;
  --line: #cbd2ce;
  --ink: #1d2a26;
  --mute: #54635d;
  --faint: #6c7a74;
  --accent: #11613e;
  --selected: #dfefe4;
  --active-line: #f2f7f3;
  --gold: var(--accent);
  --night: #192324;
  --terminal: #192221;
  --mint: #a3ee91;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font: 16px/1.5 Inter, "Noto Sans CJK JP", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #19211f;
  --bg: #222a27;
  --panel: #202825;
  --chrome: #27312d;
  --line: #3e4a43;
  --ink: #e1e8e2;
  --mute: #b1beb5;
  --faint: #91a096;
  --accent: #a3ee91;
  --selected: #314537;
  --active-line: #26332b;
  --night: #101815;
  --terminal: #111916;
}
* { box-sizing: border-box; }
body, h1, h2, pre { margin: 0; }
h2 { font-size: .92rem; font-weight: 680; }
button, select, input, textarea { font: inherit; border-radius: 0; }
button, select { cursor: pointer; }
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 5px 10px; border: 1px solid var(--line);
  color: var(--ink); background: var(--paper);
  font-size: .875rem; line-height: 1.4; font-weight: 550;
}
button:hover { background: var(--chrome); }
button:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
button svg { pointer-events: none; }
.ico { width: 17px; height: 17px; flex: none; }
.icon, .quiet, .tab, .xtab, .node, .menuitem { border-color: transparent; background: transparent; }
.icon { width: 30px; height: 30px; padding: 5px; color: var(--mute); }
[hidden] { display: none !important; }

header {
  height: 52px; display: flex; align-items: center; gap: 18px; padding: 0 16px;
  background: var(--night); color: #eff6f0; border-bottom: 1px solid #35453d;
}
.brand { display: flex; align-items: center; gap: 9px; font: 730 1.37rem/1 Arial, sans-serif; letter-spacing: -.065em; flex: none; }
.brand img { width: 27px; height: 27px; }
.crumb { display: flex; align-items: center; gap: 9px; min-width: 0; padding-left: 18px; border-left: 1px solid #52605a; color: #bac7bf; font: 13px/1.5 var(--mono); }
.crumb .ico { width: 15px; }
#crumbFile { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #edf4ef; }
.header-end { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.header-end .icon { color: #d3dfd7; }
.header-end button:hover { background: #35463d; }
.header-end button:focus-visible { outline-color: var(--mint); }
.connect { min-height: 31px; background: transparent; color: #e4f7e6; border-color: #708279; padding: 4px 10px; white-space: nowrap; margin-right: 5px; }
.connected .connect { color: var(--mint); border-color: #7eaa80; }
main { width: 100%; margin: 0; padding: 0; }
aside, .workarea, .layout, .panel { min-width: 0; min-height: 0; }
.panel { overflow: hidden; background: var(--panel); }
.panel-title, .editor-tools, .rootline, .device-info, .file-foot, .dialoghead { display: flex; align-items: center; }
.panel-title { flex: none; height: 44px; gap: 8px; padding: 0 14px; border-bottom: 1px solid var(--line); }
.panel-title h2 { margin-right: auto; }
.panel-title > .ico { color: var(--mute); }
.files { display: flex; flex-direction: column; }
.files .panel-title { gap: 5px; }
.files .panel-title > .ico { margin-right: 3px; }
.rootline { gap: 8px; padding: 12px 14px 6px; color: var(--mute); font-size: .81rem; }
.rootline .ico { width: 15px; }
#tree { flex: 1; overflow: auto; padding: 4px 0; }
.row { height: 32px; display: flex; align-items: center; position: relative; }
.row:hover, .row:focus-within { background: var(--chrome); }
.row.active { background: var(--selected); color: var(--accent); }
.row.active::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--accent); }
.row .node { flex: 1; min-width: 0; height: 100%; padding: 0 0 0 7px; gap: 8px; justify-content: flex-start; text-align: left; font: 14px var(--mono); color: inherit; }
.node:hover { background: transparent; }
.node span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node .ico, .tab .ico { width: 15px; height: 15px; }
.node .chev { width: 11px; color: var(--faint); }
.folder { color: var(--faint); }
.py { color: var(--accent); }
.doc { color: var(--mute); }
.more { opacity: 0; margin-right: 6px; }
.row:is(:hover,:focus-within,.active) .more { opacity: 1; }
.file-foot { flex: none; border-top: 1px solid var(--line); }
.file-foot button { border: 0; width: 100%; justify-content: flex-start; padding: 9px 16px; background: transparent; }
.file-foot button:hover { background: var(--chrome); }
.device .panel-title { background: var(--chrome); }
.device .panel-title h2 { font-family: var(--mono); font-size: .88rem; letter-spacing: -.035em; }
.board {
  position: relative; isolation: isolate; background-color: #1b2d25;
  background-image: linear-gradient(#91ab8b13 1px, transparent 1px), linear-gradient(90deg,#91ab8b13 1px,transparent 1px);
  background-size: 16px 16px;
}
.board img { width: 100%; height: 100%; object-fit: contain; }
.device-info { min-height: 41px; gap: 7px; justify-content: space-between; padding: 4px 9px 4px 14px; border-top: 1px solid var(--line); }
#linkState { color: var(--mute); font: 12px/1.3 var(--mono); white-space: nowrap; }
.device-info button { font-size: .8rem; }
.device-info .ico { width: 14px; }
.editor { display: flex; flex-direction: column; background: var(--paper); }
.editor-tools { height: 44px; flex: none; border-bottom: 1px solid var(--line); background: var(--chrome); }
#tabs { align-self: stretch; display: flex; min-width: 0; flex: 0 1 auto; overflow-x: auto; scrollbar-width: thin; }
.tabwrap { display: flex; align-items: center; border-right: 1px solid var(--line); border-top: 2px solid transparent; padding: 0 8px; color: var(--mute); }
.tabwrap.sel { background: var(--paper); color: var(--ink); border-top-color: var(--accent); }
.tab { white-space: nowrap; font: 13px var(--mono); padding: 8px 4px; color: inherit; }
.xtab { color: var(--faint); padding: 3px; }
.xtab .ico { width: 13px; height: 13px; }
#newTab { flex: none; margin-inline: 3px; }
.actions { display: flex; margin-left: auto; flex: none; align-items: center; gap: 5px; padding: 0 9px; }
.actions button { height: 30px; white-space: nowrap; }
.actions .ico { width: 15px; height: 15px; }
button.primary { background: var(--mint); color: #142b17; border-color: #7db575; padding-inline: 15px; }
button.primary:hover { background: #b4f2a9; }
.primary .ico { fill: currentColor; }
.codebox { position: relative; display: flex; flex: 1; min-height: 0; overflow: hidden; background: var(--paper); }
.codearea { flex: 1; position: relative; min-width: 0; }
.codearea, .codebox pre, .codebox textarea, #lines { font: 15px/1.7 var(--mono); letter-spacing: 0; tab-size: 4; }
.codearea:focus-within::before {
  content: ''; position: absolute; left: 0; right: 0; height: 1.7em; pointer-events: none;
  top: calc(15px + var(--cursor-index,0) * 1.7em - var(--scroll-y,0px));
  background: var(--active-line);
}
.codebox pre, .codebox textarea { position: absolute; inset: 0; width: 100%; height: 100%; padding: 15px 14px 18px; margin: 0; border: 0; outline: 0; background: transparent; white-space: pre; overflow: auto; }
.codebox pre { pointer-events: none; scrollbar-width: none; color: var(--ink); }
.codebox textarea { color: transparent; -webkit-text-fill-color: transparent; caret-color: var(--ink); resize: none; }
.codebox textarea::selection { background: #66af8a59; }
#lines { width: 51px; flex: none; text-align: right; padding: 15px 10px 18px 0; overflow: hidden; white-space: pre; background: var(--panel); border-right: 1px solid var(--line); color: var(--faint); }
.tok-key { color: #76409b; }.tok-str { color: #217342; }.tok-call { color: #215e8c; }.tok-num { color: #93451d; }.tok-comment { color: #69756d; }.tok-mod { color: #206c74; }
[data-theme=dark] .tok-key { color: #d7a8e6; }[data-theme=dark] .tok-str { color: #a9d890; }[data-theme=dark] .tok-call { color: #91c7ef; }[data-theme=dark] .tok-num { color: #f0ba90; }[data-theme=dark] .tok-comment { color: #9cac9f; }[data-theme=dark] .tok-mod { color: #88cfc6; }
.console { display: flex; flex-direction: column; background: var(--terminal); }
.console .panel-title { background: var(--chrome); height: 40px; gap: 8px; }
.terminal-actions { display: flex; align-items: center; gap: 3px; margin-left: auto; }
.terminal-actions .ico { width: 15px; }
#log { flex: 1; min-height: 0; overflow: auto; padding: 12px 17px; color: #e0e8e1; font: 13px/1.85 var(--mono); }
.logrow { display: grid; grid-template-columns: max-content max-content minmax(0,1fr); align-items: baseline; column-gap: 12px; }
.logmessage { min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.logtime { color: #a1afa7; font-size: 12px; }
.logtag { color: #a3ee91; min-width: 34px; font-size: 12px; }
.logrow .errorline { grid-column: 3; justify-self: start; margin-block: 3px; }
.error .logtag { color: #ffac97; }
.prompt { display: none; }
footer { height: 27px; display: flex; align-items: center; justify-content: space-between; padding: 0 13px; background: var(--chrome); border-top: 1px solid var(--line); color: var(--mute); font: 12px var(--mono); }
footer > span, .file-meta { display: flex; align-items: center; gap: 8px; }
.statusdot { width: 6px; height: 6px; background: var(--accent); }
.file-meta span + span { border-left: 1px solid var(--line); margin-left: 5px; padding-left: 12px; }
#menu, dialog { background: var(--paper); color: var(--ink); border: 1px solid var(--faint); }
#menu { position: fixed; z-index: 7; min-width: 165px; padding: 4px; box-shadow: 3px 3px 0 #17221b25; }
.menuitem { display: flex; width: 100%; justify-content: flex-start; font-weight: 450; }
dialog { width: min(450px,92vw); max-height: 85dvh; overflow: auto; padding: 20px; }
dialog::backdrop { background: #111a17a8; }
.dialoghead { justify-content: space-between; margin-bottom: 12px; }
.dialoghead h2 { font-size: 1.05rem; }
#dialogbody { color: var(--mute); font-size: .94rem; margin-bottom: 18px; }
#dialogbody p { margin: 8px 0; }
input:not([type=checkbox]), select { color: var(--ink); border: 1px solid var(--line); background: var(--paper); padding: 4px 7px; }
#dialogbody :is(input,select) { width: 100%; }
#dialogbuttons { display: flex; justify-content: flex-end; gap: 8px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 47px; border-top: 1px solid var(--line); font-size: .9rem; }
#toast { flex: 1; min-width: 0; margin: 0 12px; display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--ink); }
footer > span:first-child, .file-meta { flex: none; }

.empty { color: var(--mute); padding: 10px; font-size: .85rem; }
@media(max-width:680px){
  header { height: 46px; gap: 8px; padding: 0 8px; }
  .brand { font-size: 1.16rem; gap: 5px; }.brand img { width: 22px; height: 22px; }
  .crumb { padding-left: 8px; gap: 3px; font-size: 12px; }.crumb .ico { display: none; }
  .header-end { gap: 1px; }.header-end .icon { width: 25px; }.connect { font-size: .76rem; padding-inline: 6px; }
  .panel-title { padding-inline: 8px; gap: 5px; }.actions { gap: 3px; padding-inline: 4px; }
  .actions button { padding-inline: 6px; }.actions .icon { width: 24px; }.tabwrap { padding-inline: 5px; }
  .more { opacity: 1; margin-right: 2px; }.row { height: 30px; }.file-foot button { padding: 6px 9px; }
  .device-info { padding: 4px; flex-wrap: wrap; }.device-info button { padding: 3px 5px; }
  .device .panel-title h2 { font-size: .78rem; }.device .panel-title>.ico { display: none; }
  #lines { width: 34px; padding-right: 5px; }.codearea,.codebox pre,.codebox textarea,#lines { font-size: 14px; }
  .console .panel-title { gap: 3px; }.console .panel-title>.ico { display: none; }
  #log { padding: 8px; }.logrow { gap: 6px; }
}
@media(max-width:440px){
  .appbar { display: grid; grid-template-columns: auto minmax(0,1fr); grid-template-rows: 43px 26px; height: 70px; gap: 0; }
  .header-end { grid-column: 2; grid-row: 1; }
  .crumb { grid-column: 1 / -1; grid-row: 2; align-self: stretch; padding: 0; border-left: 0; border-top: 1px solid #435149; }
}
@media(hover:none){.row .more{opacity:1}}
#draftStatus { font: 12px var(--mono); margin-inline: auto 10px; color: var(--accent); }
footer:has(#draftStatus:not([hidden])) .file-meta > :not(:last-child) { display: none; }
.logrow[data-kind="RUN"] .logtag { color: #a3ee91; }
.logrow[data-kind="OUT"] .logtag { color: #bed0d7; }
.logrow[data-kind="STOP"] .logtag { color: #ffbe86; }
.logrow[data-kind="INPUT"] .logtag { color: #c5b2ff; }
.logrow[data-kind="SYS"] .logtag, .logrow[data-kind="FILE"] .logtag { color: #b3bdb7; }
.tabwrap.drop-before { box-shadow: inset 3px 0 var(--accent); }
.tabwrap.drop-after { box-shadow: inset -3px 0 var(--accent); }
.row.drop-target, .rootline.drop-target { outline: 2px solid var(--accent); outline-offset: -2px; }
#devicePanel.generic .board { display: grid; place-items: center; }
#devicePanel.generic .board > :is(img,svg) { display: none; }
#devicePanel.generic .board .device-chip { display: block; color: #b4dcc0; width: 42px; height: 42px; position: static; }
.device-chip { display: none; }
#boardName { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
