/* App chrome. Colors are CSS variables set from the active theme (src/theme.js); these are the Toxic Glow defaults. */
:root {
  --bg: #070A05;
  --fg: #DDF2CF;
  --border: #2C4A1C;
  --active: #9CFF3A;
  --on-active: #070A05;   /* text on an --active background */
  --muted: #8FA585;
  --panel: #0E140B;
  --link: #6FE0FF;
  --err: #FF5C57;
  --ok: #9CFF3A;
  --warn: #FFC53D;
  --folder: #C9B458;
  --border-soft: color-mix(in srgb, var(--border) 55%, transparent);
  --border-faint: color-mix(in srgb, var(--border) 25%, transparent);
  --mono: "Cascadia Code", "JetBrains Mono", "Fira Code", ui-monospace, Menlo, "Droid Sans Mono", "DejaVu Sans Mono", monospace;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs: 14px;
  --app-h: 100dvh;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 14px var(--ui); overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--border); border-radius: 0; }
input, select, textarea { padding: 6px 8px; min-height: 34px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 1px solid var(--active); outline-offset: -1px; }
button { cursor: pointer; padding: 6px 12px; min-height: 34px; }
button:active { outline: 1px dashed var(--active); outline-offset: -1px; }
button:disabled { opacity: .45; }
button.primary { border-color: var(--active); }
button.danger { border-color: var(--err); color: var(--err); }
button.block { display: block; width: 100%; margin: 10px 0; }
button.link { border: none; color: var(--link); min-height: 0; padding: 0 4px; }
[hidden] { display: none !important; }
.grow { flex: 1; min-width: 0; }
.ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint { color: var(--muted); padding: 16px; line-height: 1.5; }
.hint.small { font-size: 12px; padding: 6px 2px; }
.hint.center { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; flex-direction: column; }

#app { height: var(--app-h); display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }

/* top row: files button, open-file tabs, build / run / more */
#topbar { display: flex; align-items: stretch; border-bottom: 1px solid var(--border); flex: none; height: 46px; }
#topbar .files-btn { width: 46px; height: 45px; border-right: 1px solid var(--border); color: var(--folder); }
#topbar #tabs { flex: 1; min-width: 0; border-bottom: none; min-height: 0; }
#top-actions { display: flex; align-items: center; gap: 2px; padding: 0 4px; border-left: 1px solid var(--border); flex: none; }
#top-actions .ibtn { width: 40px; height: 40px; }
#top-actions .ibtn.run { border-color: var(--active); color: var(--ok); }
#top-actions .ibtn.run svg { fill: var(--ok); }

#work { flex: 1; min-height: 0; display: flex; position: relative; }
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* files drawer: overlay on phones, docked sidebar on wide screens */
#drawer { position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: min(320px, 86vw); background: var(--bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; transform: translateX(-102%); transition: transform .18s ease-out; padding-top: env(safe-area-inset-top); }
body.drawer-open #drawer { transform: none; }
#drawer-back { position: fixed; inset: 0; z-index: 39; background: #000b; display: none; }
body.drawer-open #drawer-back { display: block; }
body.wide #drawer { position: static; transform: none; transition: none; width: 280px; flex: none; padding-top: 0; }
body.wide #drawer-back, body.wide .drawer-close, body.wide #topbar .files-btn { display: none; }

