/* ==========================================================================
   PhoneRemote 网页控制台
   深色、克制、移动优先；不依赖外部字体、图片或 CDN。
   ========================================================================== */

/* --------------------------------------------------------------------------
   设计变量
   -------------------------------------------------------------------------- */
:root {
  color-scheme: dark;

  --bg: #080b0f;
  --bg-card: #0e131a;
  --bg-input: #0a0f15;
  --bg-bar: #0a0f14;
  --line: #1e2833;
  --line-strong: #2e3d4e;

  --text: #e9eff7;
  --muted: #9fadbe;
  --faint: #7b899b;

  --accent: #5b9dff;
  --accent-bright: #7db4ff;
  --accent-soft: rgba(91, 157, 255, 0.12);
  --accent-line: rgba(91, 157, 255, 0.3);
  --accent-ink: #04101f;

  --danger: #ff8a8a;
  --danger-soft: rgba(255, 138, 138, 0.1);
  --danger-line: rgba(255, 138, 138, 0.32);

  --ok: #4ad6a5;

  --font-sans: system-ui, -apple-system, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono",
    Consolas, "Liberation Mono", Menlo, monospace;

  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 10px;
  --tap: 44px;

  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* --------------------------------------------------------------------------
   基础重置与工具类
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* app.js 统一用 hidden 属性切换视图与面板 */
[hidden] {
  display: none !important;
}

.hidden,
.is-hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: rgba(91, 157, 255, 0.32);
  color: #fff;
}

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

button {
  -webkit-tap-highlight-color: transparent;
}

:where(button, select, a):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   品牌标记
   -------------------------------------------------------------------------- */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: block;
  flex: none;
  width: 36px;
  height: 36px;
}

.brand-mark .mark-bg {
  fill: #101821;
  stroke: #263547;
  stroke-width: 1;
}

.brand-mark .mark-phone {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.7;
}

.brand-mark .mark-dot {
  stroke: var(--accent);
  stroke-width: 1.7;
  stroke-linecap: round;
}

.brand-name {
  color: var(--faint);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   连接页
   -------------------------------------------------------------------------- */
#connect-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    calc(24px + env(safe-area-inset-top))
    calc(20px + env(safe-area-inset-right))
    calc(24px + env(safe-area-inset-bottom))
    calc(20px + env(safe-area-inset-left));
  background:
    radial-gradient(120% 75% at 50% -12%, rgba(91, 157, 255, 0.1), transparent 62%),
    radial-gradient(90% 60% at 50% 112%, rgba(74, 214, 165, 0.05), transparent 64%),
    var(--bg);
}

.noscript {
  width: min(100%, 424px);
  margin: 0;
  padding: 10px 14px;
  border: 1px solid var(--danger-line);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.6;
}

.connect-card {
  width: min(100%, 424px);
  padding: clamp(24px, 5.5vw, 34px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #10161e 0%, #0c1118 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 30px 70px -40px rgba(0, 0, 0, 0.95);
  animation: card-in 0.45s var(--ease) both;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.connect-card h1 {
  margin: 20px 0 10px;
  font-size: clamp(26px, 7.2vw, 32px);
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: 0.01em;
}

.lede {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
}

/* --------------------------------------------------------------------------
   配对码输入与连接按钮
   -------------------------------------------------------------------------- */
.connect-form {
  margin-top: 26px;
}

.field-label {
  display: block;
  margin: 0 2px 8px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.code-input {
  --code-tracking: 0.3em;
  display: block;
  width: 100%;
  height: 76px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: clamp(30px, 9vw, 36px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--code-tracking);
  /* 末位字符也带字距，补半个字距让数字视觉居中 */
  text-indent: calc(var(--code-tracking) / 2);
  text-align: center;
  caret-color: var(--accent);
  outline: none;
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.35);
  transition:
    border-color 0.18s var(--ease),
    box-shadow 0.18s var(--ease),
    background-color 0.18s var(--ease);
}

.code-input::placeholder {
  color: var(--faint);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-indent: 0;
}

.code-input:focus {
  border-color: var(--accent);
  background: #0b1118;
  box-shadow:
    0 0 0 3px var(--accent-soft),
    inset 0 2px 12px rgba(0, 0, 0, 0.35);
}

/* 避免移动端自动填充把输入框刷成白底 */
.code-input:-webkit-autofill,
.code-input:-webkit-autofill:hover,
.code-input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--bg-input) inset;
}

