:root {
  color-scheme: dark;
  --bg: #17171b;
  --stage: #0c0c0f;
  --card: #222229;
  --line: #34343e;
  --text: #ececf1;
  --muted: #9b9ba8;
  --accent: #d97757;
  --accent-text: #1b1b1f;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei UI", sans-serif;
  overscroll-behavior: none;
}

button, input, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 0 12px;
  min-height: 36px;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button:active { background: var(--line); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:active { filter: brightness(0.9); }
.muted { color: var(--muted); }
.error { color: var(--bad); margin: 0; }

/* ---------------------------------------------------------------- 登录 */

#login {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
#loginForm { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
#loginForm h1 { margin: 0; font-size: 24px; }
#loginForm p { margin: 0; }
#loginForm input {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-size: 16px;
}
#loginForm input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#loginForm button { height: 44px; }

/* ---------------------------------------------------------------- 主界面 */

#app {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: var(--vvh, 100dvh);
  display: flex;
  flex-direction: column;
}

#bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  padding-top: max(6px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
}
#bar .title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}
#curTitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.caret { color: var(--muted); }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--bad); }
.dot.on { background: var(--ok); }
.dot.wait { background: var(--warn); }

#stage {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: var(--stage);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}
#video {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  pointer-events: none; /* 指针事件统一由 #stage 处理 */
}
#hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
}

#tools {
  flex: none;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#keys {
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
#keys::-webkit-scrollbar { display: none; }
#keys button { flex: none; min-width: 44px; }

#composer { display: flex; align-items: flex-end; gap: 6px; padding: 0 8px 8px; }
#text {
  flex: 1;
  min-width: 0;
  height: 38px;
  max-height: 112px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-size: 16px; /* 小于 16px 时 iOS 会在聚焦时放大页面 */
  line-height: 20px;
  resize: none;
}
#text:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#composer button { height: 38px; }

/* ---------------------------------------------------------------- 会话选择 */

#picker {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
}
.sheet {
  width: 100%;
  max-width: 760px;
  max-height: 85%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 14px 14px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet-head { flex: none; display: flex; align-items: center; gap: 8px; padding: 12px; }
.sheet-head strong { flex: 1; }
#list {
  overflow-y: auto;
  padding: 0 12px 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
#list .empty { grid-column: 1 / -1; padding: 28px 8px; text-align: center; color: var(--muted); }
.win {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  height: auto;
  padding: 8px;
  text-align: left;
  white-space: normal;
}
.win.current { border-color: var(--accent); }
.win img, .win .noimg {
  width: 100%;
  height: 150px;
  border-radius: 4px;
  background: #000;
  object-fit: contain;
}
.win .noimg { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.win .name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 14px;
  word-break: break-all;
}

@media (min-width: 700px) {
  #picker { align-items: center; }
  .sheet { border-bottom: 1px solid var(--line); border-radius: 14px; }
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 130px;
  z-index: 20;
  transform: translateX(-50%);
  max-width: 86%;
  padding: 8px 14px;
  border-radius: 8px;
  background: #33333d;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  text-align: center;
  pointer-events: none;
}
