:root {
  --bg: #0d1117;
  --panel: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #3fb950;
  --danger: #f85149;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 14px;
  overflow: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }

button, select, input {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px;
}
button { cursor: pointer; background: #238636; border-color: #2ea043; }
button:hover { filter: brightness(1.15); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: #21262d; }
input:focus, select:focus { outline: 2px solid #1f6feb; outline-offset: -1px; }

/* Login */
#login { height: 100%; display: grid; place-items: center; padding: 16px; }
.card { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.card h1 { margin: 0; font-size: 20px; }
.card p { margin: 0; }
.logo { font-family: ui-monospace, Consolas, monospace; font-size: 28px; color: var(--accent); }

/* App */
/* --app-h = visible height (shrinks when the on-screen keyboard opens), set by app.js */
#app { height: var(--app-h, 100dvh); display: flex; flex-direction: column;
  padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left); }
header { display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  padding-top: calc(6px + env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--border); overflow-x: auto; }
.spacer { flex: 1; }
#host { font-size: 12px; white-space: nowrap; margin-right: 4px; }
#tabs { display: flex; gap: 4px; }
.tab { display: flex; align-items: center; gap: 6px; padding: 5px 8px 5px 12px; border-radius: 6px;
  cursor: pointer; color: var(--muted); white-space: nowrap; user-select: none; }
.tab:hover { background: #21262d; }
.tab.active { background: var(--bg); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.tab.dead { opacity: .55; }
.tab .close { border: 0; background: transparent; color: inherit; padding: 0 4px; font-size: 14px; line-height: 1; }
.tab .close:hover { color: var(--danger); background: transparent; }
.new-tab { display: flex; gap: 4px; }
#new-tab-btn { padding: 4px 10px; background: transparent; border-color: var(--border); }
#shell-select { padding: 4px 6px; }

main#terminals { flex: 1; position: relative; min-height: 0; }
.term-wrap { position: absolute; inset: 0; padding: 6px 0 0 8px; display: none; }
.term-wrap.active { display: block; }
.xterm .xterm-viewport { scrollbar-width: thin; }

/* SSH dialog */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; width: min(400px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; color: var(--muted); font-size: 12px; }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* Extra keys bar: only on touch screens */
#keys { display: none; }

/* ---------- Touch screens (phones, tablets) ---------- */
@media (pointer: coarse) {
  #keys { display: flex; flex-direction: column; gap: 6px; padding: 6px 8px; flex-shrink: 0;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
    background: var(--panel); border-top: 1px solid var(--border); }
  .keyrow { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
    -webkit-overflow-scrolling: touch; }
  .keyrow::-webkit-scrollbar { display: none; }
  #keys button { flex: 0 0 auto; min-width: 44px; height: 38px; padding: 0 10px;
    background: #21262d; border: 1px solid var(--border); color: var(--text);
    font-family: ui-monospace, Consolas, monospace; font-size: 14px;
    touch-action: pan-x; user-select: none; -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent; transition: background .08s; }
  #keys button:hover { filter: none; } /* no sticky hover glow after a tap */
  #keys .combos button { height: 34px; font-size: 13px; color: #c9d1d9; background: #1b2028; }
  /* While the finger is down: darker, pushed in */
  #keys button:active, #keys button.pressed { background: #0d1117; filter: none;
    box-shadow: inset 0 2px 4px rgba(0,0,0,.6); }
  /* Ctrl / Alt armed: dark and pressed-in with a bright outline, so it's obvious */
  #keys button.on { background: #05101f; color: #79c0ff; border: 2px solid #58a6ff;
    box-shadow: inset 0 2px 6px rgba(0,0,0,.8); font-weight: 700; }
  /* 16px+ inputs stop iOS from zooming in when they get focus */
  input, select, .xterm .xterm-helper-textarea { font-size: 16px !important; }
  header button, header select { min-height: 36px; }
  .tab { padding: 7px 6px 7px 12px; }
  .tab .close { padding: 4px 8px; font-size: 16px; }
}

/* ---------- Narrow screens: tabs get their own scrollable row ---------- */
@media (max-width: 640px) {
  header { flex-wrap: wrap; overflow: visible; row-gap: 6px; }
  #tabs { order: 10; width: 100%; overflow-x: auto; scrollbar-width: none; }
  #tabs::-webkit-scrollbar { display: none; }
  #host { display: none; }
  header button.ghost { padding: 6px 8px; }
  .term-wrap { padding: 4px 0 0 4px; }
  .card { padding: 22px; }
}
