:root {
  color-scheme: dark;
  --background: #090d12;
  --panel: #10171f;
  --panel-soft: #151e28;
  --border: rgba(255, 255, 255, 0.1);
  --text: #f4f7f9;
  --muted: #8c9ba8;
  --accent: #58e0b5;
  --accent-dark: #0e3e34;
  --danger: #ff7c78;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(circle at 18% 12%, rgba(46, 118, 102, 0.16), transparent 32rem),
    radial-gradient(circle at 84% 86%, rgba(45, 75, 110, 0.13), transparent 34rem),
    var(--background);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea, select { font: inherit; }

.login-panel {
  width: min(100% - 36px, 470px);
  margin: clamp(48px, 11vh, 120px) auto;
  padding: clamp(26px, 5vw, 44px);
  border: 1px solid var(--border);
  border-radius: 24px;
  background: linear-gradient(155deg, rgba(20, 29, 38, 0.97), rgba(12, 18, 25, 0.97));
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.35);
}

.brand-mark {
  display: flex;
  align-items: end;
  gap: 4px;
  width: 44px;
  height: 44px;
  padding: 9px;
  border-radius: 12px;
  background: var(--accent);
  box-shadow: 0 10px 28px rgba(88, 224, 181, 0.16);
}

.brand-mark span { width: 7px; border-radius: 2px; background: #09271f; }
.brand-mark span:nth-child(1) { height: 13px; }
.brand-mark span:nth-child(2) { height: 25px; }
.brand-mark span:nth-child(3) { height: 19px; }

.eyebrow {
  margin: 30px 0 10px;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.17em;
}

h1 {
  margin: 0;
  max-width: 360px;
  font-size: clamp(2rem, 7vw, 3rem);
  line-height: 1.04;
  letter-spacing: -0.045em;
}

.intro { margin: 18px 0 30px; color: var(--muted); line-height: 1.55; }

form { display: grid; gap: 10px; }

label { margin-top: 7px; color: #bfccd5; font-size: 0.78rem; font-weight: 650; }

input {
  width: 100%;
  padding: 14px 15px;
  border: 1px solid var(--border);
  border-radius: 11px;
  outline: none;
  background: #0b1117;
  color: var(--text);
  transition: border-color 150ms, box-shadow 150ms;
}

input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88, 224, 181, 0.12); }

#sessionInput { text-transform: uppercase; letter-spacing: 0.15em; font-weight: 720; }

.primary-button {
  margin-top: 12px;
  padding: 14px 18px;
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: #08251e;
  font-weight: 780;
  cursor: pointer;
  transition: transform 150ms, filter 150ms;
}

.primary-button:hover { filter: brightness(1.06); transform: translateY(-1px); }
.primary-button:disabled { cursor: wait; filter: saturate(0.3); transform: none; }

.form-error { min-height: 20px; margin: 2px 0 0; color: var(--danger); font-size: 0.8rem; }