/* slide-up panel */
#panel { flex: none; display: flex; flex-direction: column; border-top: 1px solid var(--border); min-height: 0; }
#main[data-panel="closed"] #panel-body { display: none; }
#main[data-panel="full"] #editor-wrap { display: none; }
#main[data-panel="full"] #panel { flex: 1; }
#panel-head { flex: none; touch-action: none; cursor: row-resize; user-select: none; -webkit-user-select: none; }
/* the visible bar is drawn by ::after; the grip itself is a wider, taller touch target */
#panel-head .grip { width: 160px; height: 18px; margin: 0 auto; display: flex; align-items: center; justify-content: center; }
#panel-head .grip::after { content: ""; width: 56px; height: 5px; border-radius: 3px; background: var(--border); }
#main:not([data-panel="closed"]) #panel-head .grip::after { background: var(--active); }
/* closed: just the drag line (26px tall touch area), no tabs */
#main[data-panel="closed"] #panel-tabs { display: none; }
#main[data-panel="closed"] #panel-head { height: 25px; display: flex; align-items: center; }
#main[data-panel="closed"] #panel-head .grip { margin: 0 auto; }
#panel-tabs { display: flex; align-items: center; height: 38px; padding: 0 2px 0 4px; }
.ptab { border: none; border-bottom: 2px solid transparent; background: none; min-height: 0; height: 34px; padding: 0 9px; font-size: 11px; font-weight: 600; letter-spacing: .06em; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.ptab.active { color: var(--fg); border-bottom-color: var(--active); }
.ptab .badge { color: var(--on-active); background: var(--active); font-size: 10px; padding: 0 4px; letter-spacing: 0; }
#panel-status { font-size: 12px; text-align: right; padding: 0 4px; color: var(--muted); cursor: pointer; }
#panel-status.ok { color: var(--ok); } #panel-status.bad { color: var(--err); }
#panel-tabs .ibtn { width: 34px; height: 34px; }
#panel-body { flex: 1; min-height: 0; display: flex; border-top: 1px solid var(--border-soft); }
.pview { display: none; flex-direction: column; min-width: 0; min-height: 0; flex: 1; }
.pview.active { display: flex; }
.tabbar.small { min-height: 32px; }
.tabbar.small .tab { font-size: 12.5px; }
.tabbar.small .tab .tclose { height: 30px; }
#editor-empty b { color: var(--active); }

.ic { display: inline-flex; width: 20px; height: 20px; flex: none; }
.ic svg { width: 100%; height: 100%; }
.ibtn { border: 1px solid transparent; background: none; padding: 0; width: 38px; height: 38px; min-height: 0; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.ibtn:hover, .ibtn:active { border-color: var(--active); }

.toolbar { display: flex; align-items: center; gap: 4px; padding: 2px 4px; border-bottom: 1px solid var(--border); min-height: 42px; flex: none; }
.toolbar .title { font-size: 11px; letter-spacing: .08em; padding-left: 8px; font-weight: 600; }
.toolbar select { max-width: 42vw; }
button.act { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; white-space: nowrap; }
button.act.run { border-color: var(--active); }
button.act.run .ic { color: var(--ok); }

.tabbar { display: flex; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--border); flex: none; min-height: 38px; }
.tabbar::-webkit-scrollbar { display: none; }
.tab { display: flex; align-items: center; gap: 6px; padding: 0 2px 0 10px; border-right: 1px solid var(--border); white-space: nowrap; cursor: pointer; color: var(--muted); border-top: 2px solid transparent; }
.tab.active { color: var(--fg); border-top-color: var(--active); }
.tab.dirty .tname::after { content: " ●"; }
.tab .tclose { width: 30px; height: 34px; }
.tab .tclose .ic { width: 15px; height: 15px; }
.tabbar > .ibtn { margin-left: 2px; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ext-c, .dot.ext-h { background: var(--s-keyword); }
.dot.ext-s, .dot.ext-asm { background: var(--s-control); }
.dot.ext-md { background: var(--fg); }
.dot.ext-json, .dot.ext-js { background: var(--s-func); }
.dot.ext-py { background: var(--s-type); }
.dot.ext-ld, .dot.ext-mk { background: var(--s-string); }

#editor-wrap { flex: 1; min-height: 0; position: relative; }
#editor-host { position: absolute; inset: 0; }
#editor-host .cm-editor { height: 100%; }
.cm-editor .cm-scroller { font-size: var(--fs); }
.cm-editor.cm-focused { outline: none; }

#term-area { flex: 1; min-height: 0; position: relative; }
.xterm-host { position: absolute; inset: 4px 0 0 6px; }
.xterm .xterm-viewport { background: var(--bg) !important; }

/* phone key bar */
#kb { display: flex; overflow-x: auto; scrollbar-width: none; border-top: 1px solid var(--border); flex: none; touch-action: pan-x; }
#kb::-webkit-scrollbar { display: none; }
#kb button { flex: none; min-width: 40px; height: 40px; padding: 0 6px; border: none; border-right: 1px solid var(--border-soft); font: 16px var(--mono); user-select: none; -webkit-user-select: none; touch-action: manipulation; }
#kb button.wide { font: 13px var(--ui); min-width: 48px; }
#kb[data-mode="editor"] .term-only, #kb[data-mode="term"] .ed-only { display: none; }
#kb button.ed-only { font-size: 20px; min-width: 46px; color: var(--active); }
#kb button.on { color: var(--on-active); background: var(--active); }


/* files */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.row { display: flex; align-items: center; gap: 6px; min-height: 40px; padding-right: 2px; cursor: pointer; border: 1px solid transparent; }
.row:active { border-color: var(--active); }
.row.current { border: 1px dotted var(--active); }
.row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .tw { width: 16px; height: 16px; }
.row .fold { width: 18px; height: 18px; color: var(--folder); }
.row .dot { margin: 0 4px; }
.row .more { width: 36px; height: 36px; color: var(--muted); }

/* compare */
.chk { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; white-space: nowrap; }
.chk input { min-height: 0; accent-color: var(--active); width: 16px; height: 16px; }
#view-compare .toolbar { flex-wrap: wrap; padding: 4px; }
#cmp-panes { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; }
#cmp-panes.stack { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
.cmp-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--border); }
#cmp-panes.stack .cmp-pane { border-right: none; border-bottom: 1px solid var(--border); }
.cmp-pane:last-child { border-right: none; }
/* one-line pane label: "A  compiler  flags  count" */
.pane-label { display: flex; align-items: baseline; gap: 8px; border: none; border-bottom: 1px solid var(--border-faint); min-height: 0; height: 30px; padding: 0 8px; text-align: left; width: 100%; flex: none; white-space: nowrap; overflow: hidden; }
.pane-label b { color: var(--active); flex: none; }
.pane-label .pl-comp { color: var(--fg); font-size: 12.5px; flex: none; }
.pane-label .pl-flags { color: var(--muted); font: 12px var(--mono); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pane-label .cmp-status { flex: none; font: 12px var(--mono); }
#cmp-ctrls { display: inline-flex; align-items: center; gap: 2px; }
#cmp-ctrls[hidden] { display: none !important; }
.segs { display: inline-flex; border: 1px solid var(--border); }
.seg { border: none; min-height: 0; height: 26px; padding: 0 8px; font: 600 11px var(--ui); letter-spacing: .04em; color: var(--muted); }
.seg.on { background: var(--fg); color: var(--bg); }
.sheet.flags { gap: 10px; padding-top: 10px; max-height: 85vh; overflow-y: auto; }
.fgroup-title { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding-bottom: 6px; }
.fchips { display: flex; flex-wrap: wrap; gap: 6px; }
.fchip { min-height: 36px; padding: 0 10px; font: 13px var(--mono); border-color: var(--border-soft); }
.fchip.on { border-color: var(--active); color: var(--on-active); background: var(--active); }
input.mono { font: 14px var(--mono); }
.cmp-status { font-size: 11.5px; white-space: nowrap; }
.cmp-status.ok { color: var(--ok); }
.cmp-status.bad { color: var(--err); }
.cmp-err { margin: 0 4px 4px; padding: 6px; max-height: 30%; overflow: auto; color: var(--err); border: 1px solid var(--err); font: 12px var(--mono); white-space: pre-wrap; flex: none; }
.cmp-out { flex: 1; min-height: 0; position: relative; }
.cmp-out .cm-editor { position: absolute; inset: 0; }
.cmp-out .cm-scroller { font-size: calc(var(--fs) - 1px); }

/* git */
#git-body { padding: 8px; }
.git-head { display: flex; gap: 8px; align-items: center; padding: 4px 2px 8px; }
#commit-msg { width: 100%; resize: vertical; font: 14px var(--ui); }
.btnrow { display: flex; gap: 6px; margin: 6px 0; }
.section { display: flex; align-items: center; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; padding: 14px 2px 4px; border-bottom: 1px solid var(--border-soft); }
.git-row { padding-left: 4px; }
.gs { font: 600 12px var(--mono); width: 16px; text-align: center; }
.gs-M { color: var(--warn); } .gs-A, .gs-U { color: var(--ok); } .gs-D { color: var(--err); } .gs-R { color: var(--ok); }
.gdir { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40%; }
.logrow { display: flex; gap: 8px; padding: 6px 2px; font-size: 13px; border-bottom: 1px solid var(--border-faint); }
.hash { font-family: var(--mono); color: var(--s-func); }
pre.diff { font: 12px var(--mono); overflow: auto; max-height: 60vh; margin: 0; border: 1px solid var(--border); padding: 6px 0; }
pre.diff div { padding: 0 8px; white-space: pre; }
pre.diff .add { color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, transparent); }
pre.diff .del { color: var(--err); background: color-mix(in srgb, var(--err) 15%, transparent); }
pre.diff .hunk { color: var(--s-type); }

