:root {
  --bg: #000000;
  --bg-elevated: #0a0a0a;
  --surface: #111111;
  --surface-2: #161616;
  --border: #262626;
  --border-strong: #3a3a3a;
  --text: #f2f2f2;
  --muted: #8a8a8a;
  --accent: #f5f5f5;
  --accent-ink: #0a0a0a;
  --ok: #5fd48a;
  --ok-bg: #0d1f14;
  --danger: #ff7b7b;
  --danger-bg: #1f0f0f;
  --danger-border: #5a2a2a;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  --radius: 14px;
  --max: 1080px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(255, 255, 255, 0.05), transparent 55%),
    var(--bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

button,
input,
textarea {
  font: inherit;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border-radius: 9px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover {
  background: #ffffff;
}

.btn.ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}

.btn.ghost:hover {
  background: var(--surface-2);
  border-color: #4a4a4a;
}

.btn.sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}

.btn.danger {
  border-color: var(--danger-border);
  color: var(--danger);
  background: transparent;
}

.btn.danger:hover {
  background: var(--danger-bg);
}

/* -------- Login gate -------- */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.gate-card {
  width: min(100%, 420px);
  padding: 2.25rem 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.gate-mark {
  width: 3rem;
  height: 3rem;
  margin: 0 auto 1rem;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #fff;
  color: #000;
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.gate-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}

.gate-card p {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.gate-card input {
  width: 100%;
  padding: 0.75rem 0.85rem;
  margin-bottom: 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  text-align: center;
}

.gate-card input:focus {
  outline: none;
  border-color: #666;
}

.gate-card .btn {
  width: 100%;
}

/* -------- App shell -------- */

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  width: min(100%, var(--max));
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.brand-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

.brand-btn:hover .brand-name {
  color: #fff;
}

.brand-mark {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #fff;
  color: #000;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 1;
  min-width: 0;
  justify-content: center;
}

.pill {
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

.pill-off {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.pill-on {
  background: var(--ok-bg);
  border-color: #1f4a2f;
  color: var(--ok);
}

.host {
  color: var(--muted);
  font-size: 0.85rem;
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  width: min(100%, var(--max));
  margin: 0 auto;
  padding: 1.25rem;
  flex: 1;
  display: block;
}

.home-view,
.session-view {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.home-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.home-title {
  margin: 0;
  font-size: 1.65rem;
  letter-spacing: -0.03em;
}

.home-sub {
  margin: 0.35rem 0 0;
  max-width: 36rem;
}

.home-stats {
  display: flex;
  gap: 0.5rem;
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid #1f4a2f;
  background: var(--ok-bg);
  color: var(--ok);
  font-size: 0.8rem;
  font-weight: 600;
}

.home-sessions,
.home-install {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1.1rem 1.2rem 1.25rem;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.section-title {
  margin: 0;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.sessions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.85rem;
}

.sessions-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 1.75rem 1rem;
  border: 1px dashed var(--border);
  border-radius: 12px;
  font-size: 0.92rem;
}

.session-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.95rem 1rem 1rem;
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.session-card.is-active {
  border-color: #1f4a2f;
  cursor: pointer;
}

.session-card.is-active:hover {
  border-color: #2f6a45;
  box-shadow: 0 0 0 1px rgba(95, 212, 138, 0.2);
}

.session-card.is-offline {
  opacity: 0.72;
}

.session-card.is-focused {
  border-color: var(--ok);
  box-shadow: inset 0 0 0 1px rgba(95, 212, 138, 0.35);
}

.session-card-top {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.session-card-status {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.session-card.is-active .session-card-status {
  color: var(--ok);
}

.session-badge {
  margin-left: auto;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ok);
  font-weight: 600;
}

.session-card-host {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  word-break: break-word;
}

.session-meta {
  margin: 0;
  display: grid;
  gap: 0.35rem;
}

.session-meta > div {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr);
  gap: 0.4rem;
  font-size: 0.8rem;
  line-height: 1.35;
}

.session-meta dt {
  margin: 0;
  color: var(--muted);
  font-weight: 500;
}

.session-meta dd {
  margin: 0;
  color: #d8d8d8;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 0.76rem;
}

.session-card-actions {
  margin-top: 0.25rem;
}

.session-card-actions .btn {
  width: 100%;
}

.status-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-on {
  background: var(--ok);
  box-shadow: 0 0 8px rgba(95, 212, 138, 0.65);
}

.dot-off {
  background: #c44;
  box-shadow: 0 0 6px rgba(196, 68, 68, 0.45);
}

.session-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.session-banner-label {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.session-banner-host {
  margin-top: 0.15rem;
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 600;
}

.session-banner-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.screen-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.screen-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}

.screen-modal-card {
  position: relative;
  z-index: 1;
  width: min(960px, 100%);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.screen-modal-head,
.screen-modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.screen-modal-foot {
  border-bottom: none;
  border-top: 1px solid var(--border);
}

.screen-modal-title {
  margin: 0;
  font-size: 1rem;
}

.screen-modal-body {
  padding: 0.75rem 1rem;
  overflow: auto;
  flex: 1;
  min-height: 120px;
  background: #1a1a1e;
}

.screen-modal-img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  min-height: 48px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0d0d10;
}

.site-mask-toolbar {
  flex-wrap: wrap;
}

.site-mask-config {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem 0.75rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.site-mask-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.72rem;
  color: var(--muted);
  flex: 1;
  min-width: 200px;
}

.site-mask-field input {
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.site-mask-status {
  font-size: 0.78rem;
  flex: 1 1 100%;
}

.site-mask-callout {
  flex: 1 1 100%;
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.45;
}

.site-mask-verify {
  flex: 1 1 100%;
  margin: 0;
  padding: 0.5rem 0.65rem;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 6px;
  max-height: 12rem;
  overflow: auto;
}

.site-mask-dns {
  margin: 0 1rem 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #1a1a22;
  font-size: 0.82rem;
  line-height: 1.45;
}

.site-mask-dns code {
  display: block;
  margin: 0.5rem 0;
  padding: 0.4rem 0.5rem;
  background: #0d0d10;
  border-radius: 4px;
  font-family: var(--mono);
}

.site-mask-dns ol {
  margin: 0.5rem 0 0 1.1rem;
  padding: 0;
}

.site-mask-dns-optional {
  margin-top: 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.site-mask-dns-optional summary {
  cursor: pointer;
  margin-bottom: 0.35rem;
}

.site-mask-methods {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  font-size: 0.82rem;
  flex: 1 1 100%;
}

.site-mask-methods label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.site-mask-field textarea {
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  min-height: 4rem;
}

.site-mask-chrome {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: #2a2a30;
  border-bottom: 1px solid var(--border);
}

.site-mask-bar {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.45rem 0.65rem;
  background: #0d0d10;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #e8e8ec;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-mask-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
}

.hvnc-overlay {
  position: fixed;
  inset: 0;
  z-index: 210;
  background: #0a0a0c;
  display: flex;
  flex-direction: column;
}

.hvnc-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.hvnc-title {
  font-weight: 600;
}

.hvnc-hint {
  font-size: 0.78rem;
  max-width: 14rem;
}

.control-input-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
}

.control-stage {
  outline: none;
  cursor: default;
}

.control-stage.control-active {
  cursor: crosshair;
  box-shadow: inset 0 0 0 2px var(--accent, #6ea8fe);
}

.hvnc-status {
  flex: 1;
  font-size: 0.85rem;
}

.hvnc-stage {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
}

.hvnc-frame {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.session-split {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.input-log-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.85rem 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 11rem);
  min-height: 320px;
}

.input-log-head {
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.input-log-head .section-title {
  margin: 0;
}

.input-log-sub {
  margin: 0.25rem 0 0;
  font-size: 0.78rem;
  line-height: 1.35;
}

.input-log-list {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  padding: 0.35rem 0;
  font-family: var(--mono);
  font-size: 0.76rem;
}

.input-log-empty {
  padding: 1.25rem 0.75rem;
  text-align: center;
  font-family: var(--font);
  font-size: 0.85rem;
}

.input-log-row {
  display: grid;
  grid-template-columns: 4.5rem 3.2rem 1fr;
  gap: 0.35rem;
  padding: 0.28rem 0.55rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  align-items: baseline;
}

.input-log-row:last-child {
  border-bottom: none;
}

.input-log-time {
  color: var(--muted);
}

.input-log-kind {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.input-log-kind-key {
  color: #9ecbff;
}

.input-log-kind-click {
  color: #ffb86c;
}

.input-log-label {
  color: #e8e8e8;
  word-break: break-word;
}

.input-log-typed {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.88rem;
}

@media (max-width: 960px) {
  .session-split {
    grid-template-columns: 1fr;
  }

  .input-log-panel {
    max-height: 240px;
    order: 2;
  }
}

.help {
  width: 100%;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.home-install {
  text-align: left;
}

.install-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.install-actions .btn {
  width: auto;
  min-width: 10rem;
}

.help strong {
  display: block;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.help p {
  margin: 0.35rem 0 0;
}

.help code {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: #d0d0d0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.1rem 0.35rem;
}

.help .install-steps {
  text-align: left;
  margin: 0.65rem 0 0.85rem;
  padding-left: 1.2rem;
  font-size: 0.88rem;
}

.help kbd {
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.1rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}

.help a.btn.install-copy {
  display: inline-block;
  text-align: center;
  text-decoration: none;
}

.install-status {
  margin-top: 0.5rem;
  font-size: 0.82rem;
}

.install-advanced {
  margin-top: 0.85rem;
  text-align: left;
  font-size: 0.82rem;
}

.install-advanced summary {
  cursor: pointer;
  color: var(--text);
}

.panel-frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.browser {
  padding: 1rem 1.15rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 420px;
  flex: 1;
}

.pathbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.pathbar input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
}

.pathbar input:focus {
  outline: none;
  border-color: #666;
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-start;
}

.crumbs button {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.25rem 0.55rem;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.82rem;
}

.crumbs button:hover {
  border-color: #555;
  background: var(--surface-2);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: flex-start;
}

.error {
  padding: 0.7rem 0.85rem;
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: 10px;
  color: var(--danger);
  font-size: 0.9rem;
  text-align: center;
}

.explorer-wrap {
  flex: 1;
  min-height: 280px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
}

.explorer {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.explorer th,
.explorer td {
  text-align: left;
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--border);
}

.explorer th {
  background: #0d0d0d;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  z-index: 1;
}

.explorer tbody tr {
  cursor: default;
}

.explorer tbody tr:hover {
  background: #141414;
}

.explorer tbody tr.selected {
  background: #1c1c1c;
  box-shadow: inset 2px 0 0 #fff;
}

.explorer .name .icon {
  margin-right: 0.45rem;
}

.explorer .col-mod {
  width: 12rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-family: var(--mono);
}

.explorer .col-size {
  width: 5.5rem;
  text-align: right;
  color: var(--muted);
  font-size: 0.82rem;
  font-family: var(--mono);
}

.explorer .muted {
  color: var(--muted);
  font-style: italic;
  text-align: center;
}

.row-parent .name {
  font-weight: 600;
}

.editor {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  min-height: 240px;
  background: var(--bg);
}

.editor-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.editor-path {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#editorBody {
  flex: 1;
  min-height: 200px;
  margin: 0;
  padding: 0.9rem 1rem;
  border: none;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.5;
}

#editorBody:focus {
  outline: none;
}

@media (max-width: 960px) {
  .sessions-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar-inner {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .topbar-status {
    order: 3;
    width: 100%;
    justify-content: flex-start;
  }

  .brand-name {
    font-size: 0.95rem;
  }

  .workspace {
    padding: 0.85rem;
  }

  .explorer .col-mod {
    display: none;
  }
}
