:root {
  --bg: #07090c;
  --bg-2: #0b0f14;
  --panel: #111720;
  --panel-2: #161e29;
  --panel-3: #1c2633;
  --line: #253141;
  --line-soft: #1b2431;
  --text: #e8eff8;
  --muted: #8d9caf;
  --muted-2: #68788b;
  --accent: #4d8dff;
  --accent-2: #22d3a2;
  --danger: #ff6b6b;
  --warn: #f5b84b;
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Ubuntu, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(77, 141, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(34, 211, 162, 0.07), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line-soft);
  padding: 1px 5px;
  border-radius: 5px;
}
h1, h2, h3, p { margin: 0; }
h2 { font-size: 17px; letter-spacing: -0.01em; }
h3 { font-size: 13px; font-weight: 650; letter-spacing: 0.01em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.wrap { flex-wrap: wrap; }

/* top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 60px;
  padding: 0 20px;
  background: rgba(7, 9, 12, 0.82);
  border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.logo {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #7a5cff);
  color: #fff;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  box-shadow: 0 4px 14px rgba(77, 141, 255, 0.3);
}
.brand-name { font-weight: 700; letter-spacing: -0.01em; }
.badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(245, 184, 75, 0.14);
  color: var(--warn);
  border: 1px solid rgba(245, 184, 75, 0.3);
}
.device-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 6px 11px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.025);
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(245, 184, 75, 0.12);
  flex: none;
}
.dot.on { background: var(--accent-2); box-shadow: 0 0 0 3px rgba(34, 211, 162, 0.14); }
.dot.off { background: var(--danger); box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.14); }
.role-badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(77, 141, 255, 0.15);
  color: #9dbdff;
}
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.stat { font-family: var(--mono); font-size: 11.5px; color: var(--muted); min-width: 58px; text-align: right; }

/* buttons */
button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.2;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
button:hover { background: var(--panel-3); border-color: #31415a; }
button:active { transform: translateY(1px); }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid rgba(77, 141, 255, 0.6); outline-offset: 1px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #649cff; border-color: #649cff; }
button.ghost { background: transparent; }
button.danger { color: #ffb4b4; border-color: rgba(255, 107, 107, 0.25); }
button.danger:hover { background: rgba(255, 107, 107, 0.08); }
button.small { padding: 5px 9px; font-size: 11.5px; }
button.link { background: none; border: 0; padding: 0; color: var(--muted); font-size: 11.5px; }
button.link:hover { color: var(--text); text-decoration: underline; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

input[type="text"], input:not([type]), textarea, .pathbar input, .search, .copy-row input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
}
textarea { resize: vertical; min-height: 64px; font-family: var(--sans); }
input::placeholder, textarea::placeholder { color: var(--muted-2); }

/* tabs */
.tabs {
  display: flex;
  gap: 2px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(7, 9, 12, 0.6);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  position: relative;
  background: none;
  border: 0;
  border-radius: 0;
  color: var(--muted);
  padding: 12px 14px 11px;
  font-size: 13px;
}
.tabs button:hover { color: var(--text); background: none; }
.tabs button.active { color: var(--text); }
.tabs button.active::after {
  content: "";
  position: absolute;
  left: 10px; right: 10px; bottom: -1px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
}

main { padding: 18px 20px 40px; max-width: 1680px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0.4; transform: translateY(2px); } to { opacity: 1; transform: none; } }

/* screen */
.screen-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }
.stage-col { min-width: 0; }
.stage-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100dvh - 270px);
  min-height: 380px;
  max-height: 920px;
  padding: 12px;
  background: linear-gradient(180deg, #0b1016, #080b0f);
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  overflow: hidden;
}
.stage-shell:fullscreen { height: 100dvh; max-height: none; border: 0; border-radius: 0; background: #000; padding: 0; }
.stage {
  position: relative;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  width: 100%;
  height: 100%;
}
.stage-poster { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; background: #000; z-index: 1; opacity: 0; transition: opacity .2s; }
.stage-poster.show { opacity: 1; }
#screen { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; background: transparent; z-index: 2; opacity: 0; transition: opacity .2s; }
#stage.has-frame #screen { opacity: 1; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; z-index: 3; }
.stage-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: radial-gradient(500px 300px at 50% 40%, rgba(77, 141, 255, 0.1), transparent 70%), #05070a;
  color: var(--muted);
  text-align: center;
  padding: 24px;
  z-index: 4;
}
.stage-placeholder p { font-size: 14px; color: #c7d4e5; }
.stage-placeholder small { color: var(--muted-2); font-size: 11.5px; }
.spinner {
  width: 26px; height: 26px;
  border: 2px solid rgba(77, 141, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toolbar { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 12px; }
.toolbar button { padding: 7px 10px; font-size: 12px; background: var(--panel); }
.tool-sep { width: 1px; height: 24px; background: var(--line-soft); margin: 2px 3px; align-self: center; }
.stage-hint { margin-top: 9px; text-align: center; color: var(--muted-2); font-size: 11.5px; }

.side { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card h3 { color: #c7d4e5; }
.pill {
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(34, 211, 162, 0.1);
  color: var(--accent-2);
  border: 1px solid rgba(34, 211, 162, 0.22);
}
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 12.5px; }
.kv span { color: var(--muted); }
.kv strong { font-weight: 550; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter { height: 4px; background: var(--line-soft); border-radius: 4px; overflow: hidden; margin-top: 9px; }
.meter span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width 0.4s; }
.switch { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11.5px; cursor: pointer; user-select: none; }
.switch input { accent-color: var(--accent); }
.switch input:checked + span { color: var(--accent-2); }
body.readonly #overlay { pointer-events: none; cursor: default; }
body.readonly #toolbar { display: none; }
#text-input { margin-bottom: 8px; }
.card .row { justify-content: flex-end; }
.card p { margin-top: 8px; }
.log { font-family: var(--mono); font-size: 10.5px; line-height: 1.55; color: #9db0c7; max-height: 140px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0; }
.log .err { color: #ff9b9b; }
.log .ok { color: #7ee7c7; }

/* generic panels */
.panel { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { font-size: 16px; }

/* UI inspector */
.ui-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr); gap: 18px; align-items: start; }
.ui-stage { position: relative; background: #05070a; border: 1px solid var(--line-soft); border-radius: 10px; overflow: hidden; min-height: 320px; max-height: 78dvh; display: flex; align-items: center; justify-content: center; padding: 10px; }
.ui-frame { position: relative; display: flex; max-width: 100%; max-height: calc(78dvh - 22px); }
.ui-frame img { display: block; max-width: 100%; max-height: calc(78dvh - 22px); width: auto; height: auto; opacity: 0; border-radius: 6px; }
.ui-stage.ready .ui-frame img { opacity: 1; }
#ui-canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.ui-stage .stage-placeholder { z-index: 2; }
.check { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); user-select: none; }
.check input { accent-color: var(--accent); }
.tree-panel { min-height: 400px; }
.search { margin-bottom: 0; max-width: 230px; }
.tree { max-height: calc(100dvh - 290px); min-height: 300px; overflow: auto; font-family: var(--mono); font-size: 11.5px; }
.tree-node { padding: 3px 6px; border-radius: 5px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #a9bbd0; }
.tree-node:hover { background: rgba(77, 141, 255, 0.09); color: #dbe8f8; }
.tree-node .t { color: #e8eff8; }
.tree-node .c { color: var(--muted-2); }
.tree-node .id { color: #7fa7ff; }
.tree-node.clickable .t { color: #9fe7d2; }
.tree-node .b { color: #5f7288; }
.tree-empty { padding: 12px 6px; }

/* files */
.files-panel { padding-bottom: 8px; }
.pathbar { display: flex; gap: 8px; margin-bottom: 12px; }
.pathbar input { font-family: var(--mono); font-size: 12px; }
.file-drop { position: relative; border: 1px solid var(--line-soft); border-radius: 10px; overflow: auto; max-height: calc(100dvh - 330px); min-height: 300px; }
.file-drop.dragging { outline: 2px dashed var(--accent); outline-offset: -6px; background: rgba(77, 141, 255, 0.04); }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead th { position: sticky; top: 0; z-index: 2; background: var(--panel-2); color: var(--muted); font-weight: 550; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; padding: 8px 12px; border-bottom: 1px solid var(--line-soft); }
tbody td { padding: 7px 12px; border-bottom: 1px solid rgba(37, 49, 65, 0.5); vertical-align: middle; }
tbody tr:hover { background: rgba(255, 255, 255, 0.022); }
tbody tr:last-child td { border-bottom: 0; }
.file-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.file-name .ico { width: 18px; text-align: center; flex: none; opacity: 0.85; }
.file-name .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 48vw; }
.file-name.dir .nm { color: #9fc2ff; cursor: pointer; }
.file-name.dir .nm:hover { text-decoration: underline; }
.size, .when { color: var(--muted); font-family: var(--mono); font-size: 11px; white-space: nowrap; }
.actions-col { text-align: right; }
.file-actions { display: flex; gap: 4px; justify-content: flex-end; }
.file-actions button, .file-actions a {
  padding: 3px 7px; font-size: 10.5px; border-radius: 5px; text-decoration: none;
  border: 1px solid var(--line-soft); background: transparent; color: var(--muted);
}
.file-actions a:hover, .file-actions button:hover { color: var(--text); border-color: var(--line); }
.drop-hint { display: none; position: sticky; bottom: 0; padding: 8px; text-align: center; font-size: 11px; color: var(--muted-2); background: var(--panel); }
.file-drop.dragging .drop-hint { display: block; }
.upload-panel { display: flex; align-items: center; gap: 10px; padding: 10px 2px 4px; font-size: 12px; color: var(--muted); }
.upload-panel progress { flex: 1; height: 6px; accent-color: var(--accent); }
.upload-panel span:first-child { max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* shell */
.terminal {
  background: #05070a;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 14px;
  min-height: 340px;
  max-height: calc(100dvh - 390px);
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  color: #b7c8dc;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 12px;
}
.terminal .cmd { color: #7fa7ff; }
.terminal .err { color: #ff9b9b; }
.terminal .dim { color: #61738a; }
.shell-form { display: flex; align-items: center; gap: 8px; }
.shell-form .prompt { color: var(--accent-2); font-family: var(--mono); }
.shell-form input { font-family: var(--mono); font-size: 12.5px; }
.shell-form button { flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chips button { padding: 4px 8px; font-size: 11px; border-radius: 999px; color: var(--muted); background: transparent; }

/* share */
.share-panel { max-width: 980px; }
.copy-row { display: flex; gap: 8px; margin: 14px 0 6px; }
.share-pin-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 0 2px; font-size: 12.5px; }
.share-pin-row strong { font-family: var(--mono); font-size: 18px; letter-spacing: 0.18em; color: var(--accent-2); }
.share-pin-row .tiny { flex: 1 1 240px; }
.copy-row input { font-family: var(--mono); font-size: 12px; }
.copy-row button { flex: none; }
.share-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.share-box { border: 1px solid var(--line-soft); background: var(--bg-2); border-radius: 10px; padding: 13px; }
.share-box h3 { margin-bottom: 6px; color: #c7d4e5; }
.share-box p { color: var(--muted); font-size: 12.5px; line-height: 1.55; }
#share-status { min-height: 18px; }

/* toasts */
#toasts { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 36px)); }
.toast {
  background: #141c27;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 9px;
  padding: 10px 13px;
  font-size: 12.5px;
  color: #d9e5f5;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  animation: slide 0.2s ease;
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--accent-2); }
@keyframes slide { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* login */
.login-body { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.login-card {
  width: 100%;
  max-width: 430px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 18px;
  padding: 26px;
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.5);
}
.login-card .logo { width: 46px; height: 30px; font-size: 12px; }
.login-card h1 { font-size: 21px; margin: 18px 0 6px; letter-spacing: -0.02em; }
.login-card p { color: var(--muted); font-size: 13px; line-height: 1.55; }
.login-card form { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.login-card input { font-family: var(--mono); font-size: 13px; padding: 11px; }
.login-card button { padding: 11px; font-size: 14px; }
.login-error { min-height: 18px; color: #ff9b9b; font-size: 12.5px; }
.login-note { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line-soft); }

/* responsive */
@media (max-width: 1150px) {
  .screen-grid { grid-template-columns: 1fr; }
  .side { display: grid; grid-template-columns: 1fr 1fr; }
  .side .card:last-child { grid-column: 1 / -1; }
  .stage-shell { height: auto; min-height: 0; max-height: none; padding: 10px; }
  .stage { height: auto; }
  .ui-grid { grid-template-columns: 1fr; }
  .tree { max-height: 420px; }
}
@media (max-width: 720px) {
  .topbar { padding: 0 12px; gap: 8px; height: 54px; }
  .brand-name { display: none; }
  .device-chip { max-width: 46vw; font-size: 11.5px; padding: 5px 9px; }
  .stat { display: none; }
  main { padding: 12px 12px 32px; }
  .tabs { padding: 0 8px; }
  .tabs button { padding: 11px 11px 10px; font-size: 12.5px; }
  .stage-shell { padding: 6px; border-radius: 12px; }
  .toolbar button { padding: 6px 8px; font-size: 11px; }
  .tool-sep { display: none; }
  .side { grid-template-columns: 1fr; }
  .side .card:last-child { grid-column: auto; }
  .panel { padding: 12px; }
  .file-name .nm { max-width: 34vw; }
  .when { display: none; }
  thead th:nth-child(3), tbody td:nth-child(3) { display: none; }
  .copy-row { flex-wrap: wrap; }
  .copy-row input { flex: 1 1 100%; }
  .share-grid { grid-template-columns: 1fr; }
  .terminal { min-height: 260px; max-height: 48dvh; }
  #rtt, #kbps { display: none; }
}
