:root {
      color-scheme: dark;
      --brand-primary: #0f2f27;
      --brand-accent: #174036;
      --brand-highlight: #bcf5e7;
      --brand-shadow: rgba(15, 47, 39, 0.55);
      --text-primary: #f2f2f2;
      --text-muted: rgba(188, 245, 231, 0.78);
      --control-bg: rgba(16, 46, 38, 0.75);
      --control-border: rgba(188, 245, 231, 0.18);
    }

    * {
      box-sizing: border-box;
    }

    html, body {
      margin: 0;
      padding: 0;
      width: 100%;
      height: 100%;
      background: #000;
      font-family: "Roboto", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    }

    body.viewer-mode {
      display: flex;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      padding: 0;
    }

    body.controller-mode {
      background: #000;
      color: var(--text-primary);
      display: flex;
      flex-direction: column;
      min-height: 100%;
      padding: clamp(1.2rem, 4vw, 2.4rem);
      gap: clamp(1rem, 2.5vw, 1.5rem);
      overflow: hidden;
    }

    h1, h2, h3, p {
      margin: 0;
    }

    a {
      color: inherit;
    }

    button {
      background: var(--brand-primary);
      border: none;
      color: var(--text-primary);
      padding: 0.6rem 1.2rem;
      border-radius: 0.75rem;
      font-size: 1rem;
      cursor: pointer;
      transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s ease;
    }

    button:disabled {
      opacity: 0.5;
      cursor: not-allowed;
      box-shadow: none;
      transform: none;
    }

    button:not(:disabled):hover {
      box-shadow: 0 12px 28px var(--brand-shadow);
      transform: translateY(-2px);
      background: var(--brand-accent);
    }

    .viewer-shell {
      position: relative;
      width: 100vw;
      height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
      background: #000;
    }

    .viewer-surface {
      position: relative;
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      background: #000;
    }

    .viewer-surface img,
    .viewer-surface video {
      display: none;
      max-width: 100vw;
      max-height: 100vh;
      width: auto;
      height: auto;
      object-fit: contain;
      background: #000;
    }


