:root {
  color-scheme: dark;
  font-size: 112.5%;
  --bg: #000000;
  --surface: rgba(12, 14, 18, 0.72);
  --surface-solid: #0c0e12;
  --text: #e8edf4;
  --muted: #7d8fa3;
  --accent: #3d9cf5;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --border: rgba(255, 255, 255, 0.1);
  --vv-top: 0px;
  --vv-left: 0px;
  --vv-w: 100%;
  --vv-h: 100%;
  --pwa-fill-h: 100%;
  --pwa-extra-b: 0px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

html.pwa-standalone,
html.pwa-standalone body {
  height: calc(var(--pwa-fill-h, 100%) + var(--pwa-extra-b, 0px));
  min-height: calc(var(--pwa-fill-h, 100%) + var(--pwa-extra-b, 0px));
  max-height: none;
}

.shell {
  position: fixed;
  top: var(--vv-top, 0px);
  left: var(--vv-left, 0px);
  width: var(--vv-w, 100%);
  height: var(--vv-h, 100%);
  right: auto;
  bottom: auto;
  overflow: hidden;
  background: #000;
}

html.pwa-standalone .shell {
  top: 0;
  left: 0;
  right: auto;
  bottom: auto;
  width: 100%;
  height: calc(var(--pwa-fill-h, 100%) + var(--pwa-extra-b, 0px));
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.chrome {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 3;
  pointer-events: none;
}

.chrome > * {
  pointer-events: auto;
}

.chrome.top {
  top: 0;
  padding:
    env(safe-area-inset-top, 0px)
    max(0.55rem, env(safe-area-inset-right, 0px))
    0
    max(0.55rem, env(safe-area-inset-left, 0px));
}

header {
  text-align: center;
}

header h1 {
  margin: 0;
  font-family: "Michroma", system-ui, sans-serif;
  font-size: clamp(1.05rem, 3.2vmin, 1.35rem);
  font-weight: 400;
  letter-spacing: 0.1em;
  line-height: 1.15;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.55);
}

.status {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.22rem;
  margin-top: 0.18rem;
}

.pill {
  font-size: 0.48rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.1rem 0.36rem;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.pill.on {
  color: var(--green);
  border-color: rgba(52, 211, 153, 0.4);
  background: rgba(52, 211, 153, 0.12);
}

.pill.warn {
  color: var(--amber);
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.12);
}

.pill.rec {
  color: var(--red);
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.14);
}

.mono {
  font-family: ui-monospace, Menlo, monospace;
}

.stats {
  width: min(22rem, 100%);
  margin: 0.28rem auto 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.16rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.38rem;
  padding: 0.12rem 0.22rem 0.14rem;
  text-align: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: none;
}

.stat .lbl {
  display: block;
  font-size: 0.42rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat .val {
  display: block;
  margin-top: 0.02rem;
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--text);
}

.chrome.bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 4;
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  padding:
    0.15rem
    max(0.35rem, env(safe-area-inset-right, 0px))
    0.35rem
    max(0.35rem, env(safe-area-inset-left, 0px));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.5) 70%, transparent 100%);
  pointer-events: none;
}

/* PWA only: paint into home-indicator strip; Safari tab stays on VV floor. */
html.pwa-standalone .chrome.bottom {
  padding-bottom: max(0.35rem, env(safe-area-inset-bottom, 0px));
}

.chrome.bottom input,
.chrome.bottom button {
  pointer-events: auto;
  touch-action: manipulation;
}

.chrome.bottom #time-slider {
  touch-action: pan-x;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.slider-label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.7rem;
  color: var(--muted);
  width: 1rem;
  text-align: center;
}

.time-label {
  font-size: 0.62rem;
  color: var(--muted);
  min-width: 3.2rem;
  text-align: right;
}

#time-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 0.28rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  outline: none;
}

#time-slider:disabled {
  opacity: 0.4;
}

#time-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 0 0 3px rgba(61, 156, 245, 0.25);
  cursor: pointer;
}

#time-slider::-moz-range-thumb {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.toggles {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.28rem;
}

.chip {
  font: inherit;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.28rem 0.58rem;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.chip.on {
  color: var(--text);
  border-color: rgba(61, 156, 245, 0.45);
  background: rgba(61, 156, 245, 0.16);
}

.actions {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr 1fr;
  gap: 0.28rem;
}

.btn {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.5rem 0.35rem;
  cursor: pointer;
  min-height: 2.35rem;
}

.btn:disabled {
  opacity: 0.38;
  cursor: default;
}

.btn.primary {
  background: linear-gradient(180deg, #2f7fd4 0%, #1f5fa8 100%);
  border-color: rgba(61, 156, 245, 0.5);
}

.btn.primary.is-rec {
  background: linear-gradient(180deg, #c44 0%, #922 100%);
  border-color: rgba(248, 113, 113, 0.45);
}

.btn.danger {
  color: #fca5a5;
}

@media (pointer: coarse) and (min-width: 600px) and (min-height: 600px) {
  .chrome.bottom {
    max-width: 620px;
    gap: 0.28rem;
    padding-left: max(0.55rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.55rem, env(safe-area-inset-right, 0px));
  }
}

@media (min-width: 700px) {
  .stats {
    width: min(28rem, 70vw);
  }

  .actions {
    max-width: 28rem;
    margin: 0 auto;
    width: 100%;
  }

  .toggles {
    max-width: 28rem;
    margin: 0 auto;
    width: 100%;
  }

  .slider-row {
    max-width: 28rem;
    margin: 0 auto;
    width: 100%;
  }
}
