/* Code - editor */
.app-code {
  --code-font: 13.5px;
  --cd-bg: #161b26; --cd-side: #1b212d; --cd-tab: #1b212d; --cd-line: rgba(255, 255, 255, .07);
  --cd-gutter: rgba(238, 241, 247, .32); --cd-active: rgba(255, 255, 255, .035); --cd-sel: rgba(var(--accent-rgb), .30);
  --cd-acc: #3b9cf6;
  --t-kw: #c792ea; --t-str: #c3e88d; --t-num: #f78c6c; --t-com: #6f7d95; --t-def: #82aaff; --t-var: #e6e9f0; --t-var2: #f07178;
  --t-prop: #7fdbca; --t-tag: #f07178; --t-attr: #ffcb6b; --t-type: #ffcb6b; --t-op: #89ddff; --t-head: #82aaff; --t-link: #7fdbca; --t-err: #ff5370;
  position: relative; background: var(--cd-bg);
}
[data-theme="light"] .app-code {
  --cd-bg: #ffffff; --cd-side: #f4f6fa; --cd-tab: #f4f6fa; --cd-line: rgba(10, 20, 40, .08);
  --cd-gutter: rgba(21, 26, 37, .36); --cd-active: rgba(10, 20, 40, .035); --cd-sel: rgba(var(--accent-rgb), .22);
  --cd-acc: #1e6fd9;
  --t-kw: #8839ef; --t-str: #2f8a2d; --t-num: #c2410c; --t-com: #8a93a5; --t-def: #1e5bd8; --t-var: #1d2433; --t-var2: #c7254e;
  --t-prop: #0b7a75; --t-tag: #c7254e; --t-attr: #a15c00; --t-type: #a15c00; --t-op: #0d7fb3; --t-head: #1e5bd8; --t-link: #0b7a75; --t-err: #d20f39;
}
.win .code-run { gap: 5px; }
.win .code-run .ic { color: #22c55e; }

.app-code .code-split { flex: 1; display: flex; min-height: 0; }
.app-code [hidden] { display: none !important; }
.app-code .code-side { width: 230px; flex: 0 0 auto; display: flex; flex-direction: column; background: var(--cd-side); min-width: 0; }
.app-code.code-no-side .code-side, .app-code.code-no-side .code-resizer.side { display: none; }
.app-code .code-side-head { height: 38px; display: flex; align-items: center; gap: 2px; padding: 0 4px 0 6px; flex: 0 0 auto; border-bottom: 1px solid var(--cd-line); }
.app-code .code-side-head .icon-btn { width: 26px; height: 26px; border-radius: 7px; color: var(--text-2); }
.app-code .code-root { display: flex; align-items: center; gap: 6px; min-width: 0; border: 0; background: none; color: var(--text); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 4px 6px; border-radius: 7px; }
.app-code .code-root:hover { background: var(--hover); }
.app-code .code-root span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-code .code-root .ic:first-child { color: var(--cd-acc); }
.app-code .code-tree { flex: 1; padding: 4px 0 20px; outline: none; }
.app-code .code-node { height: 26px; display: flex; align-items: center; gap: 5px; padding-right: 8px; font-size: 13px; color: var(--text); cursor: default; white-space: nowrap; outline: none; }
.app-code .code-node:hover { background: var(--hover); }
.app-code .code-node:focus-visible { box-shadow: inset 0 0 0 1px var(--cd-acc); }
.app-code .code-node.on { background: rgba(var(--accent-rgb), .16); }
.app-code .code-node.dir > .ic { color: var(--cd-acc); }
.app-code .code-node-name { overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.app-code .code-chev { width: 13px; display: grid; color: var(--text-3); transition: transform .12s; flex: 0 0 auto; }
.app-code .code-chev.open { transform: rotate(90deg); }
.app-code .code-fic { display: grid; flex: 0 0 auto; }
.app-code .code-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-2); flex: 0 0 auto; }
.app-code .code-tree-empty { padding: 20px 14px; font-size: 12.5px; text-align: center; }