.field-help {
  margin: 10px 2px 0;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.65;
}

.connect-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  margin-top: 20px;
  padding: 0 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 15.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow:
    0 12px 28px -16px rgba(91, 157, 255, 0.9),
    0 1px 0 rgba(255, 255, 255, 0.28) inset;
  transition:
    background-color 0.16s var(--ease),
    transform 0.16s var(--ease),
    box-shadow 0.16s var(--ease),
    opacity 0.16s var(--ease);
}

.connect-btn:active {
  transform: translateY(1px);
}

.connect-btn:disabled {
  opacity: 0.55;
  box-shadow: none;
  cursor: not-allowed;
}

.error-line {
  margin: 12px 2px 0;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.error-line:empty {
  display: none;
}

/* --------------------------------------------------------------------------
   连接页底部：服务器地址与安全说明
   -------------------------------------------------------------------------- */
.connect-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.server-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  margin: 0;
  font-size: 12px;
}

.server-label {
  flex: none;
  color: var(--faint);
}

.server-host {
  min-width: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
  overflow-wrap: anywhere;
}

.server-host:empty::before {
  content: "—";
  color: var(--faint);
}

.trust-line {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.5;
}

.trust-line::before {
  content: "";
  flex: none;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(74, 214, 165, 0.12);
}

/* --------------------------------------------------------------------------
   会话页骨架
   -------------------------------------------------------------------------- */
#session-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
}

/* --------------------------------------------------------------------------
   顶部工具条：状态、画质、断开、安全码
   -------------------------------------------------------------------------- */
.session-top {
  flex: none;
  padding:
    calc(8px + env(safe-area-inset-top))
    calc(12px + env(safe-area-inset-right))
    8px
    calc(12px + env(safe-area-inset-left));
  border-bottom: 1px solid #1a2430;
  background: linear-gradient(180deg, #0d131a 0%, #0a0f15 100%);
}

.top-inner,
.text-inner {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
}

.top-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: var(--tap);
}

.status-pill {
  display: inline-flex;
  flex: 0 1 auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-size: 12.5px;
}

.status-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 157, 255, 0.14);
}

#status-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-controls {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
}

.select-wrap {
  position: relative;
  display: inline-flex;
}

.select-wrap::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 13px;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

#quality-select {
  appearance: none;
  -webkit-appearance: none;
  height: var(--tap);
  min-width: 90px;
  padding: 0 32px 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #0b1118;
  color: var(--text);
  font-size: 13.5px;
  cursor: pointer;
  transition:
    border-color 0.16s var(--ease),
    background-color 0.16s var(--ease);
}

#quality-select option {
  background: #0b1118;
  color: var(--text);
}

#btn-disconnect {
  height: var(--tap);
  min-width: 64px;
  padding: 0 14px;
  border: 1px solid var(--danger-line);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background-color 0.16s var(--ease),
    border-color 0.16s var(--ease),
    color 0.16s var(--ease);
}

/* 安全码：等宽大字，提示与手机画面上的 4 位码核对 */
.sas-block {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  margin-top: 8px;
  padding: 8px 12px;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
}

.sas-caption {
  flex: none;
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
}

.sas-code {
  margin-right: -0.18em;
  color: #f3f8ff;
  font-family: var(--font-mono);
  font-size: clamp(20px, 5.2vw, 26px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.sas-code:empty::before {
  content: "----";
  color: rgba(233, 239, 247, 0.28);
}

.sas-hint {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
  text-align: right;
}

/* app.js 若把提示改为警告文案，可直接加 warn 类 */
.sas-hint.warn,
.sas-hint.is-warn {
  color: var(--danger);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   画面区域：黑底、等比完整显示、不裁切
   -------------------------------------------------------------------------- */
#video-wrap {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  background: #000;
  touch-action: none;
  overscroll-behavior: contain;
}

#video-canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  background: #000;
  /* 画布元素本身保持画面的宽高比，指针坐标换算不会把黑边算进去 */
  object-fit: contain;
  object-position: center;
  outline: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}

/* --------------------------------------------------------------------------
   文字输入面板（默认隐藏）
   -------------------------------------------------------------------------- */
#text-panel {
  flex: none;
  padding:
    10px
    calc(10px + env(safe-area-inset-right))
    10px
    calc(10px + env(safe-area-inset-left));
  border-top: 1px solid #1a2430;
  background: var(--bg-bar);
}

