:root {
  --bg: #1a1915; --panel: #262521; --panel2: #302f2a; --line: #3d3b35;
  --fg: #ece9e1; --muted: #9b978c; --accent: #d97757; --accent2: #e8906f;
  --ok: #6fbf73; --bad: #e06c5f;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; font-weight: normal; }
.err { color: var(--bad); min-height: 1.2em; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: var(--fg); background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); }

.view { position: fixed; inset: 0; display: flex; flex-direction: column; height: 100dvh; }
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:active { background: var(--accent2); }
.btn.big { width: 100%; padding: 14px; font-size: 16px; }
.icon-btn { background: none; border: none; font-size: 20px; padding: 6px 10px; border-radius: 8px; min-width: 40px; min-height: 40px; }
.icon-btn:active { background: var(--panel2); }
.icon-btn.danger { color: var(--bad); }
.small-btn { font-size: 13px; min-width: 34px; padding: 6px; }

/* login */
#v-login { align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card h1 { margin: 0; }
.login-card p { margin: 0; }
.logo { font-size: 48px; color: var(--accent); }
.logo-sm { color: var(--accent); }

/* home */
.topbar { display: flex; align-items: center; gap: 6px; padding: calc(8px + var(--safe-t)) 10px 8px; background: var(--panel); border-bottom: 1px solid var(--line); flex: none; }
.topbar .title { flex: 1; font-weight: 600; font-size: 17px; padding-left: 6px; }
.home-main { flex: 1; overflow-y: auto; padding: 14px 14px calc(30px + var(--safe-b)); max-width: 820px; width: 100%; margin: 0 auto; -webkit-overflow-scrolling: touch; }
.home-main h2 { font-size: 15px; margin: 22px 0 8px; color: var(--fg); }
.banner { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 13px; word-break: break-all; }
.banner a { color: var(--accent2); }
.search { width: 100%; margin-bottom: 8px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; gap: 10px; align-items: flex-start; }
.card:active { background: var(--panel2); }
.card .body { flex: 1; min-width: 0; }
.card .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .s { color: var(--muted); font-size: 12px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .p { color: var(--muted); font-size: 13px; margin-top: 3px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .x { background: none; border: none; color: var(--muted); font-size: 18px; padding: 2px 6px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--panel2); color: var(--muted); margin-right: 4px; vertical-align: middle; }
.badge.live { background: #2e4a2f; color: var(--ok); }
.badge.dead { background: #4a2e2b; color: var(--bad); }
.empty { color: var(--muted); font-size: 13px; padding: 8px 2px; }
.more { text-align: center; }

/* sheet */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet-card { background: var(--panel); width: 100%; max-width: 640px; max-height: 88dvh; border-radius: 16px 16px 0 0; padding: 12px 12px calc(12px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; }
@media (min-width: 700px) { .sheet { align-items: center; } .sheet-card { border-radius: 16px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.path-row { display: flex; gap: 6px; align-items: center; }
.path-input { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.dir-list { overflow-y: auto; flex: 1; min-height: 160px; border: 1px solid var(--line); border-radius: 10px; -webkit-overflow-scrolling: touch; }
.dir-list .sec { padding: 6px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--panel2); }
.dir-list .d { padding: 11px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dir-list .d:active { background: var(--panel2); }
.check { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheet-actions .primary { grid-column: span 2; padding: 13px; }

/* terminal */
.term-top { padding-left: 4px; }
.term-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-weight: 600; }
#term-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); flex: none; }
.dot.on { background: var(--ok); }
#term-wrap { flex: 1; min-height: 0; background: #1a1915; padding: 4px 2px 0 6px; position: relative; }
#term { position: absolute; inset: 4px 2px 0 6px; }
.xterm .xterm-viewport { background: #1a1915 !important; }
.keys { flex: none; display: flex; gap: 6px; overflow-x: auto; padding: 6px 8px; background: var(--panel); border-top: 1px solid var(--line); scrollbar-width: none; }
.keys::-webkit-scrollbar { display: none; }
.keys button { flex: none; min-width: 42px; height: 36px; padding: 0 10px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; font-size: 14px; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.keys button:active, .keys button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.compose { flex: none; display: flex; gap: 6px; align-items: flex-end; padding: 6px 8px calc(6px + var(--safe-b)); background: var(--panel); }
.compose textarea { flex: 1; resize: none; max-height: 40dvh; min-height: 42px; line-height: 1.35; }
.compose .send { min-width: 48px; height: 42px; padding: 0; font-size: 18px; }
.compose .icon-btn { height: 42px; }

/* history tabs + PC lock */
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab { flex: 1; padding: 9px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.tab.on { background: var(--panel2); color: var(--fg); border-color: var(--accent); }
.unlock { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.unlock p { margin: 0 0 10px; font-size: 13px; }
.unlock .err { margin: 8px 0 0; }
.unlock-row { display: flex; gap: 8px; }
.unlock-row input { flex: 1; min-width: 0; }
.pc-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.small-lock { padding: 6px 10px; font-size: 13px; }
.badge.pc { background: #3a3350; color: #b9a8f0; }

/* project picker */
.proj-path { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.np-row { display: flex; gap: 8px; }
.np-row input { flex: 1; min-width: 0; }
.np-err { margin: -4px 0 0; font-size: 13px; min-height: 0; }
.invisible { visibility: hidden; }
.btn:disabled { opacity: .45; cursor: default; }
