:root {
  color-scheme: dark;
  --bg: #020b13;
  --surface: rgba(5, 28, 44, 0.91);
  --surface-strong: #08253a;
  --line: rgba(93, 226, 215, 0.16);
  --text: #effffc;
  --muted: #8eacba;
  --primary: #13b8c9;
  --primary-strong: #21e6c1;
  --accent: #21e6c1;
  --danger: #ff667a;
  --warning: #ffb75c;
  --shadow: 0 22px 70px rgba(0, 8, 14, 0.48);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 18% -8%, rgba(19, 184, 201, 0.24), transparent 34rem),
    radial-gradient(circle at 100% 25%, rgba(33, 230, 193, 0.13), transparent 28rem),
    var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 860px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(26px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.view-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-bottom: 12px;
  padding: 5px;
  border-radius: 14px;
}

.view-switch__button {
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 800;
}

.view-switch__button.is-active {
  color: var(--text);
  background: rgba(19, 184, 201, 0.2);
  box-shadow: inset 0 0 0 1px rgba(33, 230, 193, 0.25);
}

.view-switch__button span {
  margin-left: 4px;
  padding: 2px 4px;
  border-radius: 4px;
  color: #b8ffe9;
  background: rgba(40, 215, 161, 0.13);
  font-size: 0.52rem;
  letter-spacing: 0.05em;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand img {
  filter: drop-shadow(0 8px 18px rgba(19, 184, 201, 0.35));
}

.brand h1,
.brand p,
.pair-copy h2,
.pair-copy p,
.dialog-header h2 {
  margin: 0;
}

.brand h1 {
  font-size: 1.03rem;
  letter-spacing: 0.01em;
}

.brand p {
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 2px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 105px;
  justify-content: center;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(9, 13, 24, 0.72);
  font-size: 0.76rem;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6f7890;
}

.status-badge--online {
  color: #b8ffe9;
  border-color: rgba(40, 215, 161, 0.32);
}

.status-badge--online .status-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(40, 215, 161, 0.12), 0 0 14px rgba(40, 215, 161, 0.8);
}

.status-badge--waiting .status-dot {
  background: var(--warning);
  box-shadow: 0 0 12px rgba(255, 183, 92, 0.65);
}

.card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.pair-panel {
  display: grid;
  justify-items: center;
  padding: 28px 22px 24px;
  text-align: center;
  overflow: hidden;
}

.pair-illustration {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 250px;
  height: 126px;
  margin-bottom: 11px;
}

.pair-illustration::before {
  content: "";
  position: absolute;
  width: 210px;
  height: 100px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(19, 184, 201, 0.28), transparent 68%);
  filter: blur(7px);
}

.phone-shape,
.monitor-shape {
  position: relative;
  z-index: 1;
  border: 2px solid rgba(222, 216, 255, 0.72);
  background: linear-gradient(145deg, rgba(19, 184, 201, 0.26), rgba(3, 24, 39, 0.94));
  box-shadow: inset 0 0 18px rgba(33, 230, 193, 0.14), 0 14px 30px rgba(0, 0, 0, 0.28);
}

.phone-shape {
  width: 48px;
  height: 88px;
  border-radius: 12px;
}

.phone-shape span {
  position: absolute;
  left: 50%;
  bottom: 5px;
  width: 11px;
  height: 3px;
  border-radius: 3px;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.55);
}

.monitor-shape {
  display: grid;
  place-items: center;
  width: 105px;
  height: 70px;
  border-radius: 9px;
}

.monitor-shape::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -17px;
  width: 32px;
  height: 16px;
  border-bottom: 3px solid rgba(222, 216, 255, 0.65);
  transform: translateX(-50%);
}

.monitor-shape span {
  color: #c9bfff;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.signal-lines {
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 13px;
}

.signal-lines i {
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(40, 215, 161, 0.7);
  animation: signal 1.4s infinite ease-in-out;
}

.signal-lines i:nth-child(2) { animation-delay: 0.18s; }
.signal-lines i:nth-child(3) { animation-delay: 0.36s; }

@keyframes signal {
  0%, 70%, 100% { opacity: 0.28; transform: scale(0.75); }
  35% { opacity: 1; transform: scale(1); }
}

