:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  background: #050711;
  color: #f7f9ff;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }
.browser-auth {
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start; gap: 20px;
  padding: max(16px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  text-align: center; background: rgba(5, 7, 17, .97);
  overflow-y: auto; overscroll-behavior: contain;
}
.browser-auth > * { flex-shrink: 0; }
.browser-auth > :first-child { margin-top: auto; }
.browser-auth > :last-child { margin-bottom: auto; }
.browser-auth a { text-decoration: none; }
.browser-invite p { max-width: 38rem; line-height: 1.5; margin: 0; }
.browser-invite input {
  width: min(100%, 22rem); padding: 16px; border: 1px solid #00e5ff;
  border-radius: 8px; background: #101a30; color: #fff;
  font: 700 clamp(22px, 5vw, 32px) ui-monospace, monospace;
  letter-spacing: .15em; text-align: center; user-select: text;
}
.browser-invite button:disabled { opacity: .6; cursor: progress; }
.browser-invite [role="status"] { min-height: 3em; }
:focus-visible { outline: 3px solid #00e5ff; outline-offset: 3px; }
:root:fullscreen #nanoroom-shell {
  grid-template-rows: minmax(0, 1fr); padding: 0; gap: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
:root:fullscreen .shell-header, :root:fullscreen .shell-footer { display: none; }
:root:fullscreen #player-frame { width: 100%; height: 100%; border: 0; border-radius: 0; }
.mobile-player #nanoroom-shell {
  position: fixed; inset: 0; height: 100vh; height: 100dvh;
  grid-template-rows: minmax(0, 1fr); padding: 0; gap: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.mobile-player .shell-header, .mobile-player .shell-footer { display: none; }
.mobile-player #player-frame { border: 0; border-radius: 0; }
.orientation-panel {
  position: absolute; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  gap: 16px; padding: 24px; text-align: center; overflow-y: auto;
  background: #080a15;
}
.orientation-panel h1 { font-size: clamp(22px, 6vw, 32px); margin: 0; }
.orientation-panel p { max-width: 28rem; color: #b9c7df; line-height: 1.5; }
.orientation-panel > * { flex-shrink: 0; }
.orientation-panel > :first-child { margin-top: auto; }
.orientation-panel > :last-child { margin-bottom: auto; }
.rotate-phone { font-size: 64px; color: #00e5ff; }
.mobile-entry-panel { gap: 12px; padding: 16px max(24px, env(safe-area-inset-right)) 16px max(24px, env(safe-area-inset-left)); }
.mobile-entry-panel h1 { font-size: clamp(22px, 4vh, 30px); }
.mobile-entry-panel p { margin: 0; }
.mobile-entry-panel button { min-height: 44px; }
#mobile-entry-status:empty { display: none; }
.mobile-portrait #unity-canvas { visibility: hidden; pointer-events: none; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 0, 204, .16), transparent 32%),
    radial-gradient(circle at 82% 78%, rgba(0, 229, 255, .16), transparent 34%),
    #050711;
}

button { font: inherit; }

#nanoroom-shell {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: 48px minmax(0, 1fr) 28px;
  padding: 8px;
  gap: 8px;
}

.shell-header, .shell-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  color: #9ea9c7;
  font-size: 12px;
  letter-spacing: .08em;
}

.brand {
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .16em;
  text-shadow: 0 0 18px rgba(0, 229, 255, .7);
}

.shell-action, .primary-action {
  border: 1px solid rgba(0, 229, 255, .65);
  border-radius: 8px;
  background: rgba(12, 20, 42, .92);
  color: #f7f9ff;
  padding: 8px 14px;
  cursor: pointer;
}

.shell-action:hover, .primary-action:hover,
.shell-action:focus-visible, .primary-action:focus-visible {
  border-color: #ff32d2;
  box-shadow: 0 0 18px rgba(255, 50, 210, .32);
  outline: none;
}

#player-frame {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(72, 231, 255, .32);
  border-radius: 12px;
  background: #080a15;
  box-shadow: 0 0 40px rgba(0, 229, 255, .1), inset 0 0 30px rgba(0, 0, 0, .45);
}

#unity-canvas {
  /* The drawing buffer must follow the frame, not size its grid track.
     This applies to desktop too; otherwise resizing can crop the menu. */
  position: absolute;
  inset: 0;
  margin: auto;
  min-width: 0;
  min-height: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #080a15;
  outline: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Keep sprite artwork at a readable game-surface size on 1440p/4K/ultrawide
   monitors, including fullscreen. Unity still renders text at device density.
   Phones keep their entire touch surface, without desktop letterboxing. */
:root:not(.mobile-player) #unity-canvas {
  max-width: 1920px;
  max-height: 1080px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 28px;
  text-align: center;
  background: linear-gradient(145deg, rgba(6, 8, 20, .98), rgba(11, 15, 35, .96));
}

.overlay.hidden { display: none; }
.overlay h1 { margin: 0; font-size: clamp(22px, 3vw, 38px); }
.overlay p { margin: 0; color: #aeb8d6; }

.loader-mark {
  width: 58px;
  height: 58px;
  border: 4px solid rgba(0, 229, 255, .18);
  border-top-color: #00e5ff;
  border-right-color: #ff32d2;
  border-radius: 50%;
  animation: spin .85s linear infinite;
  box-shadow: 0 0 24px rgba(0, 229, 255, .35);
}

.progress-track {
  width: min(420px, 70vw);
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #18213d;
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #00e5ff, #ff32d2);
  box-shadow: 0 0 16px rgba(0, 229, 255, .6);
  transition: width .12s linear;
}

#unity-warning {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 4;
  width: min(720px, calc(100% - 24px));
  transform: translateX(-50%);
}

.banner {
  margin-bottom: 8px;
  padding: 10px 14px;
  border-radius: 8px;
  color: #fff;
  background: rgba(124, 82, 0, .95);
}

.banner.error { background: rgba(145, 20, 50, .96); }

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

@media (max-width: 700px), (max-height: 560px) {
  #nanoroom-shell { grid-template-rows: minmax(0, 1fr); padding: 0; gap: 0; }
  .shell-header, .shell-footer { display: none; }
  #player-frame { border: 0; border-radius: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .loader-mark { animation-duration: 1.8s; }
  .progress-bar { transition: none; }
}