.trust-note {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.trust-note p { margin: 0; }
.trust-icon { color: var(--accent); font-size: 0.62rem; line-height: 1.7; }

.viewer-panel {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: #05080b;
}

.viewer-panel[hidden], .login-panel[hidden] { display: none; }

.toolbar {
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 66px;
  padding: 9px max(12px, env(safe-area-inset-right)) 9px max(12px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: rgba(12, 17, 23, 0.96);
  backdrop-filter: blur(16px);
}

.remote-identity { display: flex; align-items: center; gap: 11px; min-width: 0; }
.remote-identity > div:last-child { display: grid; gap: 3px; min-width: 0; }
.remote-identity strong { overflow: hidden; font-size: 0.86rem; text-overflow: ellipsis; white-space: nowrap; }

.mini-mark {
  display: flex;
  gap: 3px;
  align-items: end;
  width: 34px;
  height: 34px;
  padding: 8px;
  flex: 0 0 auto;
  border-radius: 9px;
  background: var(--accent-dark);
}

.mini-mark span { width: 7px; border-radius: 2px; background: var(--accent); }
.mini-mark span:first-child { height: 11px; }
.mini-mark span:last-child { height: 18px; }

.connection-state { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.68rem; }
.connection-state i { width: 7px; height: 7px; border-radius: 50%; background: #e0aa58; box-shadow: 0 0 10px currentColor; }
.connection-state i.online { background: var(--accent); }
.connection-state i.offline { background: var(--danger); }

.toolbar-actions { display: flex; align-items: center; gap: 7px; }
.network-stats { margin-right: 5px; color: var(--muted); font: 0.68rem ui-monospace, SFMono-Regular, Consolas, monospace; }

.tool-button {
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel-soft);
  color: #dce5eb;
  font-size: 0.73rem;
  font-weight: 650;
  cursor: pointer;
}

.tool-button:hover { border-color: rgba(255, 255, 255, 0.22); }
.tool-button.danger { color: #ffaaa6; }

.monitor-select, .quality-select {
  min-height: 36px;
  max-width: 165px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
  background: var(--panel-soft);
  color: #dce5eb;
  font-size: 0.73rem;
  cursor: pointer;
}

.quality-select { max-width: 112px; }

.mobile-label { display: none; }

.screen-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  background: #05080b;
  touch-action: none;
}

#remoteScreen {
  display: block;
  flex: none;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  outline: none;
  background: #070b0f;
  touch-action: none;
  cursor: default;
}

.remote-cursor {
  position: absolute;
  z-index: 3;
  display: none;
  width: 28px;
  height: 38px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-2px, -2px);
  transition: left 55ms linear, top 55ms linear, opacity 100ms ease;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.9));
}

.remote-cursor svg { display: block; width: 100%; height: 100%; }
.waiting-card:not(.ready) ~ .remote-cursor { opacity: 0 !important; }

.waiting-card {
  position: absolute;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 9px;
  width: min(90%, 340px);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(16, 23, 31, 0.92);
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.waiting-card strong { color: var(--text); font-size: 0.92rem; }
.waiting-card span { font-size: 0.75rem; line-height: 1.4; }
.waiting-card.ready { display: none; }

.spinner {
  width: 28px;
  height: 28px;
  margin-bottom: 5px;
  border: 2px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 850ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.mobile-keyboard {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0.01;
  pointer-events: none;
}

body.keyboard-open .viewer-panel {
  top: var(--visual-viewport-top, 0px);
  bottom: auto;
  height: var(--visual-viewport-height, 100dvh);
}

body.keyboard-open .screen-stage { align-items: flex-start; }
body.keyboard-open .touch-hint { display: none; }

.clipboard-dialog {
  width: min(100% - 28px, 560px);
  padding: clamp(22px, 4vw, 32px);
  border: 1px solid var(--border);
  border-radius: 20px;
  background: #111922;
  color: var(--text);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
}

.monitor-dialog {
  width: min(100% - 24px, 680px);
  max-height: min(88dvh, 820px);
  padding: clamp(20px, 4vw, 30px);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: auto;
  background: #111922;
  color: var(--text);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
}
.monitor-dialog::backdrop { background: rgba(2, 5, 8, 0.82); backdrop-filter: blur(5px); }
.monitor-dialog .eyebrow { margin: 0 0 7px; }
.monitor-dialog h2 { margin: 0; font-size: 1.28rem; letter-spacing: -0.025em; }
.layout-presets { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.monitor-layout-list { display: grid; gap: 7px; }
.monitor-layout-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(170px, 0.8fr);
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #0b1117;
}
.monitor-choice { display: flex; align-items: center; gap: 10px; margin: 0; cursor: pointer; }
.monitor-choice input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }
.monitor-choice span { display: grid; gap: 3px; }
.monitor-choice strong { color: var(--text); font-size: 0.77rem; }
.monitor-choice small { color: var(--muted); font-size: 0.66rem; }
.monitor-layout-row select {
  width: 100%; min-height: 36px; padding: 0 9px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel-soft); color: #dce5eb; font-size: 0.7rem;
}
.monitor-layout-row select:disabled { opacity: 0.42; }
.monitor-layout-error { min-height: 20px; margin: 8px 0; color: var(--danger); font-size: 0.73rem; }
.layout-preview-wrap { display: grid; gap: 7px; }
.layout-preview-wrap > small { color: var(--muted); font-size: 0.67rem; }
.layout-preview {
  display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 30px); gap: 5px;
  min-height: 135px; padding: 7px; border: 1px dashed var(--border); border-radius: 10px; background: #080d12;
}
.layout-preview-monitor {
  display: grid; place-items: center; min-width: 0; border: 1px solid rgba(88,224,181,0.42);
  border-radius: 7px; background: rgba(88,224,181,0.12); color: var(--accent); font-weight: 780; font-size: 0.76rem;
}