.viewer-preload-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      gap: 1rem;
      color: var(--text-primary);
      font-size: 1rem;
      letter-spacing: 0.04em;
      z-index: 5;
      padding: 2rem;
      text-align: center;
    }

    .viewer-preload-overlay[hidden] {
      display: none;
    }

    .viewer-preload-progress {
      width: min(320px, 70vw);
      height: 6px;
      border-radius: 999px;
      background: rgba(255, 255, 255, 0.2);
      overflow: hidden;
    }

    .viewer-preload-progress span {
      display: block;
      height: 100%;
      width: 0;
      background: var(--brand-highlight);
      transform-origin: left center;
      transition: width 0.2s ease;
    }

    .viewer-preload-status {
      font-size: 0.9rem;
      color: var(--text-muted);
    }

    .audioPrompt {
      position: absolute;
      bottom: 2rem;
      left: 50%;
      transform: translateX(-50%);
      background: rgba(0, 0, 0, 0.75);
      color: #fff;
      padding: 0.75rem 1rem;
      border-radius: 0.65rem;
      font-size: 0.95rem;
      letter-spacing: 0.02em;
      display: none;
      white-space: nowrap;
    }

    .controller-layout {
      display: flex;
      flex-direction: column;
      gap: clamp(1rem, 3vw, 1.75rem);
      flex: 1;
      overflow: hidden;
      position: relative;
    }

    .controller-copyright {
      position: fixed;
      bottom: clamp(0.6rem, 2vw, 1.5rem);
      right: clamp(0.6rem, 2vw, 1.5rem);
      font-size: 0.78rem;
      color: var(--text-muted);
      letter-spacing: 0.05em;
      text-transform: uppercase;
      pointer-events: none;
      opacity: 0.75;
    }

    .controller-header {
      display: flex;
      flex-direction: column;
      gap: 0.75rem;
      position: relative;
      align-items: flex-start;
    }

    .brand-banner {
      display: flex;
      align-items: center;
      gap: 0.85rem;
      flex-wrap: wrap;
    }

    .brand-logo {
      width: clamp(52px, 12vw, 72px);
      height: clamp(52px, 12vw, 72px);
      object-fit: cover;
      border-radius: 18px;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
      background: rgba(0, 0, 0, 0.4);
      padding: 0.25rem;
    }

    .brand-text {
      display: none;
    }

    .status-text {
      font-size: 0.92rem;
      opacity: 0.78;
      line-height: 1.4;
      color: var(--text-muted);
    }

    .controller-user {
      display: flex;
      align-items: center;
      gap: 0.65rem;
      margin-left: auto;
    }

    .controller-user span {
      font-size: 0.95rem;
      color: var(--text-muted);
    }

    @keyframes fadeIn {
      from { opacity: 0; transform: translateY(-6px); }
      to { opacity: 1; transform: translateY(0); }
    }

    .controller-viewport {
      position: relative;
      flex: 1;
      min-height: 260px;
      border-radius: clamp(0.75rem, 3vw, 1.5rem);
      border: 1px solid var(--control-border);
      overflow: hidden;
      background: rgba(0, 0, 0, 0.85);
      display: flex;
      box-shadow: 0 16px 42px rgba(0, 0, 0, 0.45);
    }

    .controller-viewport iframe {
      width: 100%;
      height: 100%;
      border: none;
      background: #000;
    }

    .controller-actions {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: clamp(1rem, 4vw, 1.5rem);
      flex-wrap: wrap;
      margin-top: auto;
    }

    .controller-actions .nav-group {
      display: flex;
      gap: clamp(1rem, 4vw, 1.5rem);
      flex: 1;
      justify-content: center;
      background: var(--control-bg);
      border: 1px solid var(--control-border);
      border-radius: 1.4rem;
      padding: clamp(0.9rem, 3vw, 1.4rem);
      box-shadow: 0 18px 38px rgba(0, 0, 0, 0.35);
      flex-wrap: wrap;
    }

    .control-btn {
      flex: 1;
      min-width: 120px;
      max-width: 220px;
      padding: clamp(1.1rem, 2vw, 1.5rem) clamp(1.4rem, 4vw, 1.9rem);
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 0.45rem;
      background: rgba(11, 33, 27, 0.82);
      border: 1px solid rgba(188, 245, 231, 0.18);
      box-shadow: inset 0 0 0 1px rgba(188, 245, 231, 0.08), 0 24px 48px rgba(0, 0, 0, 0.35);
    }

    .control-btn .icon {
      font-size: clamp(2.1rem, 6vw, 2.8rem);
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .control-btn .icon svg {
      width: clamp(42px, 10vw, 56px);
      height: clamp(42px, 10vw, 56px);
      fill: var(--brand-highlight);
    }

    .control-btn .label {
      font-size: clamp(0.78rem, 2vw, 0.95rem);
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--text-muted);
    }

    .control-btn[data-state="standby"] {
      background: rgba(4, 13, 10, 0.9);
    }

    .audio-toggle {
      background: rgba(188, 245, 231, 0.12);
      border: 1px solid rgba(188, 245, 231, 0.28);
      color: var(--brand-highlight);
      width: 48px;
      height: 48px;
      border-radius: 999px;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 0;
      align-self: center;
    }

    .audio-toggle .audio-icon svg {
      width: 22px;
      height: 22px;
      fill: currentColor;
    }

    .audio-toggle .sr-only {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0, 0, 0, 0);
      border: 0;
    }

    .audio-toggle.active {
      color: var(--text-primary);
      background: rgba(188, 245, 231, 0.28);
    }

    .controller-footer {
      display: flex;
      flex-direction: column;
      gap: 1rem;
    }

    #viewerLayout {
      display: none;
    }

    #controllerLayout {
      display: none;
    }

    body.viewer-mode #viewerLayout {
      display: flex;
    }

    body.controller-mode #controllerLayout {
      display: flex;
    }

    .controller-auth-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.92);
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 2rem;
      z-index: 2000;
    }

    .controller-auth-overlay[hidden] {
      display: none;
    }

    .controller-auth-card {
      background: var(--control-bg, rgba(16, 46, 38, 0.75));
      border: 1px solid var(--control-border, rgba(188, 245, 231, 0.18));
      border-radius: 1rem;
      width: min(420px, 100%);
      padding: clamp(1.4rem, 4vw, 2rem);
      color: var(--text-primary, #f2f2f2);
      display: flex;
      flex-direction: column;
      gap: 0.75rem;
      box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
      backdrop-filter: blur(14px);
    }

    .controller-auth-card h2 {
      margin: 0;
      font-size: 1.35rem;
      font-weight: 600;
    }

    .controller-auth-card p {
      margin: 0 0 0.35rem;
      color: var(--text-muted, rgba(188, 245, 231, 0.78));
      font-size: 0.95rem;
    }

    .controller-auth-card label {
      font-size: 0.78rem;
      letter-spacing: 0.06em;
      text-transform: uppercase;
      color: var(--text-muted, rgba(188, 245, 231, 0.78));
    }

    .controller-auth-card input {
      width: 100%;
      padding: 0.65rem 0.75rem;
      border-radius: 0.6rem;
      border: 1px solid rgba(188, 245, 231, 0.24);
      background: rgba(12, 32, 26, 0.82);
      color: inherit;
      font-size: 1rem;
    }

    .controller-auth-card input:focus {
      outline: 2px solid var(--brand-highlight, #bcf5e7);
      outline-offset: 2px;
    }

    .controller-auth-card button {
      margin-top: 0.5rem;
      padding: 0.75rem 1rem;
      border: none;
      border-radius: 0.65rem;
      background: var(--brand-primary, #0f2f27);
      color: var(--text-primary, #f2f2f2);
      font-size: 1rem;
      font-weight: 600;
      cursor: pointer;
      transition: background 0.2s ease, transform 0.15s ease;
    }

    .controller-auth-card button:disabled {
      opacity: 0.6;
      cursor: not-allowed;
      transform: none;
    }

    .controller-auth-card button:not(:disabled):hover {
      background: var(--brand-accent, #174036);
      transform: translateY(-1px);
    }

    .controller-auth-providers-section {
      margin-top: 0.5rem;
      display: flex;
      flex-direction: column;
      gap: 0.75rem;
    }

    .controller-auth-divider {
      display: flex;
      align-items: center;
      gap: 0.75rem;
      color: var(--text-muted, rgba(188, 245, 231, 0.78));
      font-size: 0.85rem;
      letter-spacing: 0.06em;
      text-transform: uppercase;
    }

    .controller-auth-divider::before,
    .controller-auth-divider::after {
      content: "";
      flex: 1;
      height: 1px;
      background: rgba(188, 245, 231, 0.18);
    }

    .controller-auth-providers {
      display: flex;
      flex-direction: column;
      gap: 0.6rem;
    }

    .controller-auth-provider-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 0.5rem;
      background: rgba(23, 64, 54, 0.52);
      border: 1px solid rgba(188, 245, 231, 0.24);
      color: inherit;
      padding: 0.7rem 1rem;
      border-radius: 0.65rem;
      cursor: pointer;
      font-size: 0.98rem;
      font-weight: 600;
      transition: background 0.2s ease, transform 0.15s ease, border-color 0.2s ease;
    }

    .controller-auth-provider-btn:hover:not(:disabled) {
      background: rgba(28, 74, 62, 0.72);
      border-color: rgba(188, 245, 231, 0.45);
      transform: translateY(-1px);
    }

    .controller-auth-provider-btn:disabled {
      opacity: 0.6;
      cursor: not-allowed;
      transform: none;
    }

    .controller-auth-error {
      min-height: 1.2rem;
      font-size: 0.9rem;
      color: #ffb4a2;
    }

    .controller-signout-button {
      margin-left: auto;
      align-self: flex-end;
      background: transparent;
      border: 1px solid rgba(188, 245, 231, 0.24);
      color: inherit;
      padding: 0.4rem 0.85rem;
      border-radius: 0.6rem;
      font-size: 0.85rem;
      cursor: pointer;
      transition: background 0.2s ease, border-color 0.2s ease;
    }

    .controller-signout-button:hover:not(:disabled) {
      background: rgba(23, 64, 54, 0.55);
      border-color: rgba(188, 245, 231, 0.42);
    }

    .controller-signout-button:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }

    @media (min-width: 768px) {
      .controller-actions .nav-group {
        flex: none;
        width: auto;
      }

      .controller-actions button {
        flex: none;
      }

      .controller-actions {
        justify-content: center;
      }
    }

    @media (orientation: portrait) {
      body.viewer-mode .viewer-surface img,
      body.viewer-mode .viewer-surface video {
        max-width: 100vw;
        max-height: 100vh;
      }
    }

    @media (orientation: landscape) {
      body.viewer-mode .viewer-surface {
        padding: 2vh 4vw;
      }
    }
