/* iDen 远屏 client styles. Served as /app.css (CSP style-src 'self': no inline styles). */
:root {
  --bg: #000;
  --surface: rgba(28, 28, 30, 0.96);
  --surface-2: #2c2c2e;
  --field: #1c1c1e;
  --line: rgba(255, 255, 255, 0.14);
  --text: #f5f5f7;
  --muted: #a1a1a6;
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.22);
  --danger: #ff453a;
  --ok: #30d158;
  --warn: #ffd60a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans CJK SC", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
body { overflow: hidden; }

svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ----- controls ----- */
button {
  font: inherit;
  color: inherit;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  min-height: 40px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button:hover:not(:disabled) { border-color: rgba(255, 255, 255, 0.3); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: transparent; color: #fff; font-weight: 600; }
button.secondary { background: transparent; }
button.danger { background: transparent; color: var(--danger); border-color: rgba(255, 69, 58, 0.45); }
button.small { padding: 5px 10px; min-height: 32px; font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="text"], textarea, select {
  font: inherit;
  font-size: 16px; /* 16 px or iOS zooms the page on focus */
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  min-width: 0;
}
textarea { resize: none; }
select { padding: 7px 10px; font-size: 14px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

label.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
label.switch input { width: 20px; height: 20px; margin: 0; }
label.switch.big { font-size: 17px; font-weight: 600; margin-top: 4px; }

.hint { color: var(--muted); font-size: 13px; margin: 8px 0; }
.hint.strong { color: var(--text); font-size: 15px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.row > button { flex: 1 1 auto; }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- gate ----- */
.gate {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-t) + 24px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 24px) calc(var(--safe-l) + 16px);
  background: radial-gradient(120% 80% at 50% 0%, #1a1f2b 0%, #000 70%);
}
.gate-card {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px 22px 20px;
}
.brand { margin: 0; color: var(--muted); font-size: 13px; letter-spacing: 0.06em; }
.gate h1 { margin: 4px 0 18px; font-size: 24px; font-weight: 650; }
.gate label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.pair-row { display: flex; gap: 8px; }
.pair-row input { flex: 1; }
.pair-row button { flex: none; }
.gate-busy { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 8px 0 4px; }
.pair-code {
  display: block;
  text-align: center;
  font-size: clamp(46px, 15vw, 76px);
  font-weight: 700;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  margin: 8px 0 2px;
  user-select: all;
  -webkit-user-select: all;
}
#pair-timer { text-align: center; }
#pair-wait > button { width: 100%; margin-top: 6px; }
#gate-actions button { width: 100%; }
.gate-status { min-height: 1.4em; margin: 12px 0 0; color: var(--warn); font-size: 14px; }
.gate-status:empty { margin: 0; min-height: 0; }
.gate-foot { margin: 16px 0 0; font-size: 13px; }
.gate-foot a { color: var(--muted); }

/* ----- remote screen ----- */
.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #000;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.stage canvas {
  position: absolute;
  display: block;
  transform-origin: 0 0;
  background: #000;
}
.stage.expired canvas { opacity: 0.12; filter: grayscale(1); }
.ring {
  position: absolute;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  opacity: 0;
}
.ring.long { border-color: var(--accent); width: 60px; height: 60px; margin: -30px 0 0 -30px; }
.ring.on { animation: ring 380ms ease-out forwards; }
@keyframes ring {
  0% { opacity: 0.95; transform: scale(0.55); }
  100% { opacity: 0; transform: scale(1.15); }
}

/* ----- viewer chrome ----- */
.viewer { user-select: none; -webkit-user-select: none; }
.banner {
  position: fixed;
  top: calc(var(--safe-t) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  max-width: calc(100vw - 140px);
  background: var(--warn);
  color: #000;
  font-weight: 600;
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 10px;
  text-align: center;
  pointer-events: none;
}
.control-bar {
  position: fixed;
  bottom: calc(var(--safe-b) + 14px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 24px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 6px 6px 6px 14px;
  font-size: 14px;
  white-space: nowrap;
}
.control-bar span { overflow: hidden; text-overflow: ellipsis; }
.dock:not([hidden]) ~ .control-bar { display: none; }

.toolbar {
  position: fixed;
  top: calc(var(--safe-t) + 10px);
  z-index: 40;
}
.toolbar.right { right: calc(var(--safe-r) + 10px); }
.toolbar.left { left: calc(var(--safe-l) + 10px); }
.tb-toggle {
  width: 44px;
  height: 44px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(20, 20, 22, 0.55);
  border-color: rgba(255, 255, 255, 0.22);
  opacity: 0.75;
  touch-action: none;
}
.tb-toggle:hover, .toolbar.open .tb-toggle { opacity: 1; }
.tb-toggle .i-close, .toolbar.open .tb-toggle .i-open { display: none; }
.toolbar.open .tb-toggle .i-close { display: block; }
.tb-actions {
  position: absolute;
  top: 52px;
  display: grid;
  grid-template-columns: repeat(4, 74px);
  gap: 6px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  max-width: calc(100vw - 20px);
}
.toolbar.right .tb-actions { right: 0; }
.toolbar.left .tb-actions { left: 0; }
@media (min-width: 640px) { .tb-actions { grid-template-columns: repeat(5, 76px); } }
.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 2px 6px;
  min-height: 62px;
  font-size: 12px;
  border-radius: 12px;
  background: transparent;
  border-color: transparent;
}
.tool span { white-space: nowrap; }
.tool[aria-pressed="true"] { background: var(--accent-soft); color: #cfe5ff; border-color: rgba(10, 132, 255, 0.5); }
.tool .i-muted, .viewer.muted .tool .i-sound { display: none; }
.viewer.muted .tool .i-muted { display: block; }

.hud {
  position: fixed;
  top: calc(var(--safe-t) + 8px);
  left: calc(var(--safe-l) + 8px);
  z-index: 20;
  background: rgba(0, 0, 0, 0.62);
  border-radius: 10px;
  padding: 6px 9px 8px;
  max-width: calc(100vw - 80px);
  pointer-events: auto;
}
.hud pre {
  margin: 0 0 6px;
  font: 11px/1.45 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap;
  color: #e8e8ea;
}
.toolbar.left ~ .hud { left: auto; right: calc(var(--safe-r) + 8px); }

/* 快捷键 panel, docked at the bottom */
.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 35;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 8px calc(var(--safe-r) + 10px) calc(var(--safe-b) + 8px) calc(var(--safe-l) + 10px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.key-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.key-row::-webkit-scrollbar { display: none; }
.key-row button { flex: none; min-width: 46px; min-height: 40px; padding: 6px 10px; }
.key-row button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: transparent; }
.sc-row button { font-size: 13px; }
.type-row { display: flex; align-items: center; gap: 8px; }
.type-row label { flex: none; font-size: 13px; color: var(--muted); }
.type-row textarea { flex: 1; height: 42px; line-height: 22px; }
.dock-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.dock-foot .hint { margin: 0; flex: 1; }
.dock-foot button { margin-left: auto; }

/* sheets (剪贴板, 设备) */
.sheet {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 45;
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100% - 40px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  user-select: text;
  -webkit-user-select: text;
}
.sheet.wide { width: min(620px, calc(100vw - 24px)); }
.sheet header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet h2 { margin: 0; font-size: 18px; }
.sheet .close { width: 36px; height: 36px; min-height: 0; padding: 0; border-radius: 50%; font-size: 20px; line-height: 1; }
.sheet textarea { width: 100%; }

.dev-list { list-style: none; margin: 10px 0 0; padding: 0; }
.dev { padding: 12px 0; border-top: 1px solid var(--line); }
.dev-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.dev-head b { font-size: 16px; margin-right: 4px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.dev-meta { margin: 4px 0 8px; font-size: 12px; color: var(--muted); }
.dev-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rename { display: inline-flex; gap: 6px; align-items: center; }
.rename input { width: 12em; padding: 5px 8px; }
.journal { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.journal summary { cursor: pointer; font-weight: 600; }
.journal ol { list-style: none; padding: 0; margin: 8px 0 0; font-size: 12px; max-height: 260px; overflow-y: auto; }
.journal li { padding: 3px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.j-time { color: var(--muted); font-variant-numeric: tabular-nums; }

/* approval cards */
.approvals {
  position: fixed;
  top: calc(var(--safe-t) + 60px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  width: min(430px, calc(100vw - 24px));
  max-height: calc(100% - var(--safe-t) - 80px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.approvals:empty { display: none; }
.card {
  background: var(--surface);
  border: 1px solid rgba(10, 132, 255, 0.6);
  border-radius: 16px;
  padding: 14px 14px 12px;
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.65);
  user-select: text;
  -webkit-user-select: text;
}
.card p { margin: 0 0 6px; }
.card-title { font-weight: 650; font-size: 16px; }
.card-meta { font-size: 12px; color: var(--muted); }
.card .warn { color: var(--warn); font-weight: 600; font-size: 14px; margin: 8px 0; }
.card .label { font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.card .badge.ok { color: var(--ok); font-size: 13px; }
.card input.code {
  width: 100%;
  font-size: 26px;
  letter-spacing: 0.32em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.card input.code::placeholder { font-size: 15px; letter-spacing: normal; font-family: inherit; }
.card .switch { margin-top: 8px; font-size: 14px; }
.card-status { min-height: 1.2em; font-size: 13px; color: var(--warn); margin: 8px 0 0 !important; }
.seg { display: flex; gap: 6px; }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block;
  text-align: center;
  padding: 8px 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
}
.seg input:checked + span { background: var(--accent); border-color: transparent; color: #fff; font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* overlay and toast */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  padding: 24px;
}
.overlay.blocking { pointer-events: auto; background: rgba(0, 0, 0, 0.45); }
.overlay-box {
  background: rgba(20, 20, 22, 0.82);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 18px;
  max-width: 420px;
  text-align: center;
}
.overlay-box p { margin: 0; }
.overlay-box button { margin-top: 12px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 76px);
  transform: translateX(-50%);
  z-index: 60;
  margin: 0;
  max-width: min(520px, calc(100vw - 32px));
  background: rgba(30, 30, 32, 0.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 14px;
  font-size: 14px;
  text-align: center;
  pointer-events: none;
}

/* ----- /probe page ----- */
body.probe { overflow: auto; }
.probe-main { max-width: 760px; margin: 0 auto; padding: calc(var(--safe-t) + 18px) 16px calc(var(--safe-b) + 30px); }
.probe-main h1 { font-size: 22px; margin: 0 0 4px; }
.probe-main table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 12px 0; }
.probe-main th, .probe-main td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.probe-main th { color: var(--muted); font-weight: 500; width: 38%; }
.probe-main td { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; word-break: break-all; }
.probe-main .yes { color: var(--ok); }
.probe-main .no { color: var(--danger); }
.probe-main a { color: var(--accent); }
.probe-main pre { white-space: pre-wrap; word-break: break-all; font-size: 11px; background: var(--field); padding: 10px; border-radius: 10px; }
