:root {
  --ground: #F6F7F8;
  --surface: #FFFFFF;
  --session: #ECEEF0;
  --screen-frame: #E7E9EC;
  --ink: #272B30;
  --quiet: #5C636B;
  --accent: #3D5A73;
  --ok: #2F7D5B;
  --warn: #A8612A;
  --off: #9AA0A7;
  --line: rgba(22, 26, 30, .07);
  --line-strong: rgba(22, 26, 30, .12);
  --shadow: 0 1px 2px rgba(22, 26, 30, .04), 0 8px 24px rgba(22, 26, 30, .06);
  --shadow-hover: 0 1px 2px rgba(22, 26, 30, .05), 0 14px 34px rgba(22, 26, 30, .10);
  --shadow-pop: 0 2px 4px rgba(22, 26, 30, .06), 0 24px 60px rgba(22, 26, 30, .18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ground);
  color: var(--ink);
  font: 300 14px/1.6 Inter, "PingFang SC", "Microsoft YaHei Light", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, p { margin: 0; font-weight: 300; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  height: 44px; padding: 0 16px; border: 1px solid rgba(22, 26, 30, .10); border-radius: 4px;
  background: var(--surface); font-weight: 400; white-space: nowrap;
}
.btn.primary {
  border: 0; background: var(--accent); color: #fff;
  box-shadow: 0 1px 2px rgba(22, 26, 30, .12), inset 0 1px 0 rgba(255, 255, 255, .14);
}
.btn.ghost { border: 0; background: transparent; font-weight: 300; }
.btn:disabled { opacity: .55; cursor: default; }
.input {
  height: 44px; width: 100%; padding: 0 12px; border: 1px solid var(--line-strong);
  border-radius: 4px; background: var(--surface);
}
.dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--off); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.status { display: flex; align-items: center; gap: 8px; color: var(--quiet); }

