/* 虚拟屏幕：素净浅色、圆角卡片、系统字体，手机竖屏优先 */

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1f2329;
  --soft: #646b76;
  --faint: #9aa0a9;
  --line: #e3e6ea;
  --accent: #5b7fd1;
  --accent-soft: #eaf0fb;
  --ok: #2f8a57;
  --ok-soft: #e5f4eb;
  --warn: #a8701c;
  --warn-soft: #fbf1df;
  --danger: #c24f3c;
  --danger-soft: #fbecea;
  --radius: 14px;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* 带 hidden 的一律藏起来（不让下面的 display 规则把它顶出来） */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: default;
}

h1,
p {
  margin: 0;
}

/* 整页一屏高：老浏览器用 100vh，新的用 100dvh（不被地址栏挡）；四周让开刘海和底部横条 */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── 公用控件 ── */

.field {
  flex: 1;
  min-width: 0;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-size: 16px; /* 小于 16px 时 iOS 一点输入框就会整页放大 */
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field::placeholder {
  color: var(--faint);
}

.btn-primary {
  flex-shrink: 0;
  height: 46px;
  padding: 0 20px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.btn-primary:disabled {
  opacity: .45;
}

.btn-primary:active:not(:disabled) {
  transform: scale(.97);
}

.pill-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 13px;
  white-space: nowrap;
}

.pill-btn:active {
  background: #eef0f3;
}

/* ── 进门 ── */

.view-login {
  align-items: center;
  justify-content: center;
  padding: 24px 20px 12vh;
}

.login {
  width: 100%;
  max-width: 360px;
}

.login-title {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: .04em;
}

.login-sub {
  margin-top: 6px;
  color: var(--soft);
}

.login-form {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.login-msg {
  min-height: 1.5em;
  margin-top: 12px;
  font-size: 14px;
  color: var(--danger);
}

/* ── 列表 ── */

.list-head {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 10px;
}

.list-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: .03em;
}

.list-count {
  min-height: 1.5em;
  margin-top: 2px;
  font-size: 13px;
  color: var(--soft);
}

.link-btn {
  flex-shrink: 0;
  margin-top: 2px;
  padding: 6px 2px;
  border: 0;
  background: none;
  font-size: 13px;
  color: var(--soft);
}

.list-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px 28px;
}

.toast {
  margin-bottom: 12px;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  text-align: center;
}

.list-status {
  margin: 2px 2px 12px;
  font-size: 13px;
  color: var(--soft);
}

.list-status.is-error {
  color: var(--danger);
}

.empty {
  margin-top: 18vh;
  text-align: center;
}

.empty-main {
  font-size: 16px;
}

.empty-sub {
  margin-top: 6px;
  font-size: 13px;
  color: var(--faint);
}

.cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  gap: 14px;
}

.card {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  overflow: hidden;
  text-align: left;
  box-shadow: 0 1px 2px rgba(25, 35, 55, .04), 0 8px 20px -14px rgba(25, 35, 55, .22);
  transition: transform .12s ease;
}

.card:active {
  transform: scale(.985);
}

/* 缩略图：没有图时就是这块浅灰底，当占位 */
.thumb {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  background: #eceef1;
  overflow: hidden;
}

.thumb img {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  -webkit-user-drag: none;
  user-select: none;
}

.card-text {
  display: block;
  padding: 10px 12px 12px;
}

.card-site {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 标题最多两行，多了省略 */
.card-title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  margin-top: 2px;
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

/* ── 看画面 ── */

.live {
  position: relative;
  overflow: hidden;
}

/* 里面这层装下全部内容；横过来看时由 JS 设宽高和旋转 */
.live-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.is-rotated .live-layer {
  transform-origin: 0 0;
}

.live-top {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 8px;
}

.back-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 14px;
}

.back-btn::before {
  content: "";
  width: 7px;
  height: 7px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.live-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}

.live-site {
  font-weight: 600;
  color: var(--accent);
}

.live-title:not(:empty)::before {
  content: "·";
  margin: 0 6px;
  color: var(--faint);
}

/* 连接状态：连接中 / 重连中（黄）、已连上（绿）、已暂停（灰）、已断开（红） */
.chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 12px;
  white-space: nowrap;
}

.chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.chip[data-state="live"] {
  background: var(--ok-soft);
  color: var(--ok);
}

.chip[data-state="paused"] {
  background: #eef0f3;
  color: var(--soft);
}

