:root {
  --t-bg: #070a12;
  --t-panel: #0e1421;
  --t-raised: #151c2c;
  --t-border: #232b3e;
  --t-text: #cdd6ea;
  --t-muted: #7e8aa3;
  --t-accent: #a5b4ff;
  --t-accent-2: #7ee0c2;
  --t-danger: #f48b9b;
  --t-warn: #e9c185;
  --t-font: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  --t-mono: "JetBrains Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--t-bg);
  color: var(--t-text);
  font: 14px/1.6 var(--t-font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--t-accent); }

.term-app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

/* ------------------------------------------------------------------ topbar */
.term-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--t-border);
  background: linear-gradient(180deg, rgba(21, 28, 44, .96), rgba(13, 19, 31, .96));
  z-index: 5;
  padding-top: max(9px, env(safe-area-inset-top));
}
.term-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.term-logo {
  width: 30px; height: 30px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 9px;
  background: linear-gradient(150deg, rgba(165, 180, 255, .26), rgba(126, 224, 194, .14));
  border: 1px solid rgba(165, 180, 255, .32);
  color: var(--t-accent);
}
.term-logo svg { width: 17px; height: 17px; }
.term-brand-text { min-width: 0; }
.term-brand-text strong { display: block; font-size: 12.5px; font-weight: 600; color: #eef1f9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term-brand-text small { display: block; font-size: 9.5px; letter-spacing: 1.3px; color: var(--t-muted); text-transform: uppercase; }

.term-meta { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; justify-content: center; font-size: 11.5px; color: var(--t-muted); }
.term-dot { width: 7px; height: 7px; border-radius: 50%; background: #59637a; flex: 0 0 auto; transition: background .2s, box-shadow .2s; }
.term-dot.online { background: var(--t-accent-2); box-shadow: 0 0 0 3px rgba(126, 224, 194, .16); }
.term-dot.connecting { background: var(--t-warn); box-shadow: 0 0 0 3px rgba(233, 193, 133, .16); animation: pulse 1.2s infinite; }
.term-dot.error { background: var(--t-danger); box-shadow: 0 0 0 3px rgba(244, 139, 155, .16); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
.term-host { color: #aab6cf; font-family: var(--t-mono); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.term-tools { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.tool {
  background: rgba(255, 255, 255, .035);
  border: 1px solid var(--t-border);
  color: #aeb9d0;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 11.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.tool:hover { background: rgba(255, 255, 255, .075); color: #e6ebf7; }
.tool:active { transform: translateY(1px); }
.tool.primary {
  background: linear-gradient(180deg, #b7c3ff, #8f9ff0);
  border-color: rgba(165, 180, 255, .7);
  color: #0b1020;
  font-weight: 600;
}
.tool.icon { padding: 6px 9px; }

/* ------------------------------------------------------------------ stage */
.term-stage {
  position: relative;
  min-height: 0;
  min-width: 0;
  padding: 10px 12px;
  background:
    radial-gradient(700px 340px at 50% -10%, rgba(165, 180, 255, .06), transparent 65%),
    var(--t-bg);
  overflow: hidden;
}
.term-viewport {
  width: 100%;
  height: 100%;
  min-height: 0;
}
.term-viewport .xterm { height: 100%; padding: 2px 0; }
.term-viewport .xterm-viewport { background: transparent !important; }

.term-hint {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  max-width: min(520px, 88%);
  text-align: center;
  color: var(--t-muted);
  font-size: 12.5px;
  line-height: 1.8;
  padding: 16px 20px;
  border: 1px dashed var(--t-border);
  border-radius: 12px;
  background: rgba(14, 20, 33, .86);
  backdrop-filter: blur(4px);
  pointer-events: none;
  z-index: 2;
}
.term-hint[hidden] { display: none; }
.term-hint strong { display: block; color: #dbe2f2; font-size: 13.5px; margin-bottom: 5px; font-weight: 600; }
.term-hint .hint-sub { display: block; font-size: 11.5px; color: #75819a; }
.term-hint.error { border-color: rgba(244, 139, 155, .4); color: #f7b3bf; }
.term-hint.error strong { color: #ffc1cb; }

/* ------------------------------------------------------------------ mobile keys */
.term-keys {
  display: none;
  gap: 6px;
  padding: 7px 10px;
  border-top: 1px solid var(--t-border);
  background: #0b101b;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.term-keys::-webkit-scrollbar { display: none; }
.term-keys button {
  flex: 0 0 auto;
  min-width: 36px;
  height: 32px;
  padding: 0 9px;
  border-radius: 7px;
  border: 1px solid #2a3348;
  background: #151c2b;
  color: #b9c3d9;
  font-size: 12px;
  font-family: var(--t-mono);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.term-keys button:active { background: #232c42; }
.term-keys button.is-on {
  background: rgba(165, 180, 255, .22);
  border-color: rgba(165, 180, 255, .55);
  color: #dfe5ff;
}
.term-keys button.wide { font-family: var(--t-font); }

.term-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 14px calc(4px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--t-border);
  background: #0a0f19;
  color: #6e7a93;
  font-size: 10.5px;
  font-family: var(--t-mono);
}
.term-statusbar span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------------------------------------------ dialog */
.term-dialog {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--t-text);
  width: min(480px, 100%);
  max-height: min(88vh, 760px);
  margin: auto;
}
.term-dialog::backdrop { background: rgba(3, 6, 12, .72); backdrop-filter: blur(5px); }
.dialog-box {
  background: linear-gradient(180deg, #171f30, #111726);
  border: 1px solid #2c3550;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
  padding: 20px 20px 18px;
  max-height: min(88vh, 760px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dialog-head h2 { margin: 0; font-size: 16px; font-weight: 600; color: #eef1f9; }
.dialog-head p { margin: 3px 0 0; font-size: 11.5px; color: var(--t-muted); }
.dialog-close {
  border: 0; background: transparent; color: #7d89a2; font-size: 20px; line-height: 1;
  cursor: pointer; padding: 2px 6px; border-radius: 6px;
}
.dialog-close:hover { background: rgba(255, 255, 255, .06); color: #dfe5f2; }

.d-field { margin-bottom: 12px; }
.d-field label { display: block; font-size: 11.5px; color: #8591a9; margin-bottom: 6px; }
.d-field input, .d-field select, .d-field textarea {
  width: 100%;
  background: #0c1220;
  border: 1px solid #2c3550;
  border-radius: 8px;
  color: #e8ecf7;
  padding: 9px 11px;
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.d-field textarea { min-height: 96px; resize: vertical; font-family: var(--t-mono); font-size: 11.5px; line-height: 1.6; }
.d-field input:focus, .d-field select:focus, .d-field textarea:focus {
  border-color: rgba(165, 180, 255, .6);
  box-shadow: 0 0 0 3px rgba(165, 180, 255, .12);
}
.d-row { display: grid; grid-template-columns: 1fr 96px; gap: 10px; }
.d-row-2 { display: grid; grid-template-columns: 1fr 132px; gap: 10px; }
.d-check { display: flex; align-items: flex-start; gap: 8px; font-size: 12px; color: #a6b0c6; padding: 5px 0; cursor: pointer; }
.d-check input { margin: 3px 0 0; accent-color: #8f9ff0; width: 14px; height: 14px; flex: 0 0 auto; }
.d-check small { display: block; color: #6f7b94; font-size: 10.5px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 16px; }
.d-btn {
  border: 1px solid #2f3a54; background: #171f30; color: #bcc6dc;
  border-radius: 8px; padding: 9px 16px; font-size: 12.5px; cursor: pointer;
}
.d-btn:hover { background: #1e2740; }
.d-btn.primary {
  background: linear-gradient(180deg, #b7c3ff, #8f9ff0);
  border-color: rgba(165, 180, 255, .7);
  color: #0b1020; font-weight: 600;
}
.d-btn.primary:hover { background: linear-gradient(180deg, #c6d0ff, #9daaf7); }

.recent { margin-top: 14px; padding-top: 12px; border-top: 1px solid #242d42; }
.recent-title { font-size: 10.5px; letter-spacing: 1px; color: #6e7a93; text-transform: uppercase; margin-bottom: 8px; }
.recent-list { display: flex; flex-direction: column; gap: 5px; }
.recent-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left;
  background: rgba(255, 255, 255, .025); border: 1px solid #262f45;
  border-radius: 8px; padding: 8px 10px; cursor: pointer; font-size: 12px; color: #b6c0d6;
}
.recent-item:hover { background: rgba(165, 180, 255, .08); border-color: rgba(165, 180, 255, .3); }
.recent-item small { color: #6f7b94; font-size: 10.5px; }

.term-toast {
  position: fixed; left: 50%; bottom: 60px; transform: translate(-50%, 12px);
  background: #1a2234; border: 1px solid #33405e; color: #e6ebf7;
  font-size: 12.5px; padding: 10px 16px; border-radius: 9px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 50; max-width: 88vw; text-align: center;
}
.term-toast.show { opacity: 1; transform: translate(-50%, 0); }
.term-toast.error { border-color: rgba(244, 139, 155, .5); color: #ffc1cb; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 980px) {
  .term-keys { display: flex; }
}

@media (max-width: 760px) {
  .term-topbar { gap: 9px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); }
  .term-brand-text small { display: none; }
  .term-brand-text strong { max-width: 92px; font-size: 11.5px; }
  .term-meta { justify-content: flex-start; }
  .term-host { display: none; }
  .term-tools { margin-left: auto; gap: 4px; }
  .tool { padding: 5px 8px; font-size: 11px; }
  .tool[data-act="font-down"], .tool[data-act="font-up"], .tool[data-act="fullscreen"] { display: none; }
  .term-stage { padding: 6px 8px; }
  .term-hint { top: 38%; padding: 14px 16px; font-size: 12px; }
  .term-statusbar { font-size: 10px; padding: 3px 10px calc(3px + env(safe-area-inset-bottom)); }
  .term-statusbar #status-size { display: none; }
  .term-dialog { width: 100%; max-height: 92vh; }
  .dialog-box { border-radius: 16px 16px 0 0; max-height: 92vh; padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); }
  .term-dialog { margin: auto auto 0; }
  .d-row, .d-row-2 { grid-template-columns: 1fr 88px; }
  .term-toast { bottom: 90px; }
}

@media (max-width: 400px) {
  .tool[data-act="reconnect"] { display: none; }
  .term-brand-text { display: none; }
}