.clipboard-dialog::backdrop { background: rgba(2, 5, 8, 0.78); backdrop-filter: blur(5px); }
.clipboard-dialog .eyebrow { margin: 0 0 7px; }
.clipboard-dialog h2 { margin: 0; font-size: 1.35rem; letter-spacing: -0.025em; }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.dialog-help { margin: 18px 0; color: var(--muted); font-size: 0.82rem; line-height: 1.5; }
.close-button { border: 0; background: transparent; color: var(--muted); font-size: 1.65rem; cursor: pointer; }

#clipboardText {
  display: block;
  width: 100%;
  min-height: 160px;
  margin-top: 8px;
  padding: 13px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 11px;
  outline: none;
  background: #0b1117;
  color: var(--text);
}

#clipboardText:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88, 224, 181, 0.12); }
.clipboard-status { min-height: 20px; margin: 8px 0 0; color: var(--muted); font-size: 0.75rem; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 13px; }
.dialog-actions .primary-button { margin: 0; padding: 11px 14px; }

.secondary-button {
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-soft);
  color: #dce5eb;
  font-size: 0.76rem;
  font-weight: 650;
  cursor: pointer;
}

.touch-hint {
  display: none;
  min-height: 29px;
  padding: 7px max(10px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  border-top: 1px solid var(--border);
  background: #0c1117;
  color: var(--muted);
  font-size: 0.65rem;
  text-align: center;
}

@media (pointer: coarse) {
  .touch-hint { display: block; }
  .remote-cursor { display: block; }
  .remote-cursor.visible { opacity: 1; }
  .network-stats { display: none; }
  .toolbar { min-height: 58px; }
  .tool-button { padding: 0 9px; font-size: 0.68rem; }
}

@media (max-width: 570px) {
  .network-stats { display: none; }
  .remote-identity { display: none; }
  .toolbar-actions { width: 100%; gap: 5px; justify-content: space-between; }
  .mini-mark { display: none; }
  #fullscreenButton { display: none; }
  .tool-button { min-height: 34px; }
  .monitor-select { min-height: 34px; max-width: 88px; padding-left: 7px; font-size: 0.67rem; }
  .quality-select { min-height: 34px; max-width: 74px; padding: 0 5px; font-size: 0.65rem; }
  .monitor-layout-row { grid-template-columns: 1fr; gap: 7px; }
  .monitor-dialog { padding: 18px; }
  .layout-presets .secondary-button { flex: 1 1 auto; padding: 9px 7px; font-size: 0.68rem; }
  .desktop-label { display: none; }
  .mobile-label { display: inline; }
  .clipboard-dialog { max-height: calc(100dvh - 24px); overflow: auto; }
  .dialog-actions { display: grid; }
  .dialog-actions button { width: 100%; }
}

@media (max-height: 520px) and (pointer: coarse) {
  .touch-hint { display: none; }
  .toolbar { min-height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; animation-duration: 0.01ms !important; }
}