.eyebrow {
  color: var(--accent) !important;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.pair-copy h2 {
  max-width: 470px;
  margin-top: 8px;
  font-size: clamp(1.5rem, 5vw, 2.15rem);
  line-height: 1.16;
}

.pair-copy > p:last-child {
  max-width: 510px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.55;
}

.pair-form {
  width: min(100%, 430px);
  margin-top: 24px;
  text-align: left;
}

label {
  display: block;
  margin: 0 0 7px;
  color: #c8d0e3;
  font-size: 0.78rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(160, 178, 214, 0.22);
  border-radius: 12px;
  outline: none;
  color: var(--text);
  background: rgba(8, 12, 23, 0.82);
  transition: border-color 0.18s, box-shadow 0.18s;
}

input {
  padding: 0 14px;
}

select {
  padding: 0 38px 0 13px;
}

input:focus,
select:focus {
  border-color: rgba(33, 230, 193, 0.8);
  box-shadow: 0 0 0 4px rgba(33, 230, 193, 0.13);
}

#pairCode {
  height: 58px;
  text-align: center;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: clamp(1.25rem, 6vw, 1.75rem);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.button {
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  padding: 0 18px;
  color: var(--text);
  font-weight: 800;
  transition: transform 0.12s, filter 0.15s, opacity 0.15s;
}

.button:active,
.icon-button:active,
.nav-button:active {
  transform: translateY(1px) scale(0.985);
}

.button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.button--primary {
  background: linear-gradient(135deg, var(--primary-strong), #6444f2);
  box-shadow: 0 12px 26px rgba(13, 148, 166, 0.28);
}

.button--secondary {
  background: rgba(19, 184, 201, 0.16);
  border: 1px solid rgba(33, 230, 193, 0.35);
}

.button--ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}

.pair-form .button {
  width: 100%;
  margin-top: 12px;
}

.remember-code {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 13px 0 0;
  color: #aeb9cf;
  font-weight: 600;
}

.remember-code input {
  width: 17px;
  min-height: 17px;
  margin: 0;
  accent-color: var(--primary);
}

.form-error {
  min-height: 20px;
  margin: 9px 0 0;
  color: #ff91a0;
  font-size: 0.8rem;
}

.pair-note {
  max-width: 510px;
  margin-top: 11px;
  color: #7f8ca7;
  font-size: 0.75rem;
  line-height: 1.45;
}

.lock-icon {
  margin-right: 5px;
  color: var(--accent);
  font-size: 0.55rem;
}

.remote-panel {
  display: grid;
  gap: 12px;
}

.grid-panel {
  display: grid;
  gap: 12px;
}

.grid-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 15px;
}

.grid-toolbar p,
.grid-toolbar h2 {
  margin: 0;
}

.grid-toolbar h2 {
  margin-top: 3px;
  font-size: 1.08rem;
}

.grid-toolbar #savedCodeCount {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.7rem;
}

.grid-toolbar__actions {
  display: flex;
  gap: 7px;
}

.grid-toolbar__actions .button {
  min-height: 38px;
  padding: 0 12px;
  font-size: 0.7rem;
}

.grid-empty {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 38px 18px;
  color: var(--muted);
  text-align: center;
}

.grid-empty strong {
  color: #dfe5f5;
}

.grid-empty span {
  font-size: 0.76rem;
  line-height: 1.45;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.grid-device {
  position: relative;
  min-width: 0;
  overflow: hidden;
}

.grid-device__header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 7px;
  padding: 11px 11px 9px;
}

.grid-device__header strong {
  overflow: hidden;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grid-device__status {
  grid-column: 1;
  color: var(--muted);
  font-size: 0.62rem;
}

.grid-device__remove {
  grid-row: 1 / 3;
  grid-column: 2;
  align-self: center;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(255, 102, 122, 0.2);
  border-radius: 8px;
  color: #ff9ba8;
  background: rgba(255, 102, 122, 0.07);
}

.grid-device__open {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 9 / 13;
  border: 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: #02040a;
  overflow: hidden;
}

.grid-device__open img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.grid-device__placeholder {
  display: grid;
  justify-items: center;
  gap: 5px;
  padding: 10px;
  font-size: 0.68rem;
  text-align: center;
}

.grid-device__placeholder i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6f7890;
}

.grid-device.is-online .grid-device__placeholder i {
  background: var(--accent);
  box-shadow: 0 0 10px rgba(40, 215, 161, 0.7);
}

.grid-device__code {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 3px 5px;
  border-radius: 5px;
  color: #cbd4e8;
  background: rgba(0, 0, 0, 0.65);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.54rem;
}

.storage-security-note {
  margin: 0 5px;
  color: #7f8ca7;
  font-size: 0.68rem;
  line-height: 1.5;
  text-align: center;
}

.device-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  align-items: center;
  gap: 9px;
  padding: 12px;
}

