:root {
  --base: #1e1e2e;
  --crust: #11111b;
  --mantle: #181825;
  --surface0: #313244;
  --surface1: #45475a;
  --lavender: #b4befe;
  --overlay0: #6c7086;
  --text: #cdd6f4;
  --overlay2: #9399b2;
  --mauve: #cba6f7;
  --blue: #89b4fa;
  --yellow: #f9e2af;
  --red: #f38ba8;
  --green: #a6e3a1;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--base);
  color: var(--text);
  font: 400 14px/1.45 'Inter', system-ui, sans-serif;
}
code, pre, kbd, samp { font-family: 'JetBrains Mono', monospace; }
[hidden] { display: none !important; }

button, select, input { font: inherit; }
button {
  background: var(--surface0);
  color: var(--text);
  border: 1px solid var(--overlay0);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--lavender); }
button:disabled { opacity: .45; cursor: default; }
button.danger { color: var(--red); border-color: var(--red); }
select {
  background: var(--crust);
  color: var(--text);
  border: 1px solid var(--overlay0);
  border-radius: 6px;
  padding: 3px 6px;
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px; /* keep computeNatural/fitShared's avail = clientWidth/Height - 16 in sync */
  /* seamless: same color as terminal bg so the sub-grid remainder reads as padding, not a letterbox border */
  background: var(--base);
}
body.readonly #terminal { opacity: .78; filter: grayscale(.35); }

#probe {
  position: absolute;
  top: -9999px;
  left: -9999px;
  visibility: hidden;
  white-space: pre;
  font: 400 16px 'JetBrains Mono', monospace;
}

#control-toggle {
  position: fixed;
  top: 6px;
  right: 6px;
  z-index: 30;
  background: var(--crust);
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 5px;
  opacity: .35; /* unobtrusive over the terminal until needed */
  transition: opacity .15s ease;
}
#control-toggle:hover,
#control-toggle:focus-visible,
#control-toggle[aria-expanded="true"] { opacity: 1; }
#control-toggle[aria-expanded="true"] { border-color: var(--mauve); color: var(--mauve); }

#session-badge {
  position: fixed;
  top: 6px;
  right: 84px; /* sits just left of #control-toggle */
  z-index: 30;
  background: var(--crust);
  color: var(--blue);
  border: 1px solid var(--blue);
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 12px;
  opacity: .35; /* muted like #control-toggle so it never fights the terminal */
  transition: opacity .15s ease;
}
#session-badge:hover { opacity: 1; }

#panel {
  position: fixed;
  top: 40px;
  right: 6px;
  z-index: 29;
  width: 320px;
  max-height: calc(100vh - 52px);
  overflow-y: auto;
  background: var(--mantle);
  border: 1px solid var(--overlay0);
  border-radius: 8px;
  padding: 14px;
  display: none;
}
#panel.open { display: block; }
#panel section {
  margin-top: 14px;
  border-top: 1px solid var(--surface0);
  padding-top: 10px;
}
#panel h3 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--overlay2);
}

.facts { margin: 0; display: grid; gap: 4px; }
.facts div { display: flex; justify-content: space-between; gap: 12px; }
.facts dt { color: var(--overlay2); }
.facts dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
#p-status[data-state="connected"] { color: var(--green); }
#p-status[data-state="connecting"],
#p-status[data-state="reconnecting"] { color: var(--yellow); }
#p-status[data-state="stale"] { color: var(--peach); }
#p-status[data-state="disconnected"] { color: var(--red); }

.row { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; }
label.check { display: flex; align-items: center; gap: 8px; margin-top: 10px; }

#p-session[data-mode="split"] { color: var(--green); }
#p-session[data-mode="lobby"] { color: var(--yellow); }
#panel .hint {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--overlay2);
}

#download-path {
  flex: 1;
  min-width: 0;
  background: var(--crust);
  border: 1px solid var(--overlay0);
  border-radius: 6px;
  padding: 4px 8px;
  color: var(--text);
  font: 400 12px 'JetBrains Mono', monospace;
}
#download-path:focus { outline: none; border-color: var(--lavender); }

#logout-form {
  margin: 14px 0 0;
  border-top: 1px solid var(--surface0);
  padding-top: 12px;
}
#logout-form button { width: 100%; color: var(--blue); }

#request-bar, #ended-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--mantle);
  border: 1px solid var(--yellow);
  border-radius: 8px;
  padding: 8px 14px;
  z-index: 35;
}
#request-bar { top: 12px; }
#ended-bar { bottom: 16px; border-color: var(--red); }
#ended-bar span { color: var(--red); }

#overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 17, 27, .82);
}

/* lobby chooser z-index: below #panel and disconnect #overlay, above the terminal */
#chooser {
  position: fixed;
  inset: 0;
  z-index: 28;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 17, 27, .82);
}
.chooser-card h1 {
  margin: 0 0 16px;
  font-size: 18px;
  color: var(--mauve);
}
#chooser-note {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--yellow);
}
.chooser-buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chooser-buttons button { padding: 10px 18px; }
#chooser-info {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--overlay2);
}
.overlay-card {
  background: var(--mantle);
  border: 1px solid var(--overlay0);
  border-radius: 10px;
  padding: 24px 28px;
  text-align: center;
}
#overlay-msg { margin: 0 0 14px; }

/* upload modal: above the panel/bars, below the disconnect overlay */
#upload-modal {
  position: fixed;
  inset: 0;
  z-index: 38;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 17, 27, .82);
}
#upload-modal .overlay-card { max-width: min(360px, 92vw); }
#upload-modal h1 { margin: 0 0 12px; font-size: 18px; color: var(--mauve); }
.upload-hint { margin: 0 0 16px; font-size: 12px; line-height: 1.5; color: var(--overlay2); }
#upload-modal .upload-cancel { margin-top: 16px; }
.upload-error { margin: 12px 0 0; font-size: 12px; color: var(--red); }
.upload-bar {
  height: 6px;
  background: var(--surface1);
  border-radius: 3px;
  overflow: hidden;
}
#upload-bar-fill { height: 100%; width: 0; background: var(--mauve); }
#upload-stats { margin: 10px 0 16px; }
/* user-select: all — one click grabs the whole path when navigator.clipboard is absent (plain HTTP) */
.upload-path {
  display: block;
  background: var(--crust);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
  color: var(--text);
  user-select: all;
  overflow-wrap: anywhere;
  text-align: left;
}
#upload-result-path { margin-bottom: 16px; }
#panel code, .upload-hint code {
  background: var(--crust);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text);
}
#panel kbd {
  background: var(--surface0);
  border: 1px solid var(--overlay0);
  border-radius: 4px;
  padding: 0 4px;
  font-size: 11px;
}

/* transfer indicator/notice: never coexist, so they share one slot stacked above #toast */
#transfer-indicator {
  position: fixed;
  right: 16px;
  bottom: 60px;
  z-index: 49;
  background: var(--crust);
  border-color: var(--mauve);
  color: var(--mauve);
  font-size: 12px;
}
#transfer-notice {
  position: fixed;
  right: 16px;
  bottom: 60px;
  z-index: 49;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  background: var(--surface0);
  border-left: 3px solid var(--green);
  border-radius: 6px;
  padding: 10px 14px;
  max-width: 60vw;
}
#transfer-notice.err { border-left-color: var(--red); }
#transfer-notice-text { overflow-wrap: anywhere; }
#transfer-notice-path { flex-basis: 100%; }
#transfer-notice-close {
  margin-left: auto;
  background: none;
  border: none;
  padding: 0 2px;
  color: var(--overlay2);
  font-size: 16px;
  line-height: 1;
}
#transfer-notice-close:hover { color: var(--text); }

#toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  background: var(--surface0);
  border-left: 3px solid var(--mauve);
  border-radius: 6px;
  padding: 10px 14px;
  max-width: 60vw;
  overflow-wrap: anywhere;
}

body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: min(360px, 92vw);
  background: var(--mantle);
  border: 1px solid var(--surface0);
  border-radius: 10px;
  padding: 28px;
}
.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 0 22px;
}
.login-logo {
  width: 60px;
  height: 60px;
}
.login-wordmark {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .01em;
  color: var(--mauve);
}
.login-card label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--overlay2);
}
.login-card input {
  display: block;
  width: 100%;
  margin-top: 4px;
  background: var(--crust);
  color: var(--text);
  border: 1px solid var(--overlay0);
  border-radius: 6px;
  padding: 8px 10px;
}
.login-card input:focus { outline: none; border-color: var(--lavender); }
.login-card button {
  width: 100%;
  margin-top: 6px;
  padding: 8px;
  background: var(--mauve);
  border-color: var(--mauve);
  color: var(--crust);
  font-weight: 700;
}
.login-card .error { margin: 0 0 12px; color: var(--red); }
