:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #080e19;
  color: #eef4ff;
  --page: #0b1425;
  --panel: #101e34;
  --muted: #b7c8e2;
  --line: #354963;
  --accent: #bfddff;
  --safe-top: max(12px, env(safe-area-inset-top, 0px));
  --safe-right: max(12px, env(safe-area-inset-right, 0px));
  --safe-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  --safe-left: max(12px, env(safe-area-inset-left, 0px));
}

*, *::before, *::after { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
[hidden] { display: none !important; }
button, textarea { font: inherit; }
button {
  min-height: 44px;
  color: inherit;
  background: #182944;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6em 0.9em;
  cursor: pointer;
}
button:focus-visible, textarea:focus-visible { outline: 2px solid #a0cefd; outline-offset: 3px; }
button:disabled { opacity: 0.6; cursor: default; }
button[aria-pressed="true"] { background: #294969; border-color: #a0cefd; }
.primary { font-weight: 700; background: var(--accent); color: #112542; border-color: transparent; }
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  resize: none;
  background: #0a1527;
  color: inherit;
  border: 1px solid #53708f;
  border-radius: 8px;
  font-size: 16px;
}

.welcome {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: max(24px, var(--safe-top)) max(16px, var(--safe-right)) max(24px, var(--safe-bottom)) max(16px, var(--safe-left));
  background: radial-gradient(ellipse at top, #172b47, var(--page) 68%);
}

.join-panel {
  background: var(--panel);
  padding: clamp(20px, 5vw, 34px);
  border: 1px solid #2b415d;
  border-radius: 18px;
  width: min(100%, 500px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--accent); }
.brand img { border-radius: 11px; }
h1 { font-size: clamp(1.55rem, 5.7vw, 2.2rem); margin: 16px 0 8px; line-height: 1.13; }
p { color: var(--muted); line-height: 1.45; margin: 0 0 20px; }
label { display: block; margin-bottom: 8px; font-size: 0.9rem; font-weight: 640; }
.trusted-device { display: grid; gap: 8px; margin: 18px 0; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.secondary-button { background: transparent; }
.field-hint { margin: 0 0 8px; font-size: 0.85rem; }
#storage-hint { margin-top: 12px; }
.join-actions { display: flex; gap: 8px; margin-top: 12px; }
.join-actions .primary { flex: 1; }
.status { margin: 12px 0 0; }
.status:empty { display: none; }
.status[data-error="true"] { color: #ffbcc3; }
.home-hint { border-top: 1px solid #30445e; margin: 20px 0 0; padding-top: 14px; font-size: 0.85rem; }

.session, .stage { position: fixed; inset: 0; background: #05080e; overscroll-behavior: none; }
.stage { touch-action: none; overflow: hidden; outline: none; }
.stage:focus-visible { outline: 2px solid #a0cefd; outline-offset: -2px; }
.stage img { display: block; width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-select: none; pointer-events: none; }
.stage[data-fit="cover"] img { object-fit: cover; }
.frame-status { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 20px; pointer-events: none; }
.frame-status-content { display: grid; justify-items: center; gap: 12px; text-align: center; }
.frame-status-content p { margin: 0; }
.frame-status-content button { pointer-events: auto; }

.control-area {
  position: fixed;
  top: var(--safe-top);
  right: var(--safe-right);
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-height: calc(100% - var(--safe-top) - var(--safe-bottom));
}
.tool-toggle {
  width: 44px;
  padding: 0;
  background: rgba(13, 25, 42, 0.92);
  border-color: #7893b2;
  border-radius: 13px;
}
.tool-dots { display: block; font-size: 1.9rem; letter-spacing: 1px; line-height: 1; transform: translateY(-2px); }
.tools {
  min-width: 152px;
  max-width: calc(100vw - var(--safe-left) - var(--safe-right));
  padding: 8px;
  overflow: auto;
  background: #101d31;
  border: 1px solid #5a7392;
  border-radius: 12px;
  box-shadow: 0 8px 32px #0008;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tools button { text-align: left; white-space: nowrap; }
.permission { font-size: 0.78rem; margin: 0; padding: 4px; }
.disconnect { color: #ffd2d7; }
.keyboard-panel {
  position: fixed;
  z-index: 3;
  display: flex;
  gap: 6px;
  align-items: center;
  top: var(--safe-top);
  left: var(--safe-left);
  right: calc(var(--safe-right) + 52px);
  max-width: 480px;
  padding: 6px;
  background: #101d31;
  border: 1px solid #5a7392;
  border-radius: 12px;
}
.keyboard-panel textarea { min-width: 0; height: 44px; flex: 1; }
.keyboard-panel button { padding-inline: 8px; }
@media (max-width: 420px) { .keyboard-panel button { font-size: 0.82rem; } }
@media (max-height: 420px) { .welcome { align-items: start; } }
