:root {
  --bg: #0b0f14;
  --panel: #111821;
  --panel-2: #0f1620;
  --border: #1f2a37;
  --text: #d7e0ea;
  --muted: #7b8794;
  --accent: #34d399;
  --accent-dim: #1f6f56;
  --danger: #f87171;
  --vh: 100dvh;
}

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

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}

body { overflow: hidden; }

#app {
  position: fixed; left: 0; right: 0; top: 0;
  height: var(--vh);
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- 顶栏 ---------- */
#topbar {
  flex: 0 0 auto;
  height: 46px;
  display: flex; align-items: center; gap: 6px;
  padding: 0 6px 0 max(6px, env(safe-area-inset-left));
  background: linear-gradient(180deg, #121b26, #0f1620);
  border-bottom: 1px solid var(--border);
}

#title {
  flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 14px; font-weight: 600; letter-spacing: .3px;
  color: #e6eef8;
}
#sess-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 46vw;
}

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); box-shadow: 0 0 6px rgba(248,113,113,.7);
  flex: 0 0 auto;
}
.dot.on { background: var(--accent); box-shadow: 0 0 8px rgba(52,211,153,.8); }
.dot.wait { background: #fbbf24; box-shadow: 0 0 8px rgba(251,191,36,.7); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.tb-group { display: flex; gap: 2px; }

.tb {
  width: 38px; height: 38px; border: 0; border-radius: 10px;
  background: transparent; color: #9fb0c3;
  display: flex; align-items: center; justify-content: center;
}
.tb:active { background: #1b2634; color: var(--accent); }
.tb svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 终端 ---------- */
#term-wrap {
  flex: 1 1 auto; position: relative; min-height: 0;
  background: var(--bg);
  overflow: hidden;
}

#terminal {
  position: absolute; inset: 0;
  padding: 4px 2px 0 6px;
}
#terminal .xterm { height: 100%; }
#terminal .xterm-viewport { background: transparent !important; }

/* ---------- 覆盖提示 ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 10, 15, .82);
  backdrop-filter: blur(2px);
}
.overlay-card {
  width: min(78vw, 320px);
  background: var(--panel);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 20px 18px; text-align: center;
}
#overlay-title { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
#overlay-sub { font-size: 13px; color: var(--muted); line-height: 1.6; margin-bottom: 14px; word-break: break-all; }

/* ---------- 按键条 ---------- */
#keybar {
  flex: 0 0 auto;
  height: 50px;
  display: flex; align-items: center; gap: 5px;
  padding: 0 6px;
  background: var(--panel-2);
  border-top: 1px solid var(--border);
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none;
  touch-action: pan-x;
}
#keybar::-webkit-scrollbar { display: none; }

.key {
  flex: 0 0 auto;
  min-width: 38px; height: 36px; padding: 0 8px;
  border: 1px solid #263241; border-radius: 9px;
  background: #16202c; color: #cbd7e4;
  font-size: 12.5px; font-weight: 600; font-family: ui-monospace, "JetBrains Mono", monospace;
}
.key:active { background: #1e2c3b; border-color: #34465c; transform: translateY(1px); }
.key.mod.on {
  background: var(--accent-dim); border-color: var(--accent);
  color: #d1fae5; box-shadow: 0 0 10px rgba(52,211,153,.35);
}

/* ---------- 弹层 ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; }
.hidden { display: none !important; }
.sheet-mask { position: absolute; inset: 0; background: rgba(3, 6, 10, .62); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 78vh; overflow-y: auto;
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  animation: slideup .18s ease-out;
}
@keyframes slideup { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 15px; font-weight: 700; margin-bottom: 12px;
}
.icon-btn {
  width: 34px; height: 34px; border: 0; border-radius: 8px;
  background: #182230; color: var(--muted); font-size: 15px;
}
.icon-btn:active { background: #223044; color: var(--text); }

.session-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.session-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px;
  background: #131c27; border: 1px solid var(--border); border-radius: 11px;
}
.session-item:active { border-color: var(--accent-dim); background: #16222e; }
.session-item.current { border-color: var(--accent-dim); }
.session-name { flex: 1 1 auto; font-size: 14px; font-weight: 600; }
.session-meta { font-size: 11px; color: var(--muted); }
.session-empty { color: var(--muted); font-size: 13px; padding: 10px 2px; }

.primary {
  height: 44px; border: 0; border-radius: 11px;
  background: linear-gradient(180deg, #2ecf9b, #22b183);
  color: #05231a; font-size: 15px; font-weight: 700;
  box-shadow: 0 6px 18px rgba(34,177,131,.25);
}
.primary:active { transform: translateY(1px); filter: brightness(.95); }
.primary.wide { width: 100%; }
.sheet-tip { margin-top: 10px; font-size: 11px; color: var(--muted); text-align: center; }
.sheet-tip code { color: #9ad8c1; }

.field {
  display: block; margin-bottom: 12px;
  font-size: 12px; color: var(--muted);
}
.field input[type=text], .field input[type=range], textarea {
  display: block; width: 100%; margin-top: 6px;
}
.field input[type=text] {
  height: 42px; padding: 0 12px;
  background: #0e151e; border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 14px; font-family: ui-monospace, monospace;
}
.field input[type=text]:focus { outline: none; border-color: var(--accent-dim); }
textarea {
  min-height: 110px; padding: 10px 12px; resize: vertical;
  background: #0e151e; border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 14px; font-family: ui-monospace, monospace;
  -webkit-user-select: text; user-select: text;
}
input[type=range] { accent-color: var(--accent); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: 82vw; padding: 9px 16px;
  background: rgba(24, 34, 46, .96); color: #d9e4f0;
  border: 1px solid #2a3a4c; border-radius: 999px;
  font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  z-index: 60; transition: opacity .25s, transform .25s;
}
.toast.out { opacity: 0; transform: translateX(-50%) translateY(6px); }

#copy-text { -webkit-user-select: text; user-select: text; }