.chip[data-state="error"] {
  background: var(--danger-soft);
  color: var(--danger);
}

.chip-small {
  height: 22px;
  padding: 0 7px;
  gap: 4px;
  font-size: 11px;
}

.live-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* 中间放画面的那块；它多大由布局定，画面框按比例装进去（JS 量了再算） */
.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.frame {
  position: relative;
  flex-shrink: 0;
  border-radius: 10px;
  background: #e7e9ed;
  box-shadow: 0 1px 2px rgba(25, 35, 55, .06), 0 10px 26px -16px rgba(25, 35, 55, .35);
}

.frame-clip {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: hidden;
  border-radius: inherit;
}

/* 放大和平移都加在这一层上，变换原点是框的中心 */
.frame-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-origin: 50% 50%;
  will-change: transform;
}

/* 画面上的手势全部自己处理，浏览器别插手（不滚页、不缩放、不长按出菜单） */
.screen {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.frame-wait {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  border-radius: inherit;
  background: rgba(244, 245, 247, .84);
  text-align: center;
  pointer-events: none;
}

.frame-wait-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--soft);
}

.frame-wait[data-tone="closed"] .frame-wait-text {
  color: var(--accent);
}

.frame-wait[data-tone="error"] .frame-wait-text {
  color: var(--danger);
}

.frame-wait .pill-btn {
  pointer-events: auto;
}

.zoom-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 3;
  height: 26px;
  padding: 0 9px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, .92);
  font-size: 12px;
  box-shadow: 0 1px 3px rgba(25, 35, 55, .18);
}

.live-note {
  position: absolute;
  top: 10px;
  left: 50%;
  z-index: 4;
  max-width: calc(100% - 32px);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(31, 35, 41, .86);
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transform: translateX(-50%);
  pointer-events: none;
}

.live-tools {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 14px 8px;
}

.hint {
  min-width: 0;
  font-size: 12px;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 打字栏 */
.typebar {
  flex-shrink: 0;
  margin: 0 10px 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  box-shadow: 0 6px 18px -14px rgba(25, 35, 55, .3);
}

.type-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.type-keys {
  margin-top: 8px;
}

.type-input {
  height: 42px;
  background: var(--bg);
}

.send-btn {
  height: 42px;
  padding: 0 16px;
  font-size: 15px;
}

.key-btn {
  flex-shrink: 0;
  min-width: 52px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 13px;
}

.key-btn:disabled {
  opacity: .45;
}

.key-btn:active:not(:disabled) {
  background: #eef0f3;
}

.pw-toggle {
  flex-shrink: 0;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 2px;
  border: 0;
  background: none;
  font-size: 13px;
  color: var(--soft);
}

.switch {
  position: relative;
  width: 30px;
  height: 18px;
  border-radius: 999px;
  background: #d9dde3;
  transition: background .16s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
  transition: transform .16s;
}

.pw-toggle[aria-pressed="true"] {
  color: var(--accent);
}

.pw-toggle[aria-pressed="true"] .switch {
  background: var(--accent);
}

.pw-toggle[aria-pressed="true"] .switch::after {
  transform: translateX(12px);
}

/* ── 横着看：顶栏和底下两行收起来，左右各一条窄边栏，画面占满中间 ── */

.side {
  display: none;
}

.is-land .live-top,
.is-land .live-tools,
.is-land .typebar {
  display: none;
}

.is-land .live-body {
  flex-direction: row;
}

.is-land .side {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 64px;
  padding: 12px 0;
}

.side-btn {
  min-width: 48px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 13px;
  white-space: nowrap;
}

/* 系统自己横过来时，点「打字」在画面底部浮出打字栏 */
.is-land.is-typing .typebar {
  display: block;
  position: absolute;
  left: 50%;
  bottom: 8px;
  z-index: 6;
  width: 440px;
  max-width: 86%;
  margin: 0;
  transform: translateX(-50%);
}

.noscript {
  padding: 40px 20px;
  text-align: center;
  color: var(--soft);
}

/* ── Sakura：留给她的页面、列表底下那一句 ── */
.card-note {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.4;
  color: #7a5af8;
  overflow-wrap: anywhere;
}
.cards > li.is-left .card { outline: 2px solid rgba(122, 90, 248, 0.45); outline-offset: -2px; }
.list-foot {
  margin: 16px 4px 8px;
  font-size: 12px;
  line-height: 1.5;
  color: #8a8a8a;
}
