:root {
  --bg: #15171b;
  --bg-2: #1b1e24;
  --bg-3: #21252c;
  --line: #2c313a;
  --text: #dfe3ea;
  --muted: #8b93a1;
  --accent: #4aa3ff;
  --accent-2: #2b7fd4;
  --error: #f2544b;
  --warning: #d8a022;
  --success: #3fb98a;
  --radius: 10px;
  --tap: 44px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  overscroll-behavior: none;
}

.hidden { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 13px; }

.icon { display: block; flex: 0 0 auto; }

.screen { display: none; }
.screen.active {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  min-height: 52px;
}

.topbar .title { font-weight: 600; font-size: 16px; }

.file-title {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  max-width: 38vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dirty-dot { color: var(--warning); }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  min-width: var(--tap);
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
}
.icon-btn:active { background: var(--bg-3); }
.icon-btn.danger { color: var(--error); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-3);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.accent { background: var(--success); border-color: var(--success); color: #06231a; font-weight: 600; }
.btn.danger { color: var(--error); border-color: #4a2a2a; }
.btn.wide { width: 100%; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 13px; }
.btn .label { white-space: nowrap; }

.scroll { flex: 1; min-height: 0; overflow: auto; padding: 10px; }
.bottom-bar {
  padding: 10px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}

.login-card {
  margin: auto;
  width: min(420px, 92vw);
  padding: 20px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; }
.brand-mark { color: var(--accent); }
.field { display: block; margin: 14px 0; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.error-text { color: var(--error); font-size: 13px; min-height: 18px; margin: 8px 0 0; }

.list { display: flex; flex-direction: column; gap: 8px; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card .grow { flex: 1; min-width: 0; }
.card .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card .lead { color: var(--accent); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.ok { color: var(--success); border-color: #24503f; }
.badge.err { color: var(--error); border-color: #4a2a2a; }
.badge.warn { color: var(--warning); border-color: #4a3e21; }
.badge.run { color: var(--accent); border-color: #23405e; }

.note {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: var(--radius);
  background: #1a2530;
  border: 1px solid #24405c;
  color: #b8cee0;
  font-size: 13px;
}

.editor-wrap { position: relative; flex: 1; min-height: 0; }
#editor-host { position: absolute; inset: 0; }
.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  background: var(--bg);
  pointer-events: none;
}

.quick-keys {
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.quick-keys::-webkit-scrollbar { display: none; }
.quick-keys button {
  min-width: 44px;
  height: 40px;
  padding: 0 10px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-3);
  color: var(--text);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 14px;
}
.quick-keys button:active { background: var(--accent-2); }

.panel {
  position: absolute;
  background: var(--bg-2);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 20;
  transition: transform .18s ease;
}
.panel.side {
  top: 0;
  bottom: 0;
  left: 0;
  width: min(320px, 86vw);
  transform: translateX(-102%);
  padding-top: env(safe-area-inset-top);
}
.panel.side.open { transform: translateX(0); }
.panel.bottom {
  left: 0;
  right: 0;
  bottom: 0;
  height: min(62dvh, 520px);
  transform: translateY(102%);
  padding-bottom: env(safe-area-inset-bottom);
}
.panel.bottom.open { transform: translateY(0); }

.panel-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  min-height: 48px;
}
.panel-head .title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.panel-body { flex: 1; min-height: 0; overflow: auto; }
.panel-foot { padding: 8px 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-page { display: none; height: 100%; }
.tab-page.active { display: block; }

#tab-log {
  margin: 0;
  padding: 10px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: #c8cfda;
  overflow: auto;
}
#tab-log .ln-error { color: var(--error); }
#tab-log .ln-warn { color: var(--warning); }
#tab-log .ln-ok { color: var(--success); }
#tab-log .ln-sys { color: var(--accent); }

#tab-problems, #tab-artifacts, #deps-host, #history-host, #tree-host { padding: 8px; overflow: auto; }

.diag {
  display: flex;
  gap: 10px;
  width: 100%;
  text-align: left;
  align-items: flex-start;
  padding: 10px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--error);
  border-radius: 8px;
  background: var(--bg-3);
  color: var(--text);
  font-size: 13px;
}
.diag.warning { border-left-color: var(--warning); }
.diag .code { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--muted); }
.diag .msg { margin-top: 3px; line-height: 1.4; }
.diag .where { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--accent); }

.tree-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 38px;
  padding: 4px 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  text-align: left;
}
.tree-row:active { background: var(--bg-3); }
.tree-row.active { background: #223349; }
.tree-row.dir { color: #cbd3de; font-weight: 500; }
.tree-row .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .size { font-size: 11px; color: var(--muted); }
.tree-row .lead { color: var(--muted); }
.tree-row.dir .lead { color: var(--accent); }

.dep-group { margin-bottom: 14px; }
.dep-group h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.dep-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-3);
  font-size: 13px;
}
.dep-row .grow { flex: 1; min-width: 0; }
.dep-row .path {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dep-row.missing { border-color: #4a2a2a; }
.dep-row.missing .path { color: var(--error); }
.dep-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }

.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px; color: var(--muted); word-break: break-all; }

.toast-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(78px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 90;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 90vw;
  padding: 10px 14px;
  border-radius: 999px;
  background: #262b33;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
}
.toast.err { border-color: #4a2a2a; color: #ffb9b4; }
.toast.ok { border-color: #24503f; color: #b6f0d8; }

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .6);
  z-index: 100;
  padding: 16px;
}
.modal.open { display: flex; }
.modal-card {
  width: min(420px, 94vw);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.modal-head { padding: 14px 16px; font-weight: 600; border-bottom: 1px solid var(--line); }
.modal-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.modal-body input, .modal-body select {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
.modal-body p { margin: 0; font-size: 13px; color: var(--muted); }
.modal-foot { display: flex; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.modal-foot .btn { flex: 1; }

@media (min-width: 900px) {
  .panel.side { transform: translateX(0); position: relative; width: 300px; }
  #screen-editor.active { flex-direction: column; }
}
