:root {
  --bg: #080909;
  --panel: rgba(12, 15, 14, 0.76);
  --panel-border: rgba(230, 240, 235, 0.14);
  --text: rgba(244, 247, 245, 0.96);
  --muted: rgba(211, 220, 215, 0.7);
  --soft: rgba(211, 220, 215, 0.45);
  --accent: #d5f26f;
  --warn: #f4b860;
  --danger: #ff8b8b;
  --ok: #7ce4a4;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    url('/background.jpg') center center / cover no-repeat,
    var(--bg);
  color: var(--text);
  overflow: hidden;
  font-family: 'Newsreader', Georgia, serif;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

#remote,
#local {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#remote {
  z-index: 0;
  opacity: 0;
  transition: opacity 0.8s ease;
}

#local {
  z-index: 0;
  opacity: 0;
  transform: scaleX(-1);
  mix-blend-mode: screen;
  transition: opacity 0.8s ease, filter 0.8s ease;
  pointer-events: none;
}

body.state-connecting #local,
body.state-connected[data-connected-substate="peer-away"] #local {
  opacity: 0.18;
}

body.state-connecting #remote,
body.state-connected #remote {
  opacity: 1;
}

body.state-connecting #local {
  opacity: 0.72;
  mix-blend-mode: normal;
  filter: saturate(0.65);
}

body.state-connected[data-connected-substate="peer-away"] #local {
  opacity: 0;
  mix-blend-mode: normal;
  filter: none;
}

body.state-connected[data-connected-substate="peer-away"] #remote {
  opacity: 0;
}

#status-shell {
  position: fixed;
  top: 1.2rem;
  right: 1.2rem;
  z-index: 3;
}

#status-pill {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.72rem 0.95rem;
  border-radius: 999px;
  border: 1px solid rgba(230, 240, 235, 0.15);
  background: rgba(8, 10, 10, 0.62);
  backdrop-filter: blur(14px);
  color: var(--muted);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

body.state-unpaired #status-pill {
  border-color: rgba(230, 240, 235, 0.1);
  background: rgba(8, 10, 10, 0.42);
  color: var(--soft);
}

.preview-panel {
  display: none;
  width: 13rem;
  margin-top: 0.65rem;
  margin-left: auto;
  padding: 0.8rem;
  border: 1px solid var(--panel-border);
  background: rgba(8, 10, 10, 0.72);
  backdrop-filter: blur(14px);
}

body.state-connected #status-shell:hover #send-preview-panel,
body.state-connected.preview-open #send-preview-panel {
  display: block;
}

body.state-connected[data-connected-substate="live"] #send-preview-panel.hidden,
body.state-connected[data-connected-substate="peer-away"] #send-preview-panel.hidden {
  display: none;
}

#local-preview {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  margin-top: 0.55rem;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.26);
}

.preview-label {
  margin: 0;
  color: var(--soft);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#session-footer-action {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  z-index: 3;
  display: none;
  transform: translateX(-50%);
}

.session-note-panel {
  position: fixed;
  left: 50%;
  bottom: 4.8rem;
  z-index: 3;
  width: min(32rem, calc(100vw - 2rem));
  transform: translateX(-50%);
  padding: 0.95rem 1.1rem;
  border: 1px solid var(--panel-border);
  background: rgba(8, 10, 10, 0.62);
  backdrop-filter: blur(14px);
}

body.state-connected[data-connected-substate="live"] #connected-status-note,
body.state-booting #connected-status-note,
body.state-unpaired #connected-status-note,
body.state-pair-ended #connected-status-note,
body.state-waiting-for-pair #connected-status-note,
body.state-paired-home #connected-status-note,
body.state-connecting #connected-status-note {
  display: none;
}

#status-dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--soft);
  box-shadow: 0 0 0 0 rgba(213, 242, 111, 0.4);
}

body.state-booting #status-dot { background: var(--soft); }
body.state-unpaired #status-dot { background: var(--warn); }
body.state-pair-ended #status-dot { background: var(--warn); }
body.state-waiting-for-pair #status-dot,
body.state-connecting #status-dot { background: var(--warn); }
body.state-paired-home #status-dot,
body.state-connected #status-dot { background: var(--ok); }

body.state-waiting-for-pair #status-dot,
body.state-connected #status-dot {
  animation: pulse 1.8s ease-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(213, 242, 111, 0.45); }
  80% { box-shadow: 0 0 0 18px rgba(213, 242, 111, 0); }
  100% { box-shadow: 0 0 0 0 rgba(213, 242, 111, 0); }
}

#shell {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.view {
  display: none;
  width: min(92vw, 38rem);
  padding: 2.2rem 2rem;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.42);
}

.welcome-view {
  width: min(92vw, 34rem);
  padding: 2rem 2rem 1.75rem;
}

.welcome-view h1 {
  max-width: 24rem;
}

.welcome-view .lede {
  max-width: 28rem;
}

.welcome-view .support-copy {
  max-width: 26rem;
}

