:root {
  --bg: #0f1115;
  --panel: #161a22;
  --panel-2: #1c2230;
  --line: #272e3b;
  --text: #dfe4ee;
  --muted: #8b93a5;
  --accent: #d97757;
  --accent-dim: #a85c43;
  --green: #4ade80;
  --red: #f87171;
  --radius: 10px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
}

.hidden { display: none !important; }

/* ---------------------------------------------------------------- */
/* 配对页                                                            */
/* ---------------------------------------------------------------- */

.pair-view {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(217, 119, 87, 0.10), transparent 60%),
    var(--bg);
}

.pair-card {
  width: min(400px, 100%);
  padding: 28px 22px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.logo {
  width: 54px;
  height: 54px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.5px;
  color: #fff;
  background: linear-gradient(145deg, var(--accent), #b35f42);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(217, 119, 87, 0.30);
}

.pair-card h1 {
  margin: 0 0 6px;
  font-size: 21px;
  font-weight: 650;
}

.pair-card .sub {
  margin: 0 0 22px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}

.pair-input {
  width: 100%;
  padding: 15px 10px;
  margin-bottom: 14px;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0.45em;
  text-align: center;
  text-indent: 0.45em;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s;
}

.pair-input:focus { border-color: var(--accent); }
.pair-input::placeholder { color: #3a4252; letter-spacing: 0.4em; }

.primary-btn {
  width: 100%;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}

.primary-btn:active { transform: scale(0.98); background: var(--accent-dim); }
.primary-btn:disabled { opacity: 0.5; }

.hint {
  min-height: 18px;
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--red);
  line-height: 1.5;
}

.link-btn {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  font-size: 12.5px;
  color: var(--muted);
  background: transparent;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

.main-view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding-top: env(safe-area-inset-top);
}

/* 标签栏 —— 浏览器风格 */
.tabbar {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 44px;
  padding: 0 6px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.tabs {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  flex: 1 1 auto;
  height: 100%;
  padding-top: 8px;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  min-width: 96px;
  max-width: 168px;
  height: 36px;
  padding: 0 8px 0 11px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 9px 9px 0 0;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.tab.active {
  color: var(--text);
  background: var(--bg);
  border-color: var(--line);
}

.tab.active::after {
  content: "";
  position: absolute;
  left: 9px;
  right: 9px;
  top: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
}

.tab-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--green);
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.55);
}

.tab.exited .tab-dot {
  background: #59627a;
  box-shadow: none;
}

.tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
}

.tab-close {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  font-size: 14px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  flex: 0 0 auto;
}
.tab-close:active { background: rgba(255, 255, 255, 0.12); }

.new-tab {
  width: 34px;
  height: 34px;
  margin-bottom: 1px;
  font-size: 21px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  flex: 0 0 auto;
}
.new-tab:active { background: var(--panel-2); }

.new-tab.wide {
  width: auto;
  min-width: 34px;
  padding: 0 9px;
  font-size: 12px;
  white-space: nowrap;
}

/* 终端区 */
.terms {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--bg);
}

.term-instance {
  position: absolute;
  inset: 0;
  display: none;
  padding: 2px 4px 0;
}

.term-instance.active { display: block; }

.term-instance .xterm {
  height: 100%;
}

.term-instance .xterm-viewport {
  scrollbar-width: none;
  touch-action: pan-y;
}
.term-instance .xterm-viewport::-webkit-scrollbar { display: none; }

/* 空状态 */
.empty {
  position: absolute;
  inset: 44px 0 86px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
}

.empty-icon {
  font-size: 40px;
  opacity: 0.4;
}

.empty p { margin: 0; font-size: 14px; }
.empty .primary-btn { width: auto; padding: 11px 22px; }

/* 键盘栏 */
.keybar {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  flex: 0 0 auto;
  min-height: 48px;
}
.keybar::-webkit-scrollbar { display: none; }

.key {
  flex: 0 0 auto;
  min-width: 42px;
  height: 34px;
  padding: 0 10px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}
.key:active { background: #2a3242; }

.key.mod.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.key.accent {
  color: var(--accent);
  border-color: rgba(217, 119, 87, 0.45);
  font-weight: 600;
}

/* 文本输入栏 */
.inputbar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 7px 8px;
  padding-bottom: calc(7px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

#textInput {
  flex: 1 1 auto;
  min-height: 34px;
  max-height: 120px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  resize: none;
  line-height: 1.35;
}
#textInput:focus { border-color: var(--accent-dim); }

.send-btn {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 9px;
  cursor: pointer;
}
.send-btn.ghost {
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
}

/* 断线横幅 */
.conn-banner {
  position: absolute;
  top: calc(44px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  padding: 7px 16px;
  font-size: 12.5px;
  color: #fecaca;
  background: rgba(127, 29, 29, 0.95);
  border: 1px solid rgba(248, 113, 113, 0.4);
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- */
/* 底部弹层                                                          */
/* ---------------------------------------------------------------- */

.sheet-mask {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  animation: fadeIn 0.15s ease;
}

.sheet {
  width: 100%;
  max-height: 84vh;
  overflow-y: auto;
  overflow-anchor: none;
  padding: 8px 14px calc(16px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  animation: slideUp 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

/* 电脑上已有会话 */
.resume-wrap {
  margin: 18px 0 4px;
}

.resume-title {
  margin: 0 2px 8px;
  font-size: 12px;
  color: var(--muted);
}

.resume-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 34vh;
  overflow-y: auto;
}

.resume-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.resume-item:active { background: var(--panel-2); }

.resume-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1 1 auto;
}

.resume-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resume-preview {
  font-size: 11.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resume-time {
  flex: 0 0 auto;
  font-size: 11px;
  color: #59627a;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  margin: 4px auto 12px;
  background: #394152;
  border-radius: 2px;
}

.sheet h2 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 650;
  text-align: center;
}

.field-label {
  display: block;
  margin: 0 2px 6px;
  font-size: 12px;
  color: var(--muted);
}

.sheet-input {
  width: 100%;
  padding: 11px 12px;
  margin-bottom: 14px;
  font-size: 14px;
  font-family: "Cascadia Mono", Consolas, monospace;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
.sheet-input:focus { border-color: var(--accent-dim); }

.sheet-item {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 13px 12px;
  margin-bottom: 8px;
  text-align: left;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

.sheet-item:active { background: #232b3a; }

.sheet-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(217, 119, 87, 0.10);
  border-radius: 10px;
  flex: 0 0 auto;
}

.sheet-item b {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}

.sheet-item small {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
}

.sheet-item.danger .sheet-icon {
  color: var(--red);
  background: rgba(248, 113, 113, 0.10);
}

.sheet-cancel {
  width: 100%;
  padding: 13px;
  margin-top: 4px;
  font-size: 14px;
  color: var(--muted);
  background: transparent;
  border: none;
  cursor: pointer;
}

/* 电脑端最新回复 */
.live-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: -4px 0 10px;
  min-height: 16px;
}

.live-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #59627a;
}

.live-dot.running {
  background: #4ade80;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.7);
  animation: livePulse 1.4s ease-in-out infinite;
}

.live-dot.stopped {
  background: #f87171;
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.5);
}

@keyframes livePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.live-meta {
  margin: 0;
  min-height: 14px;
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
}

.live-text {
  overflow: visible;
  overflow-anchor: none;
  margin: 0 0 10px;
  padding: 14px;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Cascadia Mono", Consolas, monospace;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 100;
  max-width: 84vw;
  padding: 10px 18px;
  font-size: 13px;
  color: #fff;
  background: rgba(40, 46, 60, 0.96);
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
