:root {
  --bg: #000;
  --fg: #e6e6e6;
  --muted: #8a8a8a;
  --key-bg: #111;
  --key-fg: #e6e6e6;
  --accent: #5af78e;
  --danger: #ff5f56;
  --vvh: 100dvh;
  --vvtop: 0px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --mono: Menlo, 'SF Mono', ui-monospace, 'DejaVu Sans Mono', 'Roboto Mono', 'Droid Sans Mono', monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); height: 100%; }
body { font: 15px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
button { font: inherit; color: inherit; }
.prompt { font-family: var(--mono); color: var(--accent); font-weight: 700; }

/* ------------------------------------------------------------------ login */
body.login { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-logo { width: 72px; height: 72px; margin: 0 auto 12px; border-radius: 18px; background: #0d0d0d;
  border: 1px solid #222; display: grid; place-items: center; font-size: 28px; }
.login-card h1 { font-size: 22px; font-weight: 600; margin: 0 0 24px; letter-spacing: .02em; }
.login-card form { display: grid; gap: 10px; text-align: left; }
.login-card label { font-size: 13px; color: var(--muted); }
.login-card input[type=password] {
  font: 16px var(--mono); /* >=16px stops iOS zoom-on-focus */
  padding: 12px 14px; border-radius: 10px; border: 1px solid #2a2a2a; background: #0b0b0b; color: var(--fg); outline: none;
}
.login-card input[type=password]:focus { border-color: var(--accent); }
.login-card button { padding: 12px; border-radius: 10px; border: 0; background: var(--accent); color: #000; font-weight: 700; font-size: 16px; }
.login-card button:disabled { opacity: .6; }
.msg { min-height: 1.4em; margin: 4px 0 0; font-size: 14px; color: var(--danger); text-align: center; }
.msg.ok { color: var(--accent); }

/* -------------------------------------------------------------------- app */
body.app { overflow: hidden; overscroll-behavior: none; touch-action: manipulation; }
#root {
  position: fixed; left: 0; right: 0;
  top: var(--vvtop); height: var(--vvh);
  display: flex; flex-direction: column;
  padding: var(--sat) var(--sar) 0 var(--sal);
  background: var(--bg);
}
#terms { position: relative; flex: 1 1 auto; min-height: 0; }
.term { position: absolute; inset: 0; padding: 4px 4px 0 6px; display: none; }
.term.active { display: block; }
.term .xterm { height: 100%; }
.term .xterm-viewport { background: var(--bg) !important; overscroll-behavior: contain; }
/* xterm's hidden input: >=16px prevents iOS from zooming when focused. */
.xterm .xterm-helper-textarea { font-size: 16px !important; }

#extra-keys {
  flex: 0 0 auto; background: var(--bg); border-top: 1px solid #1a1a1a;
  padding: 2px 2px calc(2px + var(--sab));
  user-select: none; -webkit-user-select: none; touch-action: none;
}
/* When the soft keyboard is up the home-indicator inset is covered anyway. */
@media (hover: none) { .kbd-open #extra-keys { padding-bottom: 2px; } }
#extra-keys .row { display: grid; grid-template-columns: repeat(9, 1fr); gap: 2px; }
#extra-keys .row + .row { margin-top: 2px; }
#extra-keys button {
  height: 40px; min-width: 0; padding: 0; border: 0; border-radius: 6px;
  background: var(--key-bg); color: var(--key-fg);
  font: 600 12px var(--mono); letter-spacing: -.02em;
}
#extra-keys button[data-repeat], #extra-keys button[data-key="/"], #extra-keys button[data-key="-"],
#extra-keys button[data-key="|"], #extra-keys button[data-key="~"], #extra-keys button[data-action] { font-size: 17px; }
#extra-keys button.pressed { background: #333; }
#extra-keys button.on { background: #1f3d2a; color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
#extra-keys button.locked { background: var(--accent); color: #000; }
@media (min-width: 900px) and (hover: hover) {
  #extra-keys { max-width: 760px; margin: 0 auto; width: 100%; border-top: 0; }
  #extra-keys button { height: 34px; }
}

/* ----------------------------------------------------------------- drawer */
#scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 10; }
#drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(80vw, 300px); z-index: 11;
  background: #0b0b0b; border-right: 1px solid #1d1d1d;
  padding: calc(16px + var(--sat)) 14px calc(16px + var(--sab)) calc(14px + var(--sal));
  display: flex; flex-direction: column; gap: 12px;
  transform: translateX(-102%); transition: transform .18s ease-out;
}
#drawer.open { transform: none; }
#drawer header .who { font: 13px var(--mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#session-list { list-style: none; margin: 0; padding: 0; flex: 1 1 auto; overflow: auto; display: grid; gap: 4px; align-content: start; }
#session-list li { display: flex; border-radius: 8px; background: #121212; }
#session-list li.current { background: #1a2a20; }
#session-list .name { flex: 1; text-align: left; padding: 11px 12px; background: none; border: 0; font: 14px var(--mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#session-list .close { width: 44px; background: none; border: 0; color: var(--muted); font-size: 20px; }
#drawer .wide { padding: 12px; border-radius: 8px; border: 1px solid #262626; background: #121212; font-weight: 600; }
#drawer .wide.danger { color: var(--danger); border-color: #3a1a1a; }
.font-row { display: flex; align-items: center; gap: 10px; font: 14px var(--mono); color: var(--muted); }
.font-row span:first-child { flex: 1; }
.font-row button { width: 44px; height: 38px; border-radius: 8px; border: 1px solid #262626; background: #121212; font-weight: 700; }
#font-size { min-width: 2ch; text-align: center; color: var(--fg); }