.assigned-device {
  display: grid;
  grid-template-columns: minmax(0, auto) 1fr;
  align-items: center;
  gap: 3px 9px;
  min-width: 0;
  padding-left: 3px;
}

.assigned-device__caption {
  grid-column: 1 / -1;
  color: #7f8ca7;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.assigned-device strong {
  min-width: 0;
  overflow: hidden;
  color: #f1f4ff;
  font-size: 0.94rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.emulator-badge {
  justify-self: start;
  padding: 3px 7px;
  border: 1px solid rgba(40, 215, 161, 0.25);
  border-radius: 999px;
  color: #a8f9df;
  background: rgba(40, 215, 161, 0.08);
  font-size: 0.62rem;
  font-weight: 750;
  white-space: nowrap;
}

.icon-button {
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: #dce3f4;
  background: rgba(8, 12, 23, 0.72);
  font-size: 1.22rem;
}

.screen-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: min(68dvh, 760px);
  padding: 7px;
  overflow: hidden;
  background:
    linear-gradient(45deg, rgba(255,255,255,0.018) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.018) 75%),
    #02040a;
  background-size: 18px 18px;
  touch-action: none;
  user-select: none;
}

#remoteScreen {
  display: none;
  max-width: 100%;
  max-height: calc(88dvh - 90px);
  object-fit: contain;
  border-radius: 13px;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
}

#remoteScreen.is-visible {
  display: block;
}

.screen-placeholder {
  display: grid;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}

.screen-placeholder strong {
  color: #d6dcef;
  font-size: 0.92rem;
}

.screen-placeholder span {
  font-size: 0.77rem;
}

.spinner {
  width: 34px;
  height: 34px;
  margin-bottom: 6px;
  border: 3px solid rgba(33, 230, 193, 0.18);
  border-top-color: var(--primary-strong);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

.screen-message {
  position: absolute;
  inset: auto 14px 56px;
  z-index: 4;
  padding: 10px 13px;
  border: 1px solid rgba(255, 102, 122, 0.25);
  border-radius: 10px;
  color: #ffd0d6;
  background: rgba(73, 18, 29, 0.9);
  font-size: 0.78rem;
  text-align: center;
}

.screen-hud {
  position: absolute;
  right: 13px;
  bottom: 12px;
  z-index: 3;
  display: flex;
  gap: 5px;
}

.screen-hud span {
  padding: 4px 7px;
  border-radius: 7px;
  color: #c6d0e5;
  background: rgba(0, 0, 0, 0.62);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.64rem;
}

.nav-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  padding: 9px;
}

.nav-button {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-width: 0;
  min-height: 54px;
  border: 0;
  border-radius: 11px;
  color: var(--muted);
  background: rgba(8, 12, 23, 0.72);
  font-size: 0.67rem;
}

.nav-button span {
  color: #e8ebf6;
  font-size: 1.28rem;
  line-height: 1;
}

.text-control {
  padding: 13px;
}

.text-control > div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.text-control small,
.field-help {
  display: block;
  margin: 8px 2px 0;
  color: #7f8ca7;
  font-size: 0.7rem;
  line-height: 1.4;
}

.disconnect-button {
  justify-self: center;
  margin-top: 3px;
}

.settings-dialog {
  width: min(calc(100% - 28px), 480px);
  border: 1px solid var(--line);
  border-radius: 19px;
  padding: 0;
  color: var(--text);
  background: #111829;
  box-shadow: 0 28px 100px rgba(0, 0, 0, 0.72);
}

.settings-dialog::backdrop {
  background: rgba(2, 4, 10, 0.75);
  backdrop-filter: blur(5px);
}

