:root {
  --bg: #0d1117; --bg2: #161b22; --bg3: #21262d; --line: #30363d;
  --fg: #e6edf3; --dim: #8b949e; --acc: #3fb950; --acc2: #58a6ff; --warn: #d29922; --bad: #f85149;
  --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left); --sar: env(safe-area-inset-right);
  --vh: 100dvh;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overflow: hidden;
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
#app { position: fixed; left: 0; right: 0; top: 0; height: var(--vh); display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0;
  padding: var(--sat) var(--sar) 0 var(--sal); }
.screen[hidden] { display: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
input, select { font: inherit; font-size: 16px; color: var(--fg); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; width: 100%; outline: none; }
input:focus, select:focus { border-color: var(--acc2); }
code { font: 13px ui-monospace, Menlo, monospace; color: var(--dim); }
.grow { flex: 1; }
.logo { font: 600 20px ui-monospace, Menlo, monospace; letter-spacing: -.5px; color: var(--dim); }
.logo b { color: var(--acc); }

/* login */
#login { align-items: center; justify-content: center; }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
.narrow { width: min(340px, 90vw); display: flex; flex-direction: column; gap: 14px; text-align: center; }
.err { color: var(--bad); margin: 0; min-height: 1.2em; font-size: 13px; }
.btn { border-radius: 10px; padding: 11px 16px; background: var(--bg3); border: 1px solid var(--line); font-weight: 500; }
.btn.primary { background: #238636; border-color: #2ea043; color: #fff; }
.btn.danger { color: var(--bad); }
.btn:active { filter: brightness(1.3); }

/* home */
.bar { display: flex; align-items: center; gap: 6px; padding: 10px 14px; }
.icon-btn { min-width: 38px; height: 38px; border-radius: 10px; font-size: 20px; line-height: 1; color: var(--dim);
  display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:active { background: var(--bg3); }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 14px calc(20px + var(--sab)); }
.list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.host { display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 14px; text-align: left; width: 100%; }
.host:active { background: var(--bg3); }
.host .av { width: 40px; height: 40px; border-radius: 10px; background: var(--bg3); display: grid; place-items: center;
  font: 600 16px ui-monospace, Menlo, monospace; color: var(--acc2); flex: none; }
.host .meta { flex: 1; min-width: 0; }
.host .nm { font-weight: 600; }
.host .sub { color: var(--dim); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.host .edit { color: var(--dim); padding: 8px; margin: -8px; font-size: 18px; }
.on { width: 8px; height: 8px; border-radius: 50%; background: var(--acc); flex: none; }
.resume { display: flex; align-items: center; gap: 10px; width: 100%; margin-bottom: 14px; padding: 14px;
  border-radius: 14px; background: linear-gradient(135deg, #1f6f3a, #1a4f8a); color: #fff; font-weight: 600; text-align: left; }
.resume small { display: block; font-weight: 400; opacity: .8; }
.hint { color: var(--dim); font-size: 12.5px; margin-top: 22px; }

/* terminal screen */
#term-screen { padding-bottom: 0; background: var(--bg); }
.tbar { display: flex; align-items: center; gap: 4px; height: 40px; padding: 0 6px; flex: none;
  background: var(--bg2); border-bottom: 1px solid var(--line); }
.tbar .icon-btn { min-width: 34px; height: 34px; font-size: 22px; }
.sess-btn { display: flex; align-items: center; gap: 4px; height: 30px; padding: 0 10px; border-radius: 8px;
  background: var(--bg3); font: 600 13px ui-monospace, Menlo, monospace; color: var(--acc); max-width: 30vw; flex: none; }
.sess-btn #sess-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { color: var(--dim); font-size: 10px; }
.tabs { flex: 1; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; min-width: 0; padding: 0 2px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; height: 30px; padding: 0 11px; border-radius: 8px; font: 13px ui-monospace, Menlo, monospace;
  color: var(--dim); display: flex; align-items: center; gap: 5px; white-space: nowrap; user-select: none; -webkit-user-select: none; }
.tab .ix { opacity: .6; }
.tab.active { background: var(--bg); color: var(--fg); box-shadow: inset 0 0 0 1px var(--line); }
.tab.bell::after, .tab.act::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--warn); }
.tab.bell::after { background: var(--bad); }
.tab .z { color: var(--acc2); font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); margin: 0 6px; flex: none; }
.dot.ok { background: var(--acc); } .dot.wait { background: var(--warn); } .dot.bad { background: var(--bad); }

#term-wrap { flex: 1; min-height: 0; position: relative; background: var(--bg); padding: 4px 2px 0 6px; }
#term { position: absolute; inset: 4px 2px 0 6px; touch-action: none; }
#term .xterm { height: 100%; }
#term .xterm-viewport { overscroll-behavior: none; }
#banner { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); background: var(--bg3);
  border: 1px solid var(--line); padding: 7px 14px; border-radius: 20px; font-size: 13px; z-index: 5; white-space: nowrap; }
#banner button { color: var(--acc2); margin-left: 8px; font-weight: 600; }

/* key bar */
#keybar { flex: none; background: var(--bg2); border-top: 1px solid var(--line);
  padding: 4px calc(4px + var(--sar)) calc(4px + var(--sab)) calc(4px + var(--sal)); user-select: none; -webkit-user-select: none; }