.app-code .code-resizer { flex: 0 0 auto; background: var(--cd-line); position: relative; z-index: 2; touch-action: none; }
.app-code .code-resizer.v { width: 1px; cursor: col-resize; }
.app-code .code-resizer.h { height: 1px; cursor: row-resize; }
.app-code .code-resizer::after { content: ''; position: absolute; inset: -3px; }
.app-code .code-resizer:hover, .app-code.code-dragging .code-resizer { background: var(--cd-acc); }
.app-code.code-dragging, .app-code.code-dragging iframe { user-select: none; pointer-events: none; }
.app-code.code-dragging .code-resizer { pointer-events: auto; }

.app-code .code-mainwrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-code .code-work { flex: 1; display: flex; min-height: 0; }
.app-code .code-center { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-code .code-preview { flex: 0 0 42%; min-width: 0; display: none; flex-direction: column; background: var(--cd-side); }
.app-code .code-resizer.v:not(.side) { display: none; }
.app-code.code-has-preview .code-preview { display: flex; }
.app-code.code-has-preview .code-resizer.v:not(.side) { display: block; }
.app-code .code-console, .app-code .code-resizer.h { display: none; }
.app-code.code-has-console .code-console { display: flex; }
.app-code.code-has-console .code-resizer.h { display: block; }

/* tabs */
.app-code .code-tabs { height: 36px; flex: 0 0 auto; display: flex; overflow-x: auto; overflow-y: hidden; background: var(--cd-tab); border-bottom: 1px solid var(--cd-line); scrollbar-width: none; }
.app-code .code-tabs::-webkit-scrollbar { display: none; }
.app-code .code-tab { display: flex; align-items: center; gap: 6px; padding: 0 6px 0 12px; font-size: 12.5px; color: var(--text-2); border-right: 1px solid var(--cd-line); white-space: nowrap; flex: 0 0 auto; max-width: 220px; position: relative; outline: none; }
.app-code .code-tab:hover { background: var(--hover); }
.app-code .code-tab.on { background: var(--cd-bg); color: var(--text); }
.app-code .code-tab.on::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--cd-acc); }
.app-code .code-tab.on::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: var(--cd-bg); }
.app-code .code-tab:focus-visible { box-shadow: inset 0 0 0 1px var(--cd-acc); }
.app-code .code-tab-name { overflow: hidden; text-overflow: ellipsis; }
.app-code .code-tab-x { width: 20px; height: 20px; border: 0; background: none; border-radius: 5px; display: grid; place-items: center; color: var(--text-3); padding: 0; opacity: 0; }
.app-code .code-tab:hover .code-tab-x, .app-code .code-tab.on .code-tab-x, .app-code .code-tab.dirty .code-tab-x { opacity: 1; }
.app-code .code-tab-x:hover { background: var(--press); color: var(--text); }
.app-code .code-tab-x .code-dot { display: none; }
.app-code .code-tab.dirty .code-tab-x .code-dot { display: block; }
.app-code .code-tab.dirty .code-tab-x .ic { display: none; }
.app-code .code-tab.dirty .code-tab-x:hover .code-dot { display: none; }
.app-code .code-tab.dirty .code-tab-x:hover .ic { display: block; }

/* editor */
.app-code .code-edwrap { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.app-code .code-editor { flex: 1; min-height: 0; position: relative; }
.app-code .code-editor .CodeMirror { position: absolute; inset: 0; height: auto; font-family: var(--mono); font-size: var(--code-font); line-height: 1.55; }
.app-code .code-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--text-2); font-size: 13px; background: var(--cd-bg); z-index: 5; }

