* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  background: #111;
  color: #eee;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}
body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
header {
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0));
  background: #1a1a1a;
  border-bottom: 1px solid #333;
  flex: 0 0 auto;
}
#nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  row-gap: 6px;
}
#nav input,
#nav button,
#nav select {
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}
#nav input {
  flex: 1 1 200px;
  min-width: 140px;
  padding: 8px 10px;
  font-size: 16px;
  border: 1px solid #444;
  background: #222;
  color: #fff;
  border-radius: 6px;
}
#nav button {
  padding: 8px 14px;
  border: none;
  background: #2d6cdf;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  min-height: 40px;
  touch-action: manipulation;
}
#nav button.icon {
  padding: 8px 10px;
  font-size: 18px;
  line-height: 1;
}
#nav button:disabled {
  opacity: .45;
  cursor: default;
}
#nav select {
  padding: 8px 28px 8px 10px;
  font-size: 14px;
  border: 1px solid #444;
  background: #222 url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path fill='%23bbb' d='M1 1l5 5 5-5'/></svg>") no-repeat right 10px center;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  max-width: 100%;
}
#nav #rw,
#nav #rh {
  flex: 0 0 86px;
  width: 86px;
  min-width: 72px;
  text-align: center;
}
#nav span {
  color: #aaa;
  font-size: 13px;
}
#cookie-toggle {
  background: #444;
  white-space: nowrap;
}
#cookie-toggle.on {
  background: #2f7d4f;
}
#cookie-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px calc(16px + env(safe-area-inset-right, 0)) calc(16px + env(safe-area-inset-bottom, 0)) calc(16px + env(safe-area-inset-left, 0));
  background: rgba(0, 0, 0, .72);
}
#cookie-modal.hidden {
  display: none;
}
.cookie-modal-box {
  width: 100%;
  max-width: 540px;
  padding: 18px 18px 16px;
  background: #1e2430;
  border: 1px solid #333;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .6);
  max-height: 90dvh;
  overflow: auto;
}
.cookie-modal-box h2 {
  margin: 0 0 10px;
  font-size: 18px;
}
.cookie-modal-box p {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.55;
  color: #cfd6e2;
}
.cookie-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.cookie-modal-actions button {
  padding: 9px 16px;
  font-size: 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  background: #2d6cdf;
  color: #fff;
  min-height: 40px;
  touch-action: manipulation;
}
.cookie-modal-actions button#cookie-decline {
  background: #444;
}
#status-box {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  line-height: 1.15;
  min-width: 76px;
  margin-left: auto;
}
#ping {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: #7fd18a;
}
#ping.warn {
  color: #e6c15a;
}
#ping.bad {
  color: #ef7d7d;
}
#ping.off {
  color: #888;
}
#status {
  font-size: 12px;
  color: #aaa;
}
main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
  padding: 0 env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
  -webkit-overflow-scrolling: touch;
}
#viewer {
  outline: none;
  cursor: default;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
#screen,
#video-canvas,
#webrtc-video {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}
#video-canvas {
  display: none;
  background: #000;
}
#viewer.video #screen {
  display: none;
}
#viewer.video #video-canvas {
  display: block;
}
#webrtc-video {
  display: none;
  background: #000;
}
#viewer.webrtc #screen,
#viewer.webrtc #video-canvas {
  display: none;
}
#viewer.webrtc #webrtc-video {
  display: block;
}
#browser-frame {
  display: none;
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}
body.mode-browser #viewer {
  display: none;
}
body.mode-browser #browser-frame {
  display: block;
}
body.mode-browser #video-mode,
body.mode-browser #preset,
body.mode-browser #rw,
body.mode-browser #rh,
body.mode-browser #applySize,
body.mode-browser #nav > span:not(#status-box),
body.mode-browser #kb-toggle {
  display: none !important;
}
@media (max-width: 900px) {
  #status-box {
    display: none;
  }
}
@media (max-width: 720px) {
  header {
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0));
  }
  #nav {
    gap: 4px;
  }
  #nav button {
    padding: 7px 10px;
    font-size: 13px;
    min-height: 38px;
  }
  #nav button.icon {
    padding: 7px 9px;
    font-size: 16px;
  }
  #nav input {
    font-size: 16px;
    padding: 7px 9px;
  }
  #nav select {
    font-size: 13px;
    padding: 7px 24px 7px 9px;
  }
  #nav #rw,
  #nav #rh {
    flex-basis: 72px;
    width: 72px;
  }
  #screen,
  #video-canvas,
  #webrtc-video {
    max-height: calc(100dvh - 150px);
  }
}
@media (max-width: 520px) {
  #nav input {
    order: -1;
    flex-basis: 100%;
  }
  #screen,
  #video-canvas,
  #webrtc-video {
    max-height: calc(100dvh - 190px);
  }
}

#auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px calc(16px + env(safe-area-inset-right, 0)) calc(16px + env(safe-area-inset-bottom, 0)) calc(16px + env(safe-area-inset-left, 0));
}
#auth-overlay.hidden { display: none; }
.auth-box {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 22px 20px;
  width: min(360px, 100%);
  max-width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.7);
}
.auth-box h2 { margin: 0 0 8px 0; font-size: 18px; }
.auth-box p { margin: 0 0 16px 0; color: #aaa; font-size: 14px; line-height: 1.5; }
#auth-form { display: flex; gap: 8px; flex-wrap: wrap; }
#auth-form input {
  flex: 1 1 180px;
  padding: 9px 10px;
  font-size: 16px;
  border: 1px solid #444;
  background: #222;
  color: #fff;
  border-radius: 6px;
}
#auth-form button {
  padding: 9px 16px;
  border: none;
  background: #2d6cdf;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  min-height: 42px;
  touch-action: manipulation;
}
.auth-or { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: #777; font-size: 12px; }
.auth-or::before, .auth-or::after { content: ''; flex: 1; height: 1px; background: #333; }
#discord-auth {
  width: 100%;
  padding: 11px 16px;
  border: none;
  border-radius: 6px;
  background: #5865f2;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  touch-action: manipulation;
}
#discord-auth:hover { background: #4752c4; }
#discord-auth:disabled { opacity: .6; cursor: default; }
#auth-status { margin-top: 12px; font-size: 13px; color: #ff8a8a; min-height: 18px; line-height: 1.5; }
#discord-bar {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom, 0));
  transform: translateX(-50%);
  z-index: 1100;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(94vw, 640px);
  max-width: 94vw;
  padding: 10px 12px;
  background: #1e2430;
  border: 1px solid #3a4557;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .7);
  color: #dfe6f1;
  font-size: 13px;
  pointer-events: none;
  flex-wrap: wrap;
}
#discord-bar.hidden { display: none; }
#discord-msg { line-height: 1.4; flex: 1 1 200px; }
#discord-bar button {
  pointer-events: auto;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: #444;
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  min-height: 38px;
  touch-action: manipulation;
}
#discord-bar button:disabled { opacity: .6; cursor: default; }

#kb-toggle {
  position: fixed;
  right: calc(12px + env(safe-area-inset-right, 0));
  bottom: calc(14px + env(safe-area-inset-bottom, 0));
  z-index: 1200;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid #3a3a3a;
  background: rgba(26, 26, 26, 0.94);
  color: #eee;
  font-size: 22px;
  line-height: 1;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.7);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#kb-toggle.visible {
  display: flex;
}
#kb-toggle:active {
  transform: scale(0.96);
}

@media (hover: none) and (pointer: coarse) {
  #kb-toggle.visible {
    display: flex;
  }
}

#softkb {
  position: fixed;
  left: 50%;
  bottom: 10px;
  width: 1px;
  height: 1px;
  opacity: 0.01;
  border: none;
  padding: 0;
  margin: 0;
  z-index: 2000;
  background: transparent;
  pointer-events: none;
}