/* modals, sheets, toasts */
.modal-back { position: fixed; inset: 0; background: #000a; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--bg); border: 1px solid var(--border); padding: 16px; width: min(440px, 100%); display: flex; flex-direction: column; gap: 10px; }
.modal.wide { width: min(900px, 100%); }
.modal-title { font-weight: 600; word-break: break-all; }
.modal-msg { color: var(--muted); line-height: 1.4; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.set-row { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.set-row input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--active); }
.stepper { display: inline-flex; align-items: center; gap: 8px; }
.stepper b { min-width: 24px; text-align: center; }
.sheet-back { align-items: flex-end; padding: 0; }
.sheet { background: var(--bg); border-top: 1px solid var(--border); width: 100%; max-width: 560px; display: flex; flex-direction: column; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); gap: 6px; }
.sheet-title { color: var(--muted); font-size: 12px; padding: 6px 4px; word-break: break-all; font-family: var(--mono); }
.sheet button { text-align: left; min-height: 46px; }
.sheet button.danger { border-color: var(--err); }
.sheet .sheet-cancel { text-align: center; border-color: var(--active); }
#toasts { position: fixed; left: 8px; right: 8px; bottom: calc(100px + env(safe-area-inset-bottom)); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { pointer-events: auto; background: var(--panel); border: 1px solid var(--border); padding: 8px 12px; display: flex; gap: 10px; align-items: center; max-width: 560px; white-space: pre-wrap; font-size: 13px; }
.toast.err { border-color: var(--err); }
.toast.ok { border-color: var(--ok); }
.toast.warn { border-color: var(--warn); }
.toast button { min-height: 28px; padding: 2px 10px; border-color: var(--active); }