.cm-s-newos.CodeMirror { background: var(--cd-bg); color: var(--t-var); }
.cm-s-newos .CodeMirror-gutters { background: var(--cd-bg); border-right: 0; }
.cm-s-newos .CodeMirror-linenumber { color: var(--cd-gutter); padding: 0 10px 0 14px; }
.cm-s-newos .CodeMirror-activeline-background { background: var(--cd-active); }
.cm-s-newos .CodeMirror-activeline-gutter .CodeMirror-linenumber { color: var(--text); }
.cm-s-newos .CodeMirror-cursor { border-left: 2px solid var(--cd-acc); }
.cm-s-newos div.CodeMirror-selected, .cm-s-newos.CodeMirror-focused div.CodeMirror-selected { background: var(--cd-sel); }
.cm-s-newos .CodeMirror-line::selection, .cm-s-newos .CodeMirror-line > span::selection, .cm-s-newos .CodeMirror-line > span > span::selection { background: var(--cd-sel); }
.cm-s-newos .CodeMirror-matchingbracket { color: inherit !important; background: rgba(var(--accent-rgb), .22); outline: 1px solid rgba(var(--accent-rgb), .55); }
.cm-s-newos .CodeMirror-nonmatchingbracket { color: var(--t-err) !important; }
.cm-s-newos .cm-matchhighlight { background: rgba(var(--accent-rgb), .14); border-radius: 2px; }
.cm-s-newos .cm-searching { background: rgba(255, 196, 0, .35); border-radius: 2px; }
.cm-s-newos .CodeMirror-foldgutter-open, .cm-s-newos .CodeMirror-foldgutter-folded { color: var(--text-3); }
.cm-s-newos .CodeMirror-foldmarker { color: var(--cd-acc); text-shadow: none; font-family: inherit; background: rgba(var(--accent-rgb), .15); border-radius: 4px; padding: 0 4px; }
.cm-s-newos .cm-keyword { color: var(--t-kw); }
.cm-s-newos .cm-string { color: var(--t-str); }
.cm-s-newos .cm-string-2 { color: var(--t-var2); }
.cm-s-newos .cm-number, .cm-s-newos .cm-atom { color: var(--t-num); }
.cm-s-newos .cm-comment { color: var(--t-com); font-style: italic; }
.cm-s-newos .cm-def { color: var(--t-def); }
.cm-s-newos .cm-variable { color: var(--t-var); }
.cm-s-newos .cm-variable-2 { color: var(--t-var2); }
.cm-s-newos .cm-variable-3, .cm-s-newos .cm-type { color: var(--t-type); }
.cm-s-newos .cm-property { color: var(--t-prop); }
.cm-s-newos .cm-operator { color: var(--t-op); }
.cm-s-newos .cm-tag { color: var(--t-tag); }
.cm-s-newos .cm-attribute { color: var(--t-attr); }
.cm-s-newos .cm-builtin, .cm-s-newos .cm-qualifier { color: var(--t-type); }
.cm-s-newos .cm-meta { color: var(--t-op); }
.cm-s-newos .cm-bracket { color: var(--text-2); }
.cm-s-newos .cm-header { color: var(--t-head); font-weight: 700; }
.cm-s-newos .cm-link, .cm-s-newos .cm-url { color: var(--t-link); }
.cm-s-newos .cm-quote { color: var(--t-com); font-style: italic; }
.cm-s-newos .cm-em { font-style: italic; }
.cm-s-newos .cm-strong { font-weight: 700; }
.cm-s-newos .cm-error { color: var(--t-err); }
.cm-s-newos .CodeMirror-search-match { background: rgba(255, 196, 0, .35); }
.cm-s-newos .CodeMirror-scrollbar-filler, .cm-s-newos .CodeMirror-gutter-filler { background: transparent; }

/* search / jump dialog (CodeMirror dialog addon) */
.app-code .CodeMirror-dialog { background: var(--surface-2); color: var(--text); border-color: var(--line-2) !important; padding: 7px 12px; font-family: var(--font); font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; z-index: 15; }
.app-code .CodeMirror-dialog input { flex: 1; min-width: 140px; height: 28px; width: auto !important; background: var(--surface); border: 0; border-radius: 7px; box-shadow: inset 0 0 0 1px var(--line-2); padding: 0 10px; font-family: var(--mono); font-size: 13px; color: var(--text); }
.app-code .CodeMirror-dialog input:focus { box-shadow: inset 0 0 0 2px var(--cd-acc); }
.app-code .CodeMirror-dialog button { height: 26px; padding: 0 10px; border: 0; border-radius: 7px; background: var(--tile); color: var(--text); font-size: 12px; font-weight: 600; }
.app-code .CodeMirror-dialog button:hover { background: var(--tile-hover); }
.app-code .CodeMirror-search-hint { color: var(--text-3); font-size: 12px; }
.app-code .CodeMirror-search-label { color: var(--text-2); }

