:root {
  --red: #ff3b30;
  --yellow: #ffcc00;
  --green: #30d158;
  --unknown: #a1a1a6;
  --panel: rgba(18, 18, 20, 0.92);
  --text: #f5f5f7;
  --muted: #a1a1a6;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

#stage { position: fixed; inset: 0; background: #000; }

#video, #photo {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform-origin: 50% 50%;
}
#photo { object-fit: contain; }
#stage.contain #video { object-fit: contain; }

#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* Colored glow around the screen edge for the current light */
#edge {
  position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 0 0 transparent;
  transition: box-shadow 0.25s ease;
}
#edge.red    { box-shadow: inset 0 0 0 10px var(--red),    inset 0 0 60px 20px rgba(255, 59, 48, 0.55); }
#edge.yellow { box-shadow: inset 0 0 0 10px var(--yellow), inset 0 0 60px 20px rgba(255, 204, 0, 0.5); }
#edge.green  { box-shadow: inset 0 0 0 10px var(--green),  inset 0 0 60px 20px rgba(48, 209, 88, 0.5); }

/* Top bar */
#topbar {
  position: fixed; left: 0; right: 0; top: 0;
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: linear-gradient(rgba(0,0,0,0.65), rgba(0,0,0,0));
  z-index: 5;
}
#status {
  font: 500 13px/1.3 ui-monospace, "SF Mono", Menlo, monospace;
  color: #e5e5ea; text-shadow: 0 1px 2px #000;
  white-space: pre-line;
}
.top-actions { display: flex; gap: 10px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 22px; border: 0;
  background: rgba(40, 40, 44, 0.7); color: #fff; font-size: 20px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}

/* Announcement banner */
#banner {
  position: fixed; left: 16px; right: 16px;
  bottom: calc(var(--safe-bottom) + 20px);
  min-height: 92px;
  border-radius: 24px;
  display: flex; align-items: center; gap: 18px;
  padding: 16px 22px;
  background: rgba(28, 28, 30, 0.82);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  z-index: 5;
  transition: background 0.2s ease, transform 0.2s ease;
}
#bannerLamp {
  flex: none; width: 56px; height: 56px; border-radius: 50%;
  background: #3a3a3c; border: 3px solid rgba(255,255,255,0.25);
}
#bannerText { font-size: 22px; font-weight: 600; line-height: 1.2; }

#banner.red    { background: var(--red); }
#banner.yellow { background: var(--yellow); color: #1c1c1e; }
#banner.green  { background: var(--green); color: #0b2814; }
#banner.red #bannerText, #banner.yellow #bannerText, #banner.green #bannerText {
  font-size: 40px; font-weight: 800; letter-spacing: 0.04em;
}
#banner.red #bannerLamp, #banner.yellow #bannerLamp, #banner.green #bannerLamp {
  background: #fff; border-color: rgba(0,0,0,0.25);
  box-shadow: 0 0 24px 6px rgba(255,255,255,0.8);
}
#banner.pulse { animation: pulse 0.5s ease; }
@keyframes pulse { 0% { transform: scale(1); } 40% { transform: scale(1.05); } 100% { transform: scale(1); } }

/* Volume panel */
#volPanel {
  position: fixed; z-index: 6;
  top: calc(var(--safe-top) + 62px); right: 16px;
  width: min(340px, calc(100vw - 32px));
  padding: 16px; border-radius: 20px;
  background: var(--panel);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
