:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #08111f;
}

* { box-sizing: border-box; }

button,
input { font: inherit; }

html,
body,
#mixer-shell,
#unity-canvas {
  width: 100%;
  height: 100%;
}

html,
body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(circle at 50% 38%, rgba(54, 101, 160, 0.25), transparent 42%),
    linear-gradient(145deg, #101b2f, #07101d 62%, #050a13);
}

#mixer-shell {
  position: fixed;
  inset: 0;
  isolation: isolate;
}

#unity-canvas {
  position: absolute;
  inset: 0;
  display: block;
  border: 0;
  outline: none;
  background: #101827;
}

#mixer-shell.is-mobile #unity-canvas { visibility: hidden; }

#sandbox-utility {
  position: fixed;
  z-index: 8;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  display: flex;
  max-width: calc(100vw - max(32px, env(safe-area-inset-left)) - max(32px, env(safe-area-inset-right)));
  align-items: center;
  gap: 12px;
  padding: 8px;
  transform: translateX(-50%);
  border: 1px solid rgba(171, 199, 235, 0.18);
  border-radius: 14px;
  background: rgba(8, 18, 32, 0.92);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(18px);
}

#sandbox-utility[hidden],
#sandbox-status[hidden],
#share-fallback[hidden],
#evidence-fallback[hidden] { display: none; }

.sandbox-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.utility-button {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border: 1px solid rgba(255, 189, 88, 0.5);
  border-radius: 9px;
  color: #172032;
  background: #ffb84d;
  font-size: 13px;
  font-weight: 750;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.utility-button:hover:not(:disabled) { background: #ffc86f; }

.utility-button:focus-visible,
#share-url:focus-visible {
  outline: 2px solid #f4f8ff;
  outline-offset: 2px;
}

.utility-button:disabled {
  cursor: wait;
  opacity: 0.45;
}

.utility-button-quiet {
  border-color: rgba(171, 199, 235, 0.2);
  color: #d9e5f6;
  background: #172942;
}

.utility-button-quiet:hover:not(:disabled) { background: #223958; }

#runtime-stats {
  display: flex;
  min-width: 0;
  margin: 0;
  gap: 4px;
}

.runtime-stat {
  min-width: 58px;
  padding: 3px 8px;
  border-left: 1px solid rgba(171, 199, 235, 0.14);
  font-variant-numeric: tabular-nums;
}

.runtime-stat-wide { min-width: 132px; }

.runtime-stat dt {
  overflow: hidden;
  color: #8fa2bc;
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.06em;
  line-height: 1.2;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.runtime-stat dd {
  margin: 2px 0 0;
  overflow: hidden;
  color: #edf4ff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#sandbox-status {
  position: fixed;
  z-index: 19;
  top: max(78px, calc(env(safe-area-inset-top) + 78px));
  left: 50%;
  width: max-content;
  max-width: calc(100vw - 36px);
  padding: 9px 13px;
  transform: translateX(-50%);
  border: 1px solid rgba(171, 199, 235, 0.22);
  border-radius: 10px;
  color: #e8f1ff;
  background: rgba(8, 18, 32, 0.96);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.34);
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
}

#sandbox-status.status-success {
  border-color: rgba(81, 227, 177, 0.4);
  color: #aef5dc;
}

#sandbox-status.status-error {
  border-color: rgba(255, 117, 117, 0.48);
  color: #ffe7e7;
}

#share-fallback,
#evidence-fallback {
  position: fixed;
  z-index: 18;
  top: max(122px, calc(env(safe-area-inset-top) + 122px));
  left: 50%;
  width: min(650px, calc(100vw - 36px));
  max-height: calc(100vh - 150px);
  overflow: auto;
  padding: 13px;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 189, 88, 0.34);
  border-radius: 13px;
  color: #edf4ff;
  background: rgba(8, 18, 32, 0.98);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.4);
}

#share-fallback-title,
#evidence-fallback-title {
  margin-bottom: 8px;
  color: #ffca75;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.share-fallback-row {
  display: flex;
  min-width: 0;
  gap: 7px;
}

#evidence-fallback p {
  margin-bottom: 10px;
  font-size: 12px;
}