/* hints (appended to body) */
.CodeMirror-hints { z-index: 100000; background: var(--glass-solid, #222838); border: 1px solid var(--line-2); border-radius: 9px; box-shadow: var(--shadow-pop); padding: 4px; font-family: var(--mono); font-size: 12.5px; max-height: 16em; }
.CodeMirror-hint { color: var(--text); border-radius: 6px; padding: 3px 8px; }
li.CodeMirror-hint-active { background: var(--accent); color: var(--accent-fg); }

/* image view + welcome */
.app-code .code-imgview { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 20px; overflow: auto; font-size: 12.5px; }
.app-code .code-img-checker { padding: 10px; border-radius: 10px; background: repeating-conic-gradient(var(--surface-3) 0% 25%, var(--surface-2) 0% 50%) 50% / 16px 16px; max-width: 100%; }
.app-code .code-img-checker img { display: block; max-width: 100%; max-height: 60vh; image-rendering: auto; }
.app-code .code-welcome { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 24px; }
.app-code .code-welcome-in { max-width: 560px; width: 100%; }
.app-code .code-welcome h2 { margin: 12px 0 2px; font-size: 26px; font-weight: 700; }
.app-code .code-welcome p { margin: 0 0 22px; }
.app-code .code-welcome-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.app-code .code-welcome h4 { margin: 0 0 8px; font-size: 13px; color: var(--text-2); }
.app-code .code-welcome-grid > div { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; font-size: 13.5px; }
.app-code .code-welcome .link { display: inline-flex; align-items: center; gap: 7px; color: var(--cd-acc); font-weight: 500; text-align: left; }
.app-code .code-keys { margin-top: 26px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 24px; font-size: 12.5px; }
.app-code .code-keys > div { display: flex; justify-content: space-between; align-items: center; }

/* panels */
.app-code .code-panel-head { height: 32px; flex: 0 0 auto; display: flex; align-items: center; gap: 4px; padding: 0 6px 0 12px; border-bottom: 1px solid var(--cd-line); font-size: 11.5px; }
.app-code .code-panel-head .icon-btn { width: 26px; height: 26px; border-radius: 7px; color: var(--text-2); }
.app-code .code-panel-head .btn-sm { height: 22px; padding: 0 8px; gap: 4px; }
.app-code .code-panel-title { display: flex; align-items: center; gap: 6px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); }
.app-code .code-pv-path { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-left: 4px; min-width: 0; }
.app-code .code-frame-wrap { flex: 1; min-height: 0; background: #fff; }
.app-code .code-frame { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.app-code .code-runframe { position: absolute; width: 0; height: 0; border: 0; visibility: hidden; }
.app-code .code-console { height: 180px; flex: 0 0 auto; flex-direction: column; background: var(--cd-side); min-height: 0; }
.app-code .code-con-out { flex: 1; padding: 4px 0; font-family: var(--mono); font-size: 12.5px; user-select: text; -webkit-user-select: text; }
.app-code .code-con-line { display: flex; gap: 8px; padding: 2px 12px; border-bottom: 1px solid var(--cd-line); }
.app-code .code-con-line pre { margin: 0; white-space: pre-wrap; word-break: break-word; font: inherit; flex: 1; min-width: 0; }
.app-code .code-con-ic { width: 13px; flex: 0 0 auto; display: grid; padding-top: 2px; color: var(--text-3); }
.app-code .code-con-line.k-error { color: var(--t-err); background: rgba(229, 72, 77, .08); }
.app-code .code-con-line.k-error .code-con-ic { color: var(--t-err); }
.app-code .code-con-line.k-warn { color: #d29500; background: rgba(231, 164, 0, .08); }
.app-code .code-con-line.k-warn .code-con-ic { color: #d29500; }
.app-code .code-con-line.k-info .code-con-ic { color: var(--cd-acc); }
.app-code .code-con-line.k-result { color: var(--t-def); }
.app-code .code-con-line.k-input { color: var(--text-2); }
.app-code .code-con-line.k-system { color: var(--text-3); font-style: italic; }
.app-code .code-con-row { display: flex; align-items: center; gap: 6px; padding: 0 12px; border-top: 1px solid var(--cd-line); height: 30px; flex: 0 0 auto; color: var(--cd-acc); }
.app-code .code-con-in { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-family: var(--mono); font-size: 12.5px; color: var(--text); height: 100%; }

/* status bar */
.app-code .code-status { height: 24px; flex: 0 0 auto; display: flex; align-items: center; gap: 2px; padding: 0 8px; font-size: 11.5px; background: var(--cd-side); border-top: 1px solid var(--cd-line); color: var(--text-2); white-space: nowrap; overflow: hidden; }
.app-code .code-status button, .app-code .code-status > span { border: 0; background: none; color: inherit; font-size: inherit; padding: 2px 7px; border-radius: 5px; }
.app-code .code-status button:hover { background: var(--hover); color: var(--text); }
.app-code .code-st-path { overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* palette + sheets */
.app-code .code-pal-layer, .app-code .code-sheet-layer { position: absolute; inset: 0; z-index: 30; display: flex; justify-content: center; align-items: flex-start; padding: 50px 16px 16px; }
.app-code .code-sheet-layer { background: rgba(0, 0, 0, .25); }
.app-code .code-pal { width: min(560px, 100%); border-radius: 14px; padding: 8px; display: flex; flex-direction: column; gap: 6px; background: var(--glass-strong); max-height: 70%; animation: code-drop .14s ease; }
.app-code .code-pal .input { height: 36px; font-size: 14px; }
.app-code .code-pal-list { display: flex; flex-direction: column; max-height: 360px; }
.app-code .code-pal-row { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 10px; border: 0; background: none; border-radius: 8px; color: var(--text); font-size: 13px; text-align: left; flex: 0 0 auto; }
.app-code .code-pal-row.on { background: rgba(var(--accent-rgb), .2); }
.app-code .code-pal-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-code .code-pal-row small { color: var(--text-3); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.app-code .code-pal-row .kbd { margin-left: auto; flex: 0 0 auto; }
.app-code .code-pal-empty { padding: 14px; text-align: center; font-size: 13px; }
.app-code .code-sheet { width: min(440px, 100%); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: var(--glass-strong); max-height: 100%; }
.app-code .code-sheet h3 { margin: 0; font-size: 16px; }
.app-code .code-fold-crumb { font-size: 12px; }
.app-code .code-fold-list { height: 260px; display: flex; flex-direction: column; border-radius: 10px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); padding: 4px; }
.app-code .code-fold-row { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 10px; border: 0; background: none; border-radius: 7px; color: var(--text); font-size: 13px; text-align: left; flex: 0 0 auto; }
.app-code .code-fold-row span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-code .code-fold-row:hover { background: var(--hover); }
.app-code .code-fold-row.sel { background: var(--accent); color: var(--accent-fg); }
.app-code .code-fold-row .ic:first-child { color: var(--cd-acc); }
.app-code .code-fold-row.sel .ic { color: inherit; }
.app-code .code-sheet-actions { display: flex; gap: 8px; }
@keyframes code-drop { from { opacity: 0; transform: translateY(-8px); } }

/* phone */
@media (max-width: 759px) {
  .app-code .code-side { position: absolute; left: 0; top: 0; bottom: 0; z-index: 12; width: min(300px, 86vw) !important; box-shadow: var(--shadow-pop); }
  .app-code.code-has-preview .code-preview { position: absolute; inset: 0 0 24px 0; z-index: 11; flex-basis: auto !important; }
  .app-code .code-resizer { display: none !important; }
  .app-code .code-console { height: 42% !important; }
  .app-code .code-welcome-grid, .app-code .code-keys { grid-template-columns: 1fr; }
  .app-code .code-status .code-st-path { display: none; }
  .app-code .code-tab-x { opacity: 1; }
}
@media (max-width: 759px) {
  .win .code-run span { display: none; }
  .win .code-run { width: 32px; padding: 0; }
}