.settings-dialog form {
  padding: 18px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.dialog-header h2 {
  font-size: 1.08rem;
}

.dialog-header .icon-button {
  width: 38px;
  height: 38px;
}

.settings-dialog label:not(:first-of-type) {
  margin-top: 21px;
}

.isolation-note {
  margin: 18px 0 0;
  padding: 11px 12px;
  border: 1px solid rgba(40, 215, 161, 0.2);
  border-radius: 10px;
  color: #a9b7d2;
  background: rgba(40, 215, 161, 0.06);
  font-size: 0.72rem;
  line-height: 1.45;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: #edf1ff;
  background: rgba(17, 24, 41, 0.96);
  box-shadow: var(--shadow);
  font-size: 0.78rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.18s, transform 0.18s;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

body.focus-mode {
  overflow: hidden;
}

body.focus-mode .topbar,
body.focus-mode .view-switch,
body.focus-mode .device-bar,
body.focus-mode .text-control,
body.focus-mode .disconnect-button {
  display: none;
}

body.focus-mode .app-shell {
  width: 100%;
  height: 100dvh;
  padding: 0;
}

body.focus-mode .remote-panel {
  height: 100dvh;
  grid-template-rows: 1fr auto;
  gap: 0;
}

body.focus-mode .screen-stage {
  min-height: 0;
  height: 100%;
  border: 0;
  border-radius: 0;
  padding: 0;
}

body.focus-mode #remoteScreen {
  max-height: 100%;
}

body.focus-mode .nav-controls {
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 0;
}

[hidden] {
  display: none !important;
}

@media (min-width: 720px) {
  .app-shell { padding-top: 28px; }
  .pair-panel { padding: 38px 38px 30px; }
  .screen-stage { min-height: 640px; }
  .device-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 390px) {
  .app-shell { padding-right: 10px; padding-left: 10px; }
  .brand p { display: none; }
  .status-badge { min-width: 96px; padding-right: 8px; padding-left: 8px; }
  .pair-panel { padding-right: 15px; padding-left: 15px; }
  .nav-button { font-size: 0.6rem; }
  .grid-toolbar { align-items: flex-start; flex-direction: column; }
  .grid-toolbar__actions { width: 100%; }
  .grid-toolbar__actions .button { flex: 1; }
}

@media (orientation: landscape) and (max-height: 600px) {
  .screen-stage { min-height: 74dvh; }
  #remoteScreen { max-height: 72dvh; }
}

/* 0.3 ocean identity + H.264 surface */
.topbar__right {
  display: flex;
  align-items: center;
  gap: 9px;
}

.hotline-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(33, 230, 193, 0.28);
  border-radius: 999px;
  color: #cafff4;
  background: rgba(10, 91, 102, 0.24);
  font-size: 0.76rem;
  text-decoration: none;
}

.hotline-chip span,
.brand h1 span { color: var(--accent); }

.brand img { filter: drop-shadow(0 8px 18px rgba(22, 193, 205, 0.32)); }

.view-switch__button.is-active {
  background: rgba(19, 184, 201, 0.2);
  box-shadow: inset 0 0 0 1px rgba(33, 230, 193, 0.25);
}

input:focus,
select:focus {
  border-color: rgba(33, 230, 193, 0.7);
  box-shadow: 0 0 0 4px rgba(33, 230, 193, 0.1);
}

.remote-surface {
  display: none;
  max-width: 100%;
  max-height: calc(88dvh - 90px);
  object-fit: contain;
  border-radius: 13px;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
}

.remote-surface.is-visible { display: block; }

#remoteCanvas {
  width: auto;
  height: auto;
}

.nav-controls {
  position: sticky;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 12;
  background: rgba(5, 28, 44, 0.97);
}

.site-footer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding: 12px 14px;
}

.site-footer div { display: grid; gap: 2px; }
.site-footer strong { color: #dcfff8; font-size: 0.8rem; }
.site-footer span { color: var(--muted); font-size: 0.66rem; }
.site-footer a {
  color: #bfffee;
  font-size: 0.72rem;
  font-weight: 800;
  text-decoration: none;
}

.floating-hotline {
  position: fixed;
  right: 14px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 30;
  display: none;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 13px;
  border: 1px solid rgba(33, 230, 193, 0.42);
  border-radius: 999px;
  color: #04251f;
  background: linear-gradient(135deg, #72f7dc, #20c9bc);
  box-shadow: 0 12px 35px rgba(2, 207, 185, 0.3);
  font-size: 0.74rem;
  text-decoration: none;
}

body.focus-mode #remoteCanvas { max-height: 100%; }

@media (max-width: 620px) {
  .app-shell { padding-bottom: calc(130px + env(safe-area-inset-bottom)); }
  .topbar { align-items: flex-start; }
  .topbar__right { flex-direction: column-reverse; align-items: flex-end; }
  .hotline-chip { min-height: 30px; padding: 0 9px; }
  .hotline-chip b { display: none; }
  .nav-controls {
    bottom: calc(82px + env(safe-area-inset-bottom));
    box-shadow: 0 16px 45px rgba(0, 0, 0, 0.6);
  }
  .site-footer { grid-template-columns: auto 1fr; }
  .site-footer a { grid-column: 1 / -1; text-align: center; padding-top: 6px; }
  .floating-hotline { display: inline-flex; }
  body.focus-mode .nav-controls { bottom: 0; }
  body.focus-mode .floating-hotline { display: none; }
}

@media (orientation: landscape) and (max-height: 600px) {
  #remoteCanvas { max-height: 72dvh; }
}
