:root {
  --bg: #11131c;
  --panel: #171a26;
  --panel-2: #1e2233;
  --border: #2a2f45;
  --text: #e6e8f2;
  --muted: #8b90a8;
  --accent: #7c5cff;
  --accent-press: #6a49f0;
  --danger: #ff5c7c;
  --ok: #4ade80;
  --off: #6b7180;
  --bar-h: 44px;
  --keybar-h: 46px;
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
}

/* ---------- login gate ---------- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(120% 100% at 50% 0%, #1a1e2e 0%, var(--bg) 60%);
}
.gate-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.gate-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.gate-sub {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
#token-input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px; /* >=16px stops iOS zoom-on-focus */
  outline: none;
}
#token-input:focus {
  border-color: var(--accent);
}
.gate-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.gate-btn {
  margin-top: 4px;
  padding: 13px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  font-size: 16px;
  font-weight: 600;
}
.gate-btn:active {
  background: var(--accent-press);
}
.gate-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
}

/* ---------- top bar ---------- */
.bar {
  height: var(--bar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.status {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.status-on {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}
.status-off {
  background: var(--off);
}
.bar-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.bar-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}
.chip {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 10px;
}
.chip:active {
  background: var(--accent);
  border-color: var(--accent);
}
.chip-icon {
  padding: 7px 11px;
  font-size: 16px;
  line-height: 1;
}

/* ---------- terminal ---------- */
main {
  flex: 1 1 auto;
  min-height: 0;
  padding: 4px 6px 0;
  background: var(--bg);
}
#terminal {
  width: 100%;
  height: 100%;
}
.xterm .xterm-viewport {
  -webkit-overflow-scrolling: touch;
}

/* ---------- mobile key bar ---------- */
.keybar {
  flex: 0 0 auto;
  height: calc(var(--keybar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  gap: 5px;
  padding-left: 6px;
  padding-right: 6px;
  align-items: center;
  background: var(--panel);
  border-top: 1px solid var(--border);
  overflow-x: auto;
}
.key {
  flex: 1 0 auto;
  min-width: 42px;
  height: 34px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
}
.key:active {
  background: var(--accent);
  border-color: var(--accent);
}
.key-mod.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ---------- sheet ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.5);
}
.sheet-card {
  width: 100%;
  background: var(--panel);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sheet-item {
  text-align: left;
  padding: 15px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  border-radius: 10px;
}
.sheet-item:active {
  background: var(--panel-2);
}
.sheet-item.danger {
  color: var(--danger);
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--keybar-h) + env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%);
  z-index: 50;
  max-width: 84vw;
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
