:root {
  --accent: #0519b0;
  --accent-hover: #04148f;
  --accent-soft: #eef0fc;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --ink: #16181d;
  --ink-2: #4a505c;
  --ink-3: #7b8190;
  --line: #e3e6ec;
  --line-2: #eef0f4;
  --red: #c4321c;
  --red-soft: #fdeeeb;
  --amber: #a66300;
  --amber-soft: #fff5e0;
  --green: #17803d;
  --radius: 8px;
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --display: "Plus Jakarta Sans", Inter, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 13px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); cursor: pointer; font-weight: 500; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--line-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--line-2); }
.btn-danger-ghost { color: var(--red); }
.btn-danger-ghost:hover { background: var(--red-soft); border-color: #f3c9c1; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-xs { height: 22px; padding: 0 8px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; height: 38px; }
.icon-btn { width: 30px; height: 30px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 6px; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--line-2); color: var(--ink); }
.sel-sm { height: 28px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 0 8px; font-size: 12.5px; max-width: 210px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px 24px; }
.login-card h1 { font: 700 20px/1.2 var(--display); margin: 12px 0 4px; }
.login-card p { margin: 0 0 20px; color: var(--ink-2); }
.login-card label { display: block; font-weight: 500; margin-bottom: 6px; }
.pin-wrap { position: relative; }
.pin-wrap input { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: var(--radius); padding: 0 44px 0 12px; font-size: 16px; letter-spacing: .1em; }
.pin-eye { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; font-size: 1.125rem; }
.login-err { color: var(--red); min-height: 20px; margin: 6px 0 8px; font-size: 12.5px; }

/* app shell */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { height: 52px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font: 700 15px var(--display); margin-right: 6px; }
.nav-btns { display: flex; gap: 2px; }
.url-form { flex: 1; display: flex; gap: 6px; min-width: 0; }
.url-form input { flex: 1; min-width: 0; height: 32px; border: 1px solid var(--line); border-radius: var(--radius); padding: 0 12px; background: var(--bg); }
.url-form input:focus { background: var(--surface); border-color: var(--accent); outline: none; }
.status-pill { font-size: 12px; color: var(--ink-2); background: var(--line-2); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.status-pill.full { background: var(--amber-soft); color: var(--amber); }

.body { flex: 1; min-height: 0; display: grid; grid-template-columns: 280px 1fr 300px; }

/* sidebar */
.sidebar { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.device-select { display: none; }
.device-list { flex: 1; overflow-y: auto; padding: 8px; }
.dl-group { font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 12px 8px 4px; }
.dl-item { width: 100%; text-align: left; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 8px 10px; border: 1px solid transparent; border-radius: var(--radius); background: none; cursor: pointer; }
.dl-item:hover { background: var(--bg); }
.dl-item.active { background: var(--accent-soft); border-color: #d3d8f6; }
.dl-name { font-weight: 500; color: var(--ink); }
.dl-tags { display: flex; gap: 4px; align-items: center; }
.dl-note { grid-column: 1 / -1; font-size: 12px; color: var(--ink-3); line-height: 1.35; }
.tag { font-size: 11px; font-weight: 600; border-radius: 999px; padding: 1px 7px; line-height: 16px; }
.tag-p1 { background: var(--red-soft); color: var(--red); }
.tag-p2 { background: var(--amber-soft); color: var(--amber); }
.tag-p3 { background: var(--line-2); color: var(--ink-3); }
.tag-engine { background: var(--line-2); color: var(--ink-2); font-weight: 500; }
.side-foot { padding: 10px 14px; font-size: 12px; color: var(--ink-3); border-top: 1px solid var(--line-2); }

/* stage */
.stage-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { flex: none; display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.tb-info { flex: 1; min-width: 160px; }
.tb-name { font-weight: 600; }
.tb-sub { font-size: 12px; color: var(--ink-3); }
.tb-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 16px; overflow: hidden; }
.frame { position: relative; background: #1d2027; border-radius: 22px; padding: 10px; box-shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08); }
.frame.desktop { border-radius: 10px; padding: 22px 6px 6px; }
.frame.desktop::before { content: ""; position: absolute; top: 8px; left: 10px; width: 34px; height: 6px; background: radial-gradient(circle, #555b66 3px, transparent 3.5px) 0 0 / 12px 6px repeat-x; }
.frame.idle { width: min(393px, 90%); aspect-ratio: 393 / 659; }
#screen { display: block; background: #fff; border-radius: 12px; touch-action: none; cursor: default; outline: none; }
.frame.desktop #screen { border-radius: 4px; }
.frame.touch #screen { cursor: pointer; }
#screen:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.overlay { position: absolute; inset: 10px; display: grid; place-items: center; background: rgba(245, 247, 250, .92); border-radius: 12px; padding: 16px; }
.ov-card { text-align: center; max-width: 280px; }
.ov-title { font: 700 15px var(--display); margin-bottom: 6px; }
.ov-text { color: var(--ink-2); margin-bottom: 14px; font-size: 12.5px; }
.spinner { width: 22px; height: 22px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

.typebar { flex: none; display: flex; gap: 6px; padding: 8px 14px; border-top: 1px solid var(--line); background: var(--surface); }
.typebar input { flex: 1; min-width: 0; height: 28px; border: 1px solid var(--line); border-radius: var(--radius); padding: 0 10px; font-size: 12.5px; }
.file-banner { flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: var(--amber-soft); color: var(--amber); font-weight: 500; border-top: 1px solid #f2dfb5; }

/* console */
.console { background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.console-head { flex: none; display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line-2); font-weight: 600; }
.console-head .btn { margin-left: auto; }
.badge { font-size: 11px; background: var(--line-2); color: var(--ink-2); border-radius: 999px; padding: 0 7px; line-height: 18px; font-weight: 600; }
.badge.has { background: var(--red-soft); color: var(--red); }
.console-body { flex: 1; overflow-y: auto; font-size: 12px; }
.console-empty { padding: 14px 12px; color: var(--ink-3); }
.log { padding: 6px 12px; border-bottom: 1px solid var(--line-2); word-break: break-word; display: grid; grid-template-columns: 40px 1fr; gap: 6px; }
.log time { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.log.error { background: #fffafa; color: var(--red); }
.log.warn { color: var(--amber); }
.log.info { color: var(--ink-2); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 14px; border-radius: var(--radius); font-size: 12.5px; z-index: 50; }

/* responsive */
@media (max-width: 1180px) {
  .body { grid-template-columns: 250px 1fr; }
  .console { display: none; }
}
@media (max-width: 760px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
  .brand span, .status-pill { display: none; }
  #btn-logout { margin-left: auto; }
  .url-form { order: 5; flex-basis: 100%; }
  .body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .device-list, .side-foot { display: none; }
  .device-select { display: block; margin: 8px 12px; height: 36px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 0 10px; }
  .toolbar { padding: 8px 12px; }
  .tb-actions .btn-sm { padding: 0 8px; }
  .stage { padding: 10px; }
  .typebar { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}