/* Login */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; padding: 28px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); box-shadow: var(--shadow);
}
.brand { font-size: 16px; font-weight: 400; letter-spacing: .01em; }
.login-card h1 { margin-top: 28px; font-size: 28px; line-height: 1.25; }
.fields { margin-top: 20px; display: flex; flex-direction: column; gap: 14px; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.login-card .btn { width: 100%; margin-top: 24px; }
.error { min-height: 22px; margin-top: 8px; color: #9A3B2E; font-size: 13px; }
.hint { margin-top: 8px; color: var(--quiet); }
.compare-code { margin-top: 20px; font-size: 32px; font-weight: 300; letter-spacing: .08em; line-height: 1.3; font-variant-numeric: tabular-nums; }
.link { display: block; margin-top: 12px; padding: 8px 0; min-height: 40px; border: 0; background: transparent; color: var(--quiet); font-size: 13px; cursor: pointer; }
.setup { margin-top: 16px; }
.page-foot { margin-top: 32px; }
.browser-list { margin-top: 8px; }
.browser-row { padding: 12px 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid rgba(22, 26, 30, .06); }
.browser-row .status { font-size: 13px; }

/* Pages */
.page { max-width: 1280px; margin: 0 auto; padding: 28px 40px 72px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.name-btn { display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px; border: 0; border-radius: 4px; background: transparent; }
.name-edit { display: flex; gap: 6px; }
.name-edit .input { width: 148px; }
.heading { margin-top: 56px; display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.heading h1, .detail-head h1 { font-size: 34px; line-height: 1.2; letter-spacing: -.01em; }
.heading .count { color: var(--quiet); }

.grid { margin-top: 32px; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 28px; }
.card {
  display: block; width: 100%; padding: 0; text-align: left; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); font-weight: 300; overflow: hidden; box-shadow: var(--shadow); transition: box-shadow .18s ease;
}
.card:hover { box-shadow: var(--shadow-hover); }
.thumb { aspect-ratio: 16 / 10; background: var(--screen-frame); padding: 12px; }
.thumb.offline { opacity: .6; }
.thumb-inner {
  width: 100%; height: 100%; border-radius: 4px; background: #1E2226; overflow: hidden;
  display: flex; align-items: center; justify-content: center; color: #8A929B; font-size: 12px;
}
.thumb.offline .thumb-inner { background: transparent; color: var(--quiet); }
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.card-body { padding: 14px 16px 16px; }
.card-name { font-size: 15px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-body .status { margin-top: 2px; font-size: 13px; white-space: nowrap; overflow: hidden; }

.empty {
  margin-top: 32px; padding: 32px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); box-shadow: var(--shadow);
}
.empty h2 { font-size: 22px; line-height: 1.3; }
.empty p { margin-top: 8px; color: var(--quiet); }

/* Detail */
.back { display: inline-flex; align-items: center; gap: 6px; height: 44px; margin-left: -12px; padding: 0 12px; border: 0; border-radius: 4px; background: transparent; color: var(--quiet); }
.detail-head { margin-top: 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.detail-head .status { margin-top: 4px; }
.detail-head .btn { padding: 0 24px; }
.preview {
  margin-top: 32px; padding: 16px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--screen-frame); box-shadow: 0 1px 2px rgba(22, 26, 30, .04), 0 12px 32px rgba(22, 26, 30, .07);
}
.preview .thumb-inner { aspect-ratio: 16 / 10; height: auto; }
.preview img { width: 100%; height: 100%; object-fit: contain; display: block; }
.preview.offline .thumb-inner { background: transparent; color: var(--quiet); font-size: 14px; }

/* Session: fills the viewport so remote pixels get all the room */
.session { position: fixed; inset: 0; display: flex; flex-direction: column; gap: 8px; padding: 8px; background: var(--session); padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.toolbar {
  flex: none; align-self: center; max-width: 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 2px; padding: 2px 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
  box-shadow: 0 1px 2px rgba(22, 26, 30, .04), 0 8px 24px rgba(22, 26, 30, .08);
}
.toolbar-tab { display: none; }
.session.full { padding: 0; gap: 0; background: #000; }
.session.full .stage { border-radius: 0; box-shadow: none; background: #000; }
.session.full .toolbar {
  position: absolute; z-index: 2; top: 8px; left: 50%; transform: translate(-50%, calc(-100% - 12px));
  transition: transform .18s ease; box-shadow: var(--shadow-pop);
}
.session.full .toolbar.shown, .session.full .toolbar:focus-within { transform: translate(-50%, 0); }
.session.full .toolbar-tab {
  display: block; position: absolute; z-index: 1; top: 0; left: 50%; width: 56px; height: 14px; transform: translateX(-50%);
  padding: 0; border: 0; border-radius: 0 0 4px 4px; background: rgba(255, 255, 255, .55);
}
.session.full > div:last-child { position: absolute; z-index: 2; left: 8px; right: 8px; bottom: 8px; }
.tool { height: 44px; min-width: 44px; padding: 0 10px; border: 0; border-radius: 4px; background: transparent; font-size: 13px; font-weight: 300; white-space: nowrap; }
.tool[aria-pressed="true"] { background: rgba(61, 90, 115, .10); }
.tool.icon { display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.tool.end { height: 36px; margin: 0 4px; padding: 0 14px; background: var(--accent); color: #fff; font-weight: 400; }
.tool-name { padding: 0 8px 0 2px; font-weight: 400; white-space: nowrap; }
.tool-status { padding: 0 10px; font-size: 13px; white-space: nowrap; }
.stage {
  position: relative; flex: 1; min-height: 0; border-radius: 6px; background: #1E2226; overflow: hidden;
  box-shadow: 0 1px 2px rgba(22, 26, 30, .05), 0 16px 40px rgba(22, 26, 30, .10);
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: default; outline: none;
}
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; transform-origin: 0 0; pointer-events: none; }
.notice {
  position: absolute; left: 50%; top: 16px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 14px; border-radius: 6px; background: var(--surface); color: var(--ink); font-size: 13px;
  white-space: nowrap; box-shadow: 0 2px 4px rgba(22, 26, 30, .08), 0 12px 30px rgba(22, 26, 30, .20);
}
.panel { flex: none; padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); box-shadow: 0 1px 2px rgba(22, 26, 30, .04), 0 8px 24px rgba(22, 26, 30, .08); }
.composer { display: flex; gap: 8px; }
.composer .input { flex: 1; min-width: 0; }
.composer .btn { padding: 0 16px; font-size: 13px; }
.keys { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
.key { height: 44px; padding: 0; border: 1px solid rgba(22, 26, 30, .08); border-radius: 4px; background: #FAFAFB; font-size: 13px; font-weight: 400; box-shadow: 0 1px 1px rgba(22, 26, 30, .04), inset 0 1px 0 #fff; }

/* Dialog */
.overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(22, 26, 30, .20); }
.dialog { width: 100%; max-width: 420px; padding: 24px; border-radius: 6px; background: var(--surface); box-shadow: var(--shadow-pop); }
.dialog h2 { font-size: 20px; line-height: 1.4; }
.dialog p { margin-top: 8px; color: var(--quiet); }
.dialog-actions { margin-top: 20px; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* Only orientation and size change the layout; flows are the same everywhere. */
@media (max-width: 900px) {
  .page { padding: 16px 16px 32px; }
  .heading { margin-top: 20px; }
  .heading h1, .detail-head h1 { font-size: 28px; }
  .grid { margin-top: 20px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .thumb { padding: 6px; }
  .card-body { padding: 8px 10px 10px; }
  .card-name { font-size: 13px; }
  .card-body .status { font-size: 12px; }
  .detail-head { margin-top: 8px; }
  .preview { margin-top: 20px; padding: 6px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .page { padding: 4px 20px 20px; }
  .heading { margin-top: 0; }
  .heading h1, .detail-head h1 { font-size: 22px; }
  .grid { margin-top: 8px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .session { gap: 4px; padding: 4px 8px 8px; }
  .detail-head { margin-top: 0; }
  .preview { margin-top: 8px; max-width: 420px; }
}
@media (orientation: portrait) and (max-width: 600px) {
  .keys { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
