:root {
  --bg: #0d1117; --panel: #161b22; --panel2: #1f2630; --line: #2b3440;
  --text: #e6edf3; --muted: #8b98a8; --accent: #3b82f6; --accent2: #60a5fa;
  --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444;
  --app-h: 100dvh;
  --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(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; overflow: hidden; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.err { color: var(--bad); min-height: 1.4em; margin: 8px 0 0; }

.screen { position: fixed; inset: 0; height: var(--app-h); display: flex; flex-direction: column; }

/* login */
#login { align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(circle at 50% 20%, #1b2a44, var(--bg) 70%); }
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-logo { width: 76px; height: 76px; border-radius: 20px; }
.login-card h1 { margin: 12px 0 4px; font-size: 26px; }
#loginForm { margin-top: 24px; }
input[type=password], input[type=text], textarea.field {
  width: 100%; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 17px; outline: none; -webkit-user-select: text; user-select: text; }
input:focus, textarea.field:focus { border-color: var(--accent); }
.btn { padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.wide { width: 100%; margin-top: 12px; }
.btn:active { transform: scale(.98); }

/* top bar */
#topbar { display: flex; align-items: center; gap: 8px; padding: calc(6px + var(--safe-t)) 10px 6px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); flex: none; }
.dot.on { background: var(--ok); } .dot.off { background: var(--bad); }
.host { font-weight: 600; max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rate { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: #7c2d12; color: #fed7aa; white-space: nowrap; }
.krow button.sas { color: #fca5a5; }
.chip { border: 1px solid var(--line); background: var(--panel2); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; }
.chip.touch { background: var(--accent); border-color: var(--accent); color: #fff; }
.icon-btn { border: 0; background: none; font-size: 18px; padding: 4px 6px; }

/* viewer */
#viewport { position: relative; flex: 1; overflow: hidden; background: #000; touch-action: none; }
#stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
#screen { display: block; width: 100%; height: 100%; image-rendering: auto; }
#cursor { position: absolute; left: 0; top: 0; width: 22px; height: 22px; pointer-events: none; display: none;
  background: no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 22'%3E%3Cpath d='M2 1l0 17 4.5-4 3 7 3-1.3-3-6.8 6.2 0z' fill='white' stroke='black' stroke-width='1.3' stroke-linejoin='round'/%3E%3C/svg%3E");
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.5)); }
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; background: rgba(13,17,23,.82); text-align: center; padding: 24px; }
.overlay p { margin: 0; color: var(--muted); max-width: 300px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: rgba(22,27,34,.95);
  border: 1px solid var(--line); padding: 8px 14px; border-radius: 999px; font-size: 13px; opacity: 0;
  transition: opacity .2s; pointer-events: none; width: max-content; max-width: 90vw; text-align: center; border-radius: 14px; }
.toast.show { opacity: 1; }

/* keys */
.keys { flex: none; background: var(--panel); border-top: 1px solid var(--line); padding: 6px 4px 2px; }
.krow { display: flex; gap: 5px; padding: 0 2px 6px; }
.krow.scroll { overflow-x: auto; scrollbar-width: none; }
.krow.scroll::-webkit-scrollbar { display: none; }
.krow.scroll button { flex: 0 0 auto; min-width: 46px; padding: 9px 9px; }
.krow button { flex: 1 1 0; min-width: 0; padding: 9px 2px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); font-size: 13px; font-weight: 600; white-space: nowrap; }
.krow button:active, .krow button.pressed { background: var(--accent); border-color: var(--accent); color: #fff; }
.krow button.on { background: #1d4ed8; border-color: var(--accent2); color: #fff; }
.krow button.lock { background: #7c3aed; border-color: #a78bfa; color: #fff; }

/* toolbar */
#toolbar { flex: none; display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
#toolbar button { flex: 1; border: 0; background: none; padding: 7px 0 8px; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; }
#toolbar button span { font-size: 19px; color: var(--text); line-height: 1.2; }
#toolbar button.active span, #toolbar button.active { color: var(--accent2); }
#typer { position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0;
  font-size: 16px; resize: none; pointer-events: none; }

/* sheet */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 10; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; background: var(--panel); border-radius: 18px 18px 0 0;
  border-top: 1px solid var(--line); max-height: 82vh; overflow-y: auto; padding: 8px 16px calc(18px + var(--safe-b));
  -webkit-user-select: text; user-select: text; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 2px auto 10px; }
.sheet h2 { font-size: 18px; margin: 4px 0 12px; display: flex; align-items: center; gap: 8px; }
.sheet h2 .back { border: 0; background: none; font-size: 20px; padding: 0 6px 0 0; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { border: 1px solid var(--line); background: var(--panel2); border-radius: 14px; padding: 14px 6px; text-align: center; font-size: 13px; font-weight: 600; }
.tile .ic { display: block; font-size: 24px; margin-bottom: 4px; }
.tile:active { background: var(--accent); }
.tile.danger .ic { filter: hue-rotate(0); } .tile.danger { color: #fca5a5; }
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; width: 100%; }
.item .ic { font-size: 20px; width: 26px; text-align: center; flex: none; }
.item .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { color: var(--muted); font-size: 12px; flex: none; }
.path { color: var(--muted); font-size: 12px; word-break: break-all; margin: -6px 0 10px; }
.row { display: flex; gap: 10px; align-items: center; } .row.end { justify-content: flex-end; }
.row > .btn { flex: 1; }
.setting { padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting label { display: block; font-weight: 600; margin-bottom: 8px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--panel2); padding: 9px 4px; font-size: 13px; font-weight: 600; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.sel { background: var(--accent); color: #fff; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.switch { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.switch input { width: 46px; height: 26px; accent-color: var(--ok); }
.help dt { font-weight: 600; margin-top: 10px; } .help dd { margin: 2px 0 0; color: var(--muted); }
.progress { height: 6px; background: var(--panel2); border-radius: 3px; overflow: hidden; margin: 10px 0; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .1s; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 20; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; width: 100%; max-width: 340px; }
.modal-card p { margin: 0 0 16px; }
.modal-card .row > .btn { flex: none; }

@media (orientation: landscape) and (max-height: 500px) {
  #topbar { padding-top: 4px; padding-bottom: 4px; }
  #toolbar button { padding: 4px 0; flex-direction: row; justify-content: center; gap: 6px; }
  #toolbar button span { font-size: 16px; }
  .krow button { padding: 6px 6px; }
}