.welcome-view .actions {
  margin-top: 1.35rem;
}

.waiting-view {
  width: min(92vw, 47rem);
  padding: 2rem 2rem 1.75rem;
}

.waiting-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(14rem, 16rem);
  gap: 1.25rem;
  align-items: stretch;
}

.invite-primary {
  display: flex;
  flex-direction: column;
}

.waiting-view .lede {
  max-width: 31rem;
}

.invite-primary .invite-card {
  margin-top: 1.4rem;
}

.invite-primary .actions {
  margin-top: 1.2rem;
}

body.state-booting #view-booting,
body.state-unpaired #view-unpaired,
body.state-pair-ended #view-pair-ended,
body.state-waiting-for-pair #view-waiting,
body.state-paired-home #view-paired-home,
body.state-connecting #view-connecting {
  display: block;
}

.eyebrow {
  margin: 0 0 0.9rem;
  color: var(--accent);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.76rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.15rem, 6vw, 3.5rem);
  line-height: 0.95;
  font-weight: 400;
  letter-spacing: -0.03em;
}

.lede {
  margin: 1rem 0 0;
  max-width: 32rem;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.55;
}

.support-copy {
  margin: 0.9rem 0 0;
  max-width: 28rem;
  color: var(--soft);
  font-size: 0.98rem;
  line-height: 1.55;
}

.actions,
.stack {
  display: flex;
  gap: 0.8rem;
  margin-top: 1.7rem;
  flex-wrap: wrap;
}

.stack {
  flex-direction: column;
}

.hidden {
  display: none;
}

button,
input {
  font: inherit;
}

button {
  min-height: 3rem;
  padding: 0.8rem 1.25rem;
  border: 1px solid rgba(230, 240, 235, 0.24);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

button:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

button.primary {
  border-color: rgba(213, 242, 111, 0.44);
  background: rgba(213, 242, 111, 0.08);
}

.quiet-action {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--soft);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.quiet-action:hover {
  background: transparent;
  color: var(--text);
  transform: none;
}

#btn-disconnect-desktop {
  display: none;
  padding-left: 0.45rem;
  border-left: 1px solid rgba(230, 240, 235, 0.14);
}

body.state-connected #btn-disconnect-desktop {
  display: inline-flex;
}

#btn-disconnect-mobile {
  padding: 0.7rem 1rem;
  border: 1px solid rgba(230, 240, 235, 0.14);
  background: rgba(8, 10, 10, 0.54);
  backdrop-filter: blur(14px);
}

body.state-connected #session-footer-action {
  display: none;
}

button:disabled {
  opacity: 0.6;
  cursor: default;
  transform: none;
}

label,
.meta,
input,
.invite-code {
  font-family: 'IBM Plex Mono', monospace;
}

label {
  color: var(--soft);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

input {
  width: min(16rem, 100%);
  min-height: 3rem;
  padding: 0.8rem 0.95rem;
  border: 1px solid rgba(230, 240, 235, 0.16);
  background: rgba(0, 0, 0, 0.26);
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.invite-card {
  padding: 1.1rem 1.25rem;
  border: 1px solid rgba(213, 242, 111, 0.25);
  background: rgba(213, 242, 111, 0.05);
}

.invite-code {
  font-size: clamp(2rem, 8vw, 3rem);
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

.meta {
  margin-top: 0.8rem;
  color: var(--soft);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.qr-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  padding: 1.2rem;
}

.invite-qr {
  width: 100%;
  max-width: 17rem;
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.96);
}

.invite-qr canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.panel-note,
.panel-error {
  min-height: 1.2rem;
  margin-top: 1rem;
  font-size: 0.9rem;
}

.panel-note {
  color: var(--muted);
}

.session-note-panel .panel-note {
  min-height: 0;
  margin: 0;
}

.panel-error {
  color: var(--danger);
}

@media (max-width: 720px) {
  #shell {
    padding: 1rem;
    align-items: end;
  }

  .view {
    width: 100%;
    padding: 1.5rem 1.2rem;
  }

  #status-pill {
    top: 0.8rem;
    right: 0.8rem;
  }

  #status-shell {
    top: 0.8rem;
    right: 0.8rem;
  }

  body.state-connected #btn-disconnect-desktop {
    display: none;
  }

  body.state-connected #session-footer-action {
    display: block;
  }

  body.state-connected #status-shell:hover #send-preview-panel {
    display: none;
  }

  .preview-panel {
    width: min(13rem, calc(100vw - 2rem));
  }

  .session-note-panel {
    bottom: 4.6rem;
    width: calc(100vw - 2rem);
  }

  .actions {
    flex-direction: column;
  }

  .waiting-layout {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .qr-panel {
    width: min(11rem, 100%);
    padding: 0.2rem 0 0;
    justify-content: flex-start;
  }

  .invite-qr {
    max-width: 9.2rem;
  }

  button,
  input {
    width: 100%;
  }
}