/* login */
#login { position: fixed; inset: 0; background: var(--bg); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: min(340px, 100%); display: flex; flex-direction: column; gap: 10px; }
.login-box input { font-size: 16px; }
.login-logo { width: 96px; height: 96px; align-self: center; margin-bottom: 4px; }
.login-title { text-align: center; font-size: 18px; margin-bottom: 10px; }
.login-err { color: var(--err); text-align: center; min-height: 20px; }

/* "⋯" sheet */
.sheet.more { gap: 10px; padding-top: 10px; }
.sheet .grip { width: 40px; height: 4px; background: var(--border); align-self: center; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tile { height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 12px; padding: 4px; }
.tile .glyph { font: 16px var(--mono); }
.toggles { border: 1px solid var(--border-soft); }
.toggles .set-row { padding: 0 12px; min-height: 48px; border-bottom: 1px solid var(--border-soft); }
.toggles .set-row:last-child { border-bottom: none; }

/* theme row in the ⋯ sheet, and the theme picker */
.toggles .theme-row { width: 100%; border: none; text-align: left; }
.th-cur { color: var(--muted); font-size: 13px; }
.th-list { display: flex; flex-direction: column; gap: 6px; max-height: 65vh; overflow-y: auto; }
.th-row { display: flex; align-items: center; gap: 12px; padding: 8px; min-height: 64px; border-color: var(--border-soft); }
.th-row.on { border-color: var(--active); }
.th-sample { flex: none; width: 112px; padding: 6px 8px; border: 1px solid; font: 12px/1.45 var(--mono); white-space: nowrap; overflow: hidden; }
.th-name { display: block; font-size: 14px; }
.th-swatches { display: flex; gap: 4px; margin-top: 6px; }
.th-swatches i { width: 12px; height: 12px; border-radius: 50%; }
.th-check { color: var(--active); font-size: 18px; padding: 0 4px; }

/* Build & Run commands editor */
.cmd-label { font-size: 12px; color: var(--muted); margin-bottom: -4px; }
textarea.cmd { width: 100%; font: 13px/1.4 var(--mono); resize: vertical; }
