:root {
  --bg: #0e1014;
  --panel: #161920;
  --panel2: #1d2129;
  --line: #2a2f3a;
  --text: #e6e8ee;
  --muted: #8b93a4;
  --accent: #3d8bfd;
  --ok: #2fbf71;
  --warn: #f0a020;
  --bad: #e5484d;
  --tile-w: 200px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { background: #262b36; border-color: #3a4150; }
button:disabled { opacity: .35; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #5599ff; }
input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  min-width: 0;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }

/* top bar */
.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top, 0px));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
.dot.on { background: var(--ok); }
.group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.right { margin-left: auto; }
.stat { color: var(--muted); font-variant-numeric: tabular-nums; }
.inline-form { display: flex; gap: 6px; align-items: center; }
.inline-form input:not([type=checkbox]) { flex: 1; width: 170px; }
.size { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.size input { width: 110px; padding: 0; }
.logout { color: var(--muted); text-decoration: none; }
.logout:hover { color: var(--text); }

.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 32px; height: 18px; border-radius: 9px; background: var(--line); position: relative; transition: background .15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
.switch input:checked + .track { background: var(--warn); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); }
body.sync .switch span:last-child { color: var(--warn); font-weight: 600; }

.banner { padding: 8px 14px; background: #3a2a10; color: #ffd08a; border-bottom: 1px solid #5a4318; }
.banner a { color: #fff; font-weight: 600; word-break: break-all; }

/* grid */
main { flex: 1; display: flex; min-height: 0; position: relative; }
.grid {
  flex: 1;
  overflow: auto;
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--tile-w));
  grid-auto-rows: max-content;
  gap: 12px;
  align-content: start;
}
.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--muted); }

.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tile.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
body.sync .tile.selected { border-color: var(--warn); box-shadow: 0 0 0 1px var(--warn); }
.tile.focused .tile-head { background: #24324a; }
.tile-head { display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 8px; min-height: 30px; }
.tile-head input { margin: 0; accent-color: var(--accent); width: 15px; height: 15px; padding: 0; }
.tile-name { font-weight: 600; cursor: text; white-space: nowrap; }
.tile-model { color: var(--muted); font-size: 11px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-zoom { padding: 1px 7px; line-height: 1.3; }

.screen { position: relative; background: #000; touch-action: none; user-select: none; -webkit-user-select: none; }
.screen canvas { display: block; width: 100%; height: auto; outline: none; cursor: default; }
.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; gap: 8px; align-items: center; justify-content: center;
  text-align: center; padding: 10px;
  background: rgba(10, 12, 16, .78); color: var(--muted); font-size: 12px;
}
.overlay .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.overlay .acts button { font-size: 12px; padding: 3px 8px; }

/* focus panel */
.focus {
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  min-height: 0;
  max-width: 70vw;
}
.focus-head { display: flex; align-items: center; gap: 8px; }
.focus-head strong { font-size: 15px; }
.spacer { flex: 1; }
.focus-body { display: flex; gap: 10px; flex: 1; min-height: 0; align-items: flex-start; }
.focus .screen { border-radius: 6px; overflow: hidden; flex: none; }
.focus .screen canvas { width: auto; height: auto; }
.focus .screen canvas:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.tools { display: flex; flex-direction: column; gap: 3px; overflow: hidden auto; max-height: 100%; scrollbar-width: thin; flex: none; }
.tools button { display: flex; flex-direction: column; align-items: center; width: 50px; padding: 3px 0; font-size: 15px; line-height: 1.1; }
.tools small { font-size: 11px; color: var(--muted); margin-top: 2px; }
.tools hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 2px 0; }
.check { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); white-space: nowrap; }
.check input { accent-color: var(--accent); }
.hint { margin: 0; color: var(--muted); font-size: 11px; }

/* dialog */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 0; width: min(520px, 92vw); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dlg { display: flex; flex-direction: column; gap: 10px; padding: 16px 18px; }
.dlg h3 { margin: 0; font-size: 15px; }
.dlg p { margin: 0; }
.dlg textarea { width: 100%; resize: vertical; font-family: ui-monospace, Consolas, monospace; }
.dlg-results { max-height: 220px; overflow: auto; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.dlg-results div { display: flex; gap: 8px; padding: 2px 0; }
.dlg-results .ok { color: var(--ok); }
.dlg-results .fail { color: var(--muted); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .4); z-index: 10; max-width: 90vw;
}

@media (max-width: 760px) {
  .bar { gap: 6px 10px; padding-inline: 10px; }
  .right { margin-left: 0; }
  .batch .inline-form input { width: 120px; }
  .grid { padding: 8px; gap: 8px; }
  .focus { position: absolute; inset: 0; max-width: none; z-index: 5; border-left: 0; }
  .focus-body { flex-direction: column; align-items: center; }
  .tools { flex-direction: row; flex-wrap: wrap; justify-content: center; max-height: none; }
  .tools hr { display: none; }
  .tools button { width: 46px; }
}