#keybar.kb-open { padding-bottom: 4px; }
#keybar[hidden] { display: none; }
.krow { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.krow::-webkit-scrollbar { display: none; }
.krow + .krow { margin-top: 4px; }
.k { flex: 1 0 auto; min-width: 42px; height: 38px; padding: 0 9px; border-radius: 8px; background: var(--bg3);
  font: 500 14px ui-monospace, Menlo, monospace; color: var(--fg); display: inline-flex; align-items: center; justify-content: center;
  border-bottom: 2px solid #0008; }
.k.t { color: var(--acc2); font-size: 12.5px; }
.k.pre { color: var(--acc); }
.k.on { background: var(--acc2); color: #000; }
.k.lock { background: var(--warn); color: #000; }
.k.down { filter: brightness(1.5); transform: translateY(1px); }
.k.sm { flex: 0 0 auto; min-width: 38px; color: var(--dim); }
@media (min-width: 700px) { .k { height: 40px; min-width: 50px; } }

/* sheet */
#sheet-back { position: fixed; inset: 0; background: #0009; z-index: 20; }
#sheet { position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: min(560px, 100vw); max-height: 82vh;
  background: var(--bg2); border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; z-index: 21;
  display: flex; flex-direction: column; padding-bottom: var(--sab); animation: up .16s ease-out; }
@media (min-width: 700px) { #sheet { bottom: auto; top: 12vh; border-radius: 18px; border-bottom: 1px solid var(--line); animation: none; } }
@keyframes up { from { transform: translate(-50%, 30px); opacity: 0; } }
#sheet[hidden], #sheet-back[hidden] { display: none; }
.sh-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 8px; font-weight: 600; }
.sh-body { overflow-y: auto; padding: 4px 12px 16px; }
.row { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 10px; width: 100%; text-align: left; }
.row:active, .row.cur { background: var(--bg3); }
.row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Menlo, monospace; }
.row .sub { color: var(--dim); font-size: 12.5px; }
.row .act { color: var(--dim); padding: 4px 8px; border-radius: 6px; font-size: 13px; }
.row .act:active { background: var(--line); }
.wins { padding-left: 22px; }
.wins .row { padding: 8px 12px; }
.form { display: grid; gap: 10px; }
.form label { font-size: 12.5px; color: var(--dim); display: grid; gap: 4px; }
.form .two { display: grid; grid-template-columns: 1fr 110px; gap: 10px; }
.btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }
.sel-text { font: 12px/1.35 ui-monospace, Menlo, monospace; white-space: pre; overflow: auto; user-select: text; -webkit-user-select: text;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; max-height: 60vh; margin: 0; }
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg button { padding: 7px 12px; border-radius: 8px; background: var(--bg3); font-size: 13px; }
.seg button.on { background: var(--acc2); color: #000; }
.set { display: grid; gap: 6px; margin-bottom: 16px; }
.set > span { color: var(--dim); font-size: 12.5px; }

#toast { position: fixed; left: 50%; top: calc(54px + var(--sat)); transform: translateX(-50%); background: var(--bg3);
  border: 1px solid var(--line); padding: 8px 16px; border-radius: 20px; z-index: 30; font-size: 13.5px; max-width: 90vw; }
#term .xterm, #term .xterm-viewport, #term .xterm-scrollable-element { background: var(--bg) !important; }
.host.add { border-style: dashed; background: none; }
.host.add .av { color: var(--acc); font-size: 22px; }
textarea { font: 12px ui-monospace, Menlo, monospace; color: var(--fg); }