.evidence-fallback-row {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

#share-url {
  min-width: 0;
  flex: 1 1 auto;
  padding: 8px 10px;
  border: 1px solid rgba(171, 199, 235, 0.2);
  border-radius: 9px;
  color: #e7effb;
  background: #07101d;
  font-size: 12px;
}

#loading,
#mobile-notice {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding:
    max(24px, env(safe-area-inset-top))
    max(24px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(24px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 50% 42%, rgba(58, 106, 166, 0.34), transparent 36%),
    rgba(6, 12, 23, 0.96);
}

#loading[hidden],
#mobile-notice[hidden] { display: none; }

#mobile-notice { overflow: auto; }

.loading-card,
.notice-card {
  width: min(440px, 100%);
  padding: 34px;
  border: 1px solid rgba(171, 199, 235, 0.17);
  border-radius: 22px;
  background: rgba(13, 25, 43, 0.92);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.42);
  text-align: center;
  backdrop-filter: blur(18px);
}

.eyebrow {
  color: #ffbd58;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
}

h1 {
  margin: 10px 0 8px;
  color: #f4f8ff;
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1.08;
}

p {
  margin: 0;
  color: #aebdd2;
  font-size: 15px;
  line-height: 1.5;
}

.progress-track {
  height: 8px;
  margin-top: 28px;
  overflow: hidden;
  border-radius: 999px;
  background: #07101d;
}

#progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff9e45, #ffd06e);
  box-shadow: 0 0 22px rgba(255, 181, 72, 0.45);
  transition: width 140ms ease-out;
}

#progress-label {
  margin-top: 10px;
  color: #d9e5f6;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

#unity-warning {
  position: fixed;
  z-index: 20;
  top: max(18px, env(safe-area-inset-top));
  left: 50%;
  width: min(680px, calc(100% - 36px));
  transform: translateX(-50%);
  pointer-events: none;
}

#mixer-shell.is-ready #unity-warning {
  top: max(78px, calc(env(safe-area-inset-top) + 78px));
}

.banner {
  margin-bottom: 8px;
  padding: 12px 16px;
  border: 1px solid rgba(255, 204, 112, 0.35);
  border-radius: 10px;
  color: #fff6df;
  background: rgba(77, 54, 20, 0.95);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
}

.banner-error {
  border-color: rgba(255, 117, 117, 0.45);
  color: #ffe7e7;
  background: rgba(80, 22, 31, 0.96);
}

@media (max-width: 920px) and (pointer: fine) {
  #sandbox-utility {
    width: min(620px, calc(100vw - 24px));
    flex-wrap: wrap;
    justify-content: center;
  }

  #runtime-stats { justify-content: center; }

  #sandbox-status,
  #mixer-shell.is-ready #unity-warning {
    top: max(116px, calc(env(safe-area-inset-top) + 116px));
  }

  #share-fallback,
  #evidence-fallback {
    top: max(158px, calc(env(safe-area-inset-top) + 158px));
  }
}

@media (max-width: 540px) {
  .loading-card,
  .notice-card {
    padding: 26px 22px;
    border-radius: 18px;
  }

  .share-fallback-row { flex-wrap: wrap; }

  #share-url {
    flex-basis: 100%;
    width: 100%;
  }
}

@media (max-width: 420px) and (pointer: fine) {
  #runtime-stats {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .runtime-stat,
  .runtime-stat-wide {
    min-width: 0;
  }

  #sandbox-status,
  #mixer-shell.is-ready #unity-warning {
    top: max(166px, calc(env(safe-area-inset-top) + 166px));
  }

  #share-fallback,
  #evidence-fallback {
    top: max(208px, calc(env(safe-area-inset-top) + 208px));
  }
}

@media (max-height: 420px) {
  #sandbox-status,
  #mixer-shell.is-ready #unity-warning {
    top: max(8px, env(safe-area-inset-top));
  }

  #share-fallback,
  #evidence-fallback {
    top: max(52px, calc(env(safe-area-inset-top) + 52px));
    bottom: max(8px, env(safe-area-inset-bottom));
    max-height: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #progress-fill { transition: none; }
}