#volPanel[hidden] { display: none; }
.vol-row { display: flex; align-items: center; gap: 10px; font-size: 18px; }
.vol-row input { flex: 1; min-width: 0; accent-color: #0a84ff; height: 32px; }
#volVal { width: 3.2em; text-align: right; font-size: 16px; font-variant-numeric: tabular-nums; }
.vol-actions { display: flex; gap: 10px; margin-top: 12px; }
.vol-actions button { font-size: 16px; padding: 13px 10px; }
#btnMuteToggle.on { background: var(--red); }
.vol-hint { margin: 10px 0 0; color: var(--muted); font-size: 13px; }

/* Lens switcher */
#lensBar {
  position: fixed; z-index: 5; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 20px + 92px + 14px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
#lensBar[hidden] { display: none; }
#lensButtons {
  display: flex; gap: 6px; padding: 5px; border-radius: 26px;
  background: rgba(28, 28, 30, 0.7);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#lensButtons button {
  min-width: 52px; height: 42px; padding: 0 12px; border: 0; border-radius: 21px;
  background: rgba(60, 60, 64, 0.8); color: #fff;
  font: 600 15px/1 -apple-system, system-ui, sans-serif;
}
#lensButtons button[aria-checked="true"] { background: rgba(0,0,0,0.85); color: var(--yellow); }
#zoomRow {
  display: flex; align-items: center; gap: 10px; width: 240px;
  padding: 4px 14px; border-radius: 20px; background: rgba(28, 28, 30, 0.7);
}
#zoomRow[hidden] { display: none; }
#zoomRow input { flex: 1; accent-color: var(--yellow); height: 30px; }
#camZoomVal { font-size: 14px; width: 3em; text-align: right; color: var(--yellow); font-variant-numeric: tabular-nums; }

/* Sheets */
.sheet {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  background: rgba(0, 0, 0, 0.88);
  overflow-y: auto;
}
.sheet[hidden] { display: none; }

.start-inner, .settings-inner { width: 100%; max-width: 420px; text-align: center; }

.logo {
  display: inline-flex; flex-direction: column; gap: 8px;
  padding: 12px; border-radius: 18px; background: #1c1c1e;
  border: 2px solid #3a3a3c;
}
.logo span { width: 34px; height: 34px; border-radius: 50%; }
.logo .r { background: var(--red); box-shadow: 0 0 14px var(--red); }
.logo .y { background: var(--yellow); opacity: 0.35; }
.logo .g { background: var(--green); opacity: 0.35; }

h1 { font-size: 30px; margin: 18px 0 8px; }
h2 { font-size: 24px; margin: 0 0 16px; }
h2 .version { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 6px; }
.lead { color: #d1d1d6; font-size: 17px; line-height: 1.4; margin: 0 0 22px; }
.fine { color: var(--muted); font-size: 13px; line-height: 1.45; margin-top: 22px; }

#loadWrap { height: 6px; border-radius: 3px; background: #2c2c2e; overflow: hidden; }
#loadBar { height: 100%; width: 0; background: var(--green); transition: width 0.2s ease; }
#loadText { color: var(--muted); font-size: 14px; margin: 8px 0 20px; min-height: 1.3em; }

button.primary, button.secondary, .file-btn {
  display: block; width: 100%;
  font: 600 18px/1 -apple-system, system-ui, sans-serif;
  border: 0; border-radius: 14px; padding: 17px 20px;
}
button.primary { background: #0a84ff; color: #fff; }
button.secondary, .file-btn { background: #2c2c2e; color: #fff; }
.file-btn { margin-top: 12px; font-size: 16px; position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; font-size: 100px; }

/* Settings rows */
.settings-inner { text-align: left; background: var(--panel); border-radius: 22px; padding: 22px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 13px 0; border-bottom: 1px solid #2c2c2e; font-size: 17px;
}
.row.col { flex-direction: column; align-items: stretch; }
.row small { display: block; color: var(--muted); font-size: 13px; margin-top: 3px; }
.row input[type=checkbox] { width: 26px; height: 26px; accent-color: #30d158; flex: none; }
.row input[type=range] { width: 100%; accent-color: #0a84ff; }
.diag-box { margin-top: 14px; color: var(--muted); font-size: 14px; }
.diag-box summary { padding: 6px 0; }
#diag {
  white-space: pre-wrap; word-break: break-word; margin: 6px 0 0;
  font: 12px/1.45 ui-monospace, "SF Mono", Menlo, monospace; color: #d1d1d6;
  -webkit-user-select: text; user-select: text;
}
.settings-actions { display: flex; gap: 10px; margin-top: 20px; }
.settings-actions button { font-size: 16px; }

@media (orientation: landscape) and (max-height: 500px) {
  #banner { left: auto; right: 16px; width: 320px; min-height: 72px; }
  #banner.red #bannerText, #banner.yellow #bannerText, #banner.green #bannerText { font-size: 30px; }
  #bannerLamp { width: 44px; height: 44px; }
  #lensBar { left: 16px; transform: none; bottom: calc(var(--safe-bottom) + 20px); align-items: flex-start; }
}