/* 兼容 app.js 用状态类显示面板的写法；约定仍以 hidden 属性为主 */
#text-panel.is-open,
#text-panel.open {
  display: flex !important;
}

#text-panel.is-open .text-inner,
#text-panel.open .text-inner {
  display: flex;
}

.text-inner {
  display: flex;
  align-items: center;
  gap: 8px;
}

#text-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  /* 16px 可避免 iOS 聚焦输入框时自动放大页面 */
  font-size: 16px;
  outline: none;
  transition:
    border-color 0.16s var(--ease),
    box-shadow 0.16s var(--ease);
}

#text-input::placeholder {
  color: var(--faint);
}

#text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#text-send,
#text-cancel {
  flex: none;
  height: 46px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background-color 0.16s var(--ease),
    border-color 0.16s var(--ease),
    color 0.16s var(--ease);
}

#text-send {
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--accent);
  color: var(--accent-ink);
}

#text-cancel {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
}

#quality-select:disabled,
#btn-disconnect:disabled,
#text-send:disabled,
#text-cancel:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   底部工具条：返回 / 主页 / 最近任务 / 键盘
   -------------------------------------------------------------------------- */
.session-bottom {
  flex: none;
  padding:
    6px
    calc(8px + env(safe-area-inset-right))
    calc(6px + env(safe-area-inset-bottom))
    calc(8px + env(safe-area-inset-left));
  border-top: 1px solid #1a2430;
  background: var(--bg-bar);
}

.toolbar-inner {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 54px;
  padding: 6px 4px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.03em;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background-color 0.15s var(--ease),
    color 0.15s var(--ease),
    border-color 0.15s var(--ease);
}

.tool-btn svg {
  display: block;
  width: 22px;
  height: 22px;
}

.tool-btn:active {
  color: var(--text);
  background: rgba(91, 157, 255, 0.14);
}

.tool-btn.active,
.tool-btn[aria-pressed="true"] {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
}

/* --------------------------------------------------------------------------
   悬浮态仅在支持悬停的设备上启用，避免触屏粘滞
   -------------------------------------------------------------------------- */
@media (hover: hover) and (pointer: fine) {
  .connect-btn:hover {
    background: var(--accent-bright);
  }

  #quality-select:hover {
    border-color: var(--line-strong);
    background: #0d141c;
  }

  #btn-disconnect:hover {
    border-color: rgba(255, 138, 138, 0.5);
    background: rgba(255, 138, 138, 0.16);
  }

  #text-send:hover {
    background: var(--accent-bright);
  }

  #text-cancel:hover {
    border-color: var(--muted);
    color: var(--text);
  }

  .tool-btn:hover {
    background: rgba(255, 255, 255, 0.045);
    color: var(--text);
  }

  .tool-btn.active:hover,
  .tool-btn[aria-pressed="true"]:hover {
    background: rgba(91, 157, 255, 0.18);
    color: var(--accent);
  }
}

/* --------------------------------------------------------------------------
   窄屏适配
   -------------------------------------------------------------------------- */
@media (max-width: 380px) {
  .sas-hint {
    flex-basis: 100%;
    text-align: left;
  }

  #text-send,
  #text-cancel {
    padding: 0 12px;
  }

  .tool-btn {
    font-size: 10.5px;
  }
}

/* 横屏矮视口：压缩顶部与底部，把高度让给画面 */
@media (orientation: landscape) and (max-height: 540px) {
  .session-top {
    padding-top: calc(4px + env(safe-area-inset-top));
    padding-bottom: 4px;
  }

  .status-pill {
    min-height: 28px;
  }

  .sas-block {
    margin-top: 4px;
    padding: 4px 10px;
  }

  .sas-caption {
    font-size: 10px;
  }

  .sas-code {
    font-size: 18px;
  }

  .sas-hint {
    font-size: 10.5px;
  }

  .session-bottom {
    padding-top: 4px;
    padding-bottom: calc(4px + env(safe-area-inset-bottom));
  }

  .tool-btn {
    flex-direction: row;
    gap: 7px;
    min-height: var(--tap);
  }

  .tool-btn svg {
    width: 18px;
    height: 18px;
  }

  #text-panel {
    padding-top: 6px;
    padding-bottom: 6px;
  }
}

/* --------------------------------------------------------------------------
   减少动态效果
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .connect-card {
    animation: none;
  }

  .connect-btn:active {
    transform: none;
  }
}
