:root {
  --bg: #04070d;
  --ink: #f2f7ff;
  --muted: #8899ad;
  --muted-2: #5b6b7e;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.17);
  --glass: rgba(9, 15, 24, 0.55);
  --glass-heavy: rgba(8, 14, 23, 0.82);
  --accent: #ff6fae;
  --accent-rgb: 255, 111, 174;
  --accent-soft: rgba(255, 111, 174, 0.16);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", "Roboto Mono", "Cascadia Code", ui-monospace, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overflow: clip;
  background: var(--bg);
}

body {
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

#app {
  position: fixed;
  inset: 0;
  isolation: isolate;
  overflow: hidden;
  overflow: clip;
  touch-action: none;
}

#scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

body.is-dragging #scene {
  cursor: grabbing;
}

.ambient {
  position: absolute;
  z-index: 2;
  width: 58vw;
  height: 58vw;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(90px);
  opacity: 0.12;
  mix-blend-mode: screen;
}

.ambient-a {
  top: -28vw;
  right: -12vw;
  background: radial-gradient(circle, rgba(var(--accent-rgb), 0.9), transparent 68%);
  animation: drift-a 16s ease-in-out infinite alternate;
}

.ambient-b {
  bottom: -35vw;
  left: -18vw;
  background: radial-gradient(circle, rgba(72, 151, 255, 0.72), transparent 70%);
  animation: drift-b 21s ease-in-out infinite alternate;
}

.vignette {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 47%, transparent 28%, rgba(1, 3, 7, 0.2) 63%, rgba(1, 3, 7, 0.66) 100%),
    linear-gradient(to bottom, rgba(1, 3, 7, 0.34), transparent 18%, transparent 76%, rgba(1, 3, 7, 0.42));
}

.grain {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0.045;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.88' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.62'/%3E%3C/svg%3E");
  background-size: 160px 160px;
}

/* ---------- top bar ---------- */

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding:
    calc(24px + env(safe-area-inset-top))
    calc(28px + env(safe-area-inset-right))
    0
    calc(28px + env(safe-area-inset-left));
  pointer-events: none;
}

.topbar button {
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 150px;
}

.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  box-shadow: inset 0 0 18px rgba(255, 255, 255, 0.04);
}

.brand-mark::before {
  content: "";
  position: absolute;
  width: 46px;
  height: 17px;
  border: 1px solid rgba(var(--accent-rgb), 0.55);
  border-radius: 50%;
  transform: rotate(-28deg);
  box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.18);
}

.brand-mark i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent), 0 0 26px rgba(var(--accent-rgb), 0.65);
}

.brand-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}

.brand-copy strong {
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1;
  font-weight: 500;
  letter-spacing: 0.38em;
  padding-left: 1px;
}

.brand-copy small {
  color: var(--muted-2);
  font-family: var(--mono);
  font-size: 7px;
  line-height: 1;
  letter-spacing: 0.24em;
}

.status-pill {
  position: absolute;
  left: 50%;
  top: calc(30px + env(safe-area-inset-top));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 9px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(7, 12, 20, 0.38);
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
  color: #a8b7c9;
  font-size: 10px;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  transition: background 0.4s, box-shadow 0.4s;
}

.status-pill.is-live .status-dot {
  background: #65ffc4;
  box-shadow: 0 0 10px #65ffc4;
  animation: pulse-dot 1.7s ease-in-out infinite;
}

.status-pill.is-error .status-dot {
  background: #ff8c78;
  box-shadow: 0 0 10px #ff8c78;
}

.status-model {
  color: #e8f0fa;
  font-weight: 500;
  letter-spacing: 0.12em;
}

.status-sep {
  width: 1px;
  height: 10px;
  background: rgba(255, 255, 255, 0.14);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cam-button,
.icon-button {
  border: 1px solid var(--line);
  background: rgba(8, 14, 23, 0.46);
  backdrop-filter: blur(20px) saturate(130%);
  -webkit-backdrop-filter: blur(20px) saturate(130%);
  color: #d6e2f0;
  transition: background 0.25s, border-color 0.25s, color 0.25s, transform 0.25s var(--ease);
}

.cam-button:hover,
.icon-button:hover {
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(15, 24, 38, 0.7);
  color: #fff;
}

.cam-button:active,
.icon-button:active {
  transform: scale(0.96);
}

.cam-button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  height: 42px;
  padding: 0 15px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.1em;
  white-space: nowrap;
}

.cam-button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.45;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cam-signal {
  position: absolute;
  top: 10px;
  right: 11px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  transition: background 0.3s, box-shadow 0.3s;
}

.cam-button.is-active {
  color: #fff;
  border-color: rgba(var(--accent-rgb), 0.42);
  background: rgba(var(--accent-rgb), 0.12);
}

.cam-button.is-active .cam-signal {
  background: #65ffc4;
  box-shadow: 0 0 8px #65ffc4;
  animation: pulse-dot 1.5s ease-in-out infinite;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
}

.icon-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#fullscreenBtn .icon-exit {
  display: none;
}

#fullscreenBtn.is-fullscreen .icon-enter {
  display: none;
}

#fullscreenBtn.is-fullscreen .icon-exit {
  display: block;
}

/* ---------- model rail ---------- */

.model-rail {
  position: absolute;
  z-index: 16;
  left: calc(22px + env(safe-area-inset-left));
  top: 50%;
  transform: translateY(-46%);
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 178px;
  padding: 5px;
}

.model-item {
  position: relative;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 20px;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 49px;
  padding: 0 8px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: #718196;
  text-align: left;
  cursor: pointer;
  transition: color 0.3s, background 0.35s var(--ease), transform 0.35s var(--ease);
}

.model-item:hover {
  color: #d2deec;
  background: rgba(255, 255, 255, 0.035);
  transform: translateX(2px);
}

.model-item.is-active {
  color: #fff;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.095), rgba(255, 255, 255, 0.016));
}

.model-item::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 50%;
  width: 2px;
  height: 0;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.9);
  transform: translateY(-50%);
  transition: height 0.35s var(--ease);
}

.model-item.is-active::before {
  height: 23px;
}

.model-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 50%;
  transition: border-color 0.3s, background 0.3s, box-shadow 0.3s;
}

.model-icon svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.15;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.model-item.is-active .model-icon {
  color: var(--accent);
  border-color: rgba(var(--accent-rgb), 0.4);
  background: rgba(var(--accent-rgb), 0.09);
  box-shadow: 0 0 18px rgba(var(--accent-rgb), 0.12), inset 0 0 10px rgba(var(--accent-rgb), 0.06);
}

.model-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.model-copy strong {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.12em;
  white-space: nowrap;
}

.model-copy small {
  color: var(--muted-2);
  font-family: var(--mono);
  font-size: 7px;
  letter-spacing: 0.16em;
  white-space: nowrap;
}

.model-item.is-active .model-copy small {
  color: rgba(var(--accent-rgb), 0.7);
}

.model-index {
  justify-self: end;
  color: rgba(255, 255, 255, 0.22);
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.08em;
}

/* ---------- sensor panel ---------- */

.sensor-panel {
  position: absolute;
  z-index: 12;
  left: calc(26px + env(safe-area-inset-left));
  bottom: calc(28px + env(safe-area-inset-bottom));
  width: 264px;
  padding: 14px 15px 13px;
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 17px;
  background: linear-gradient(145deg, rgba(12, 20, 32, 0.48), rgba(5, 9, 15, 0.34));
  backdrop-filter: blur(18px) saturate(120%);
  -webkit-backdrop-filter: blur(18px) saturate(120%);
  opacity: 0.88;
}

.sensor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
}

.eyebrow {
  color: var(--muted-2);
  font-family: var(--mono);
  font-size: 7.5px;
  font-weight: 500;
  letter-spacing: 0.2em;
}

.sensor-mode {
  color: rgba(var(--accent-rgb), 0.8);
  font-family: var(--mono);
  font-size: 7.5px;
  letter-spacing: 0.12em;
}

.sensor-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 32px;
  align-items: center;
  gap: 9px;
  height: 22px;
}

.sensor-name {
  color: #77879b;
  font-size: 9px;
  letter-spacing: 0.14em;
}

.sensor-row b {
  color: #aebccd;
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 400;
  text-align: right;
}

.sensor-bar {
  position: relative;
  height: 2px;
  overflow: hidden;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
}

.sensor-bar i {
  position: absolute;
  inset: 0;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, rgba(var(--accent-rgb), 0.5), var(--accent));
  box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.35);
  transform: scaleX(0.2);
  transform-origin: left center;
  transition: transform 0.18s linear;
}

/* ---------- hint bar ---------- */

.hint-bar {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: calc(30px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 15px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  background: rgba(7, 12, 20, 0.34);
  backdrop-filter: blur(16px) saturate(120%);
  -webkit-backdrop-filter: blur(16px) saturate(120%);
  color: #75869a;
  font-size: 9px;
  letter-spacing: 0.09em;
  white-space: nowrap;
  transition: opacity 0.6s;
}

.hint-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.hint-item svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.8;
}

.hint-sep {
  width: 1px;
  height: 11px;
  background: rgba(255, 255, 255, 0.09);
}

.hint-gesture {
  color: rgba(235, 244, 255, 0.68);
}

.mini-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

/* ---------- control deck ---------- */

.control-deck {
  position: absolute;
  z-index: 18;
  right: calc(24px + env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 298px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.095);
  border-radius: 22px;
  background:
    radial-gradient(120% 120% at 100% 0%, rgba(var(--accent-rgb), 0.075), transparent 45%),
    linear-gradient(155deg, rgba(15, 24, 38, 0.67), rgba(5, 9, 15, 0.78));
  backdrop-filter: blur(26px) saturate(135%);
  -webkit-backdrop-filter: blur(26px) saturate(135%);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition: opacity 0.35s var(--ease), transform 0.35s var(--ease);
}

.deck-head {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 12px;
}

.color-wheel {
  position: relative;
  width: 54px;
  height: 54px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 50%;
  background:
    conic-gradient(from 0deg,
      #ff4560, #ffb545, #ecff63, #5dff9a, #5ef0ff, #5c8bff,
      #b35cff, #ff5ce1, #ff4560);
  box-shadow: 0 0 26px rgba(var(--accent-rgb), 0.13), inset 0 0 18px rgba(0, 0, 0, 0.2);
  cursor: crosshair;
  touch-action: none;
}

.color-wheel::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(255, 255, 255, 0.17), transparent 45%), #0a111b;
  opacity: 0.3;
}

.color-wheel::after {
  content: "";
  position: absolute;
  inset: 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: #0a111b;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.55);
}

.wheel-cursor {
  position: absolute;
  z-index: 2;
  left: calc(50% + var(--wx, 0px));
  top: calc(50% + var(--wy, -21px));
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  pointer-events: none;
}

.deck-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.deck-title .eyebrow {
  font-size: 6.8px;
}

.deck-title strong {
  overflow: hidden;
  color: #f3f7fd;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck-title small {
  color: var(--muted-2);
  font-family: var(--mono);
  font-size: 7.5px;
  letter-spacing: 0.09em;
}

.deck-title small b {
  color: rgba(var(--accent-rgb), 0.9);
  font-weight: 500;
}

.reset-button {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: #5f7084;
  cursor: pointer;
  transition: color 0.25s, border-color 0.25s, transform 0.3s;
}

.reset-button:hover {
  color: #fff;
  border-color: var(--line);
  transform: rotate(-35deg);
}

.reset-button svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.deck-body {
  display: block;
}

.swatches {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 16px;
}

.swatch {
  position: relative;
  width: 23px;
  height: 23px;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  background: var(--swatch);
  cursor: pointer;
  transition: transform 0.25s var(--ease), box-shadow 0.25s;
}

.swatch::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid transparent;
  border-radius: 50%;
  transition: border-color 0.25s;
}

.swatch:hover {
  transform: translateY(-2px) scale(1.05);
}

.swatch.is-active {
  box-shadow: 0 0 0 2px #0b111a, 0 0 0 3px rgba(var(--accent-rgb), 0.7), 0 0 16px rgba(var(--accent-rgb), 0.25);
}

.swatch.is-active::after {
  border-color: rgba(255, 255, 255, 0.8);
}

.swatch-label {
  overflow: hidden;
  margin-left: 2px;
  color: var(--muted-2);
  font-family: var(--mono);
  font-size: 6.5px;
  letter-spacing: 0.12em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck-rule {
  height: 1px;
  margin: 15px 0 13px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.025));
}

.range-line {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 7px 12px;
  color: #94a4b7;
  font-size: 9px;
  letter-spacing: 0.1em;
}

.range-value {
  color: #becad9;
  font-family: var(--mono);
  font-size: 8px;
}

.range-line input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  height: 18px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}

.range-line input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) 0%, var(--accent) var(--range, 35%), rgba(255, 255, 255, 0.09) var(--range, 35%), rgba(255, 255, 255, 0.09) 100%);
}

.range-line input[type="range"]::-moz-range-track {
  height: 2px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.09);
}

.range-line input[type="range"]::-moz-range-progress {
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.range-line input[type="range"]::-webkit-slider-thumb {
  width: 10px;
  height: 10px;
  margin-top: -4px;
  border: 2px solid #fff;
  border-radius: 50%;
  appearance: none;
  -webkit-appearance: none;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(var(--accent-rgb), 0.55);
}

.range-line input[type="range"]::-moz-range-thumb {
  width: 7px;
  height: 7px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(var(--accent-rgb), 0.55);
}

.toggle-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  color: #94a4b7;
  font-size: 9px;
  letter-spacing: 0.1em;
}

.switch {
  position: relative;
  display: block;
  width: 34px;
  height: 19px;
  cursor: pointer;
}

.switch input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
}

.switch-track {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  transition: background 0.25s, border-color 0.25s;
}

.switch-track i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #78879a;
  transition: transform 0.25s var(--ease), background 0.25s, box-shadow 0.25s;
}

.switch input:checked + .switch-track {
  border-color: rgba(var(--accent-rgb), 0.36);
  background: rgba(var(--accent-rgb), 0.14);
}

.switch input:checked + .switch-track i {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.55);
  transform: translateX(15px);
}

.deck-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 11px;
  border-top: 1px solid rgba(255, 255, 255, 0.055);
  color: #526276;
  font-family: var(--mono);
  font-size: 6.5px;
  letter-spacing: 0.1em;
}

.deck-foot b {
  color: rgba(var(--accent-rgb), 0.88);
  font-weight: 400;
}

.deck-close {
  display: none;
}

.palette-fab {
  display: none;
}

/* ---------- camera preview ---------- */

.camera-preview {
  position: absolute;
  z-index: 13;
  top: calc(88px + env(safe-area-inset-top));
  right: calc(24px + env(safe-area-inset-right));
  width: 218px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 18px;
  background: #05090f;
  box-shadow: 0 22px 58px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  opacity: 0;
  transform: translateY(-8px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.45s var(--ease), transform 0.45s var(--ease);
}

.camera-preview.is-active {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.camera-preview video,
.camera-preview canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.camera-preview canvas {
  z-index: 2;
}

.preview-shade {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(2, 5, 9, 0.56), transparent 25%, transparent 68%, rgba(2, 5, 9, 0.72)),
    radial-gradient(circle at 50% 50%, transparent 35%, rgba(2, 5, 9, 0.2));
}

.preview-top,
.preview-bottom {
  position: absolute;
  z-index: 5;
  left: 11px;
  right: 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: rgba(227, 241, 255, 0.62);
  font-family: var(--mono);
  font-size: 6.5px;
  letter-spacing: 0.1em;
}

.preview-top {
  top: 9px;
}

.preview-bottom {
  bottom: 9px;
}

.preview-bottom #gestureText {
  color: rgba(245, 250, 255, 0.88);
  font-family: var(--font);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.rec {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.rec i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #65ffc4;
  box-shadow: 0 0 8px #65ffc4;
  animation: pulse-dot 1.4s ease-in-out infinite;
}

.preview-scan {
  position: absolute;
  z-index: 4;
  left: 0;
  right: 0;
  top: 0;
  height: 28%;
  opacity: 0;
  background: linear-gradient(to bottom, transparent, rgba(var(--accent-rgb), 0.08), transparent);
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.2);
}

.camera-preview.is-searching .preview-scan {
  opacity: 1;
  animation: scan 2.4s linear infinite;
}

.corner {
  position: absolute;
  z-index: 5;
  width: 12px;
  height: 12px;
  border-color: rgba(var(--accent-rgb), 0.55);
  border-style: solid;
  pointer-events: none;
}

.corner.tl {
  top: 28px;
  left: 10px;
  border-width: 1px 0 0 1px;
}

.corner.tr {
  top: 28px;
  right: 10px;
  border-width: 1px 1px 0 0;
}

.corner.bl {
  bottom: 26px;
  left: 10px;
  border-width: 0 0 1px 1px;
}

.corner.br {
  bottom: 26px;
  right: 10px;
  border-width: 0 1px 1px 0;
}

/* ---------- toast / modal / loading ---------- */

.debug-readout {
  position: fixed;
  z-index: 999;
  top: 0;
  left: -12000px;
  width: 760px;
  max-height: 100vh;
  overflow: hidden;
  white-space: pre-wrap;
  color: #9effc8;
  background: #000;
  font: 10px/1.4 var(--mono);
  pointer-events: none;
}

body.debug-mode .debug-readout {
  left: 8px;
  padding: 8px;
  border: 1px solid #1f6b4a;
  opacity: 0.92;
}

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translate(-50%, 10px);
  max-width: min(420px, calc(100vw - 40px));
  padding: 11px 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(10, 17, 27, 0.9);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  color: #dbe6f4;
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.05em;
  text-align: center;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.35s var(--ease);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.35s, visibility 0.35s;
}

.modal.is-open {
  visibility: visible;
  opacity: 1;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 5, 10, 0.62);
  backdrop-filter: blur(16px) saturate(80%);
  -webkit-backdrop-filter: blur(16px) saturate(80%);
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: min(88vh, 760px);
  overflow: auto;
  padding: 32px 34px 28px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 26px;
  background:
    radial-gradient(100% 100% at 100% 0%, rgba(var(--accent-rgb), 0.09), transparent 45%),
    linear-gradient(155deg, rgba(16, 25, 39, 0.97), rgba(5, 9, 15, 0.98));
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transform: translateY(12px) scale(0.985);
  transition: transform 0.45s var(--ease);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.modal.is-open .modal-card {
  transform: translateY(0) scale(1);
}

.modal-card::-webkit-scrollbar {
  width: 4px;
}

.modal-card::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.16);
}

.modal-close {
  position: absolute;
  top: 18px;
  right: 18px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.03);
  color: #8596a9;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, transform 0.25s;
}

.modal-close:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.25);
  transform: rotate(90deg);
}

.modal-close svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
}

.modal-card h2 {
  margin: 16px 0 10px;
  color: #f2f7ff;
  font-size: clamp(26px, 3.2vw, 34px);
  font-weight: 400;
  line-height: 1.35;
  letter-spacing: 0.04em;
}

.modal-lead {
  max-width: 430px;
  margin: 0;
  color: #8999ac;
  font-size: 11.5px;
  line-height: 1.85;
  letter-spacing: 0.03em;
}

.gesture-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin-top: 24px;
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 18px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.055);
}

.gesture-list article {
  display: flex;
  gap: 11px;
  min-height: 102px;
  padding: 15px 14px;
  background: rgba(7, 12, 20, 0.72);
}

.gesture-glyph {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(var(--accent-rgb), 0.26);
  border-radius: 10px;
  background: rgba(var(--accent-rgb), 0.055);
  color: var(--accent);
}

.gesture-glyph svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.15;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.gesture-list strong {
  display: block;
  margin: 1px 0 5px;
  color: #dce7f4;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1em;
}

.gesture-list p {
  margin: 0;
  color: #6f8094;
  font-size: 9.5px;
  line-height: 1.65;
  letter-spacing: 0.02em;
}

.modal-note {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin-top: 17px;
  padding: 11px 13px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.025);
  color: #66778c;
  font-size: 9px;
  line-height: 1.65;
}

.note-dot {
  flex: 0 0 auto;
  width: 5px;
  height: 5px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 22px;
}

.button-primary,
.button-secondary {
  height: 40px;
  padding: 0 17px;
  border-radius: 999px;
  font-size: 10.5px;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: transform 0.2s var(--ease), background 0.25s, border-color 0.25s;
}

.button-primary {
  border: 1px solid rgba(var(--accent-rgb), 0.55);
  background: var(--accent);
  color: #0a0d12;
  font-weight: 600;
  box-shadow: 0 8px 26px rgba(var(--accent-rgb), 0.22);
}

.button-primary:hover {
  transform: translateY(-1px);
  background: #fff;
}

.button-secondary {
  border: 1px solid rgba(255, 255, 255, 0.13);
  background: rgba(255, 255, 255, 0.035);
  color: #b8c5d5;
}

.button-secondary:hover {
  border-color: rgba(255, 255, 255, 0.26);
  background: rgba(255, 255, 255, 0.07);
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 45%, rgba(var(--accent-rgb), 0.09), transparent 32%),
    #04070d;
  pointer-events: none;
  transition: opacity 0.9s var(--ease), visibility 0.9s;
}

.loading.is-done {
  visibility: hidden;
  opacity: 0;
}

.loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.loader-orbit {
  position: relative;
  width: 76px;
  height: 76px;
  margin-bottom: 24px;
}

.loader-orbit i {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 50%;
}

.loader-orbit i:nth-child(1) {
  animation: orbit 3.2s linear infinite;
  border-top-color: var(--accent);
  box-shadow: 0 -2px 12px rgba(var(--accent-rgb), 0.2);
}

.loader-orbit i:nth-child(2) {
  inset: 12px;
  animation: orbit 2.3s linear infinite reverse;
  border-right-color: rgba(var(--accent-rgb), 0.55);
}

.loader-orbit i:nth-child(3) {
  inset: 30px;
  background: var(--accent);
  border: 0;
  box-shadow: 0 0 20px var(--accent);
  animation: breathe 1.7s ease-in-out infinite;
}

.loading-brand {
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: 0.48em;
  padding-left: 0.48em;
}

.loading p {
  margin: 10px 0 17px;
  color: #607185;
  font-size: 9.5px;
  letter-spacing: 0.16em;
}

.loader-line {
  width: 158px;
  height: 1px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.loader-line i {
  display: block;
  width: 45%;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: loading-line 1.3s ease-in-out infinite;
}

/* ---------- animations ---------- */

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.72); }
}

@keyframes drift-a {
  from { transform: translate3d(-3%, -2%, 0) scale(1); }
  to { transform: translate3d(4%, 5%, 0) scale(1.08); }
}

@keyframes drift-b {
  from { transform: translate3d(2%, 3%, 0) scale(1.04); }
  to { transform: translate3d(-4%, -3%, 0) scale(0.96); }
}

@keyframes scan {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(360%); }
}

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

@keyframes breathe {
  0%, 100% { transform: scale(0.82); opacity: 0.7; }
  50% { transform: scale(1.14); opacity: 1; }
}

@keyframes loading-line {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(330%); }
}

@media (max-width: 1180px) {
  .hint-bar {
    display: none;
  }
}

@media (max-width: 820px) {
  .topbar {
    padding:
      calc(17px + env(safe-area-inset-top))
      calc(14px + env(safe-area-inset-right))
      0
      calc(16px + env(safe-area-inset-left));
    align-items: flex-start;
  }

  .brand {
    gap: 9px;
    min-width: 0;
  }

  .brand-mark {
    width: 31px;
    height: 31px;
  }

  .brand-mark::before {
    width: 40px;
    height: 15px;
  }

  .brand-copy strong {
    font-size: 12px;
    letter-spacing: 0.32em;
  }

  .brand-copy small {
    font-size: 6px;
    letter-spacing: 0.17em;
  }

  .status-pill {
    top: calc(65px + env(safe-area-inset-top));
    left: calc(17px + env(safe-area-inset-left));
    transform: none;
    height: 27px;
    padding: 0 10px;
    gap: 7px;
    font-size: 8.5px;
    background: rgba(7, 12, 20, 0.3);
  }

  .status-sep {
    height: 8px;
  }

  .top-actions {
    gap: 6px;
  }

  .cam-button {
    height: 38px;
    padding: 0 11px;
    gap: 6px;
    font-size: 9.5px;
  }

  .cam-button svg {
    width: 14px;
    height: 14px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .icon-button svg {
    width: 15px;
    height: 15px;
  }

  .cam-signal {
    top: 8px;
    right: 8px;
  }

  .model-rail {
    top: auto;
    left: calc(12px + env(safe-area-inset-left));
    right: calc(12px + env(safe-area-inset-right));
    bottom: calc(12px + env(safe-area-inset-bottom));
    transform: none;
    flex-direction: row;
    gap: 3px;
    width: auto;
    padding: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    border: 1px solid rgba(255, 255, 255, 0.095);
    border-radius: 18px;
    background: rgba(7, 12, 20, 0.62);
    backdrop-filter: blur(24px) saturate(130%);
    -webkit-backdrop-filter: blur(24px) saturate(130%);
    box-shadow: 0 16px 42px rgba(0, 0, 0, 0.32);
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .model-rail::-webkit-scrollbar {
    display: none;
  }

  .model-item {
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
    width: auto;
    height: 40px;
    padding: 0 9px;
    border-radius: 12px;
  }

  .model-item:hover {
    transform: none;
  }

  .model-item::before {
    display: none;
  }

  .model-icon {
    width: 24px;
    height: 24px;
    border: 0;
    background: transparent !important;
    box-shadow: none !important;
  }

  .model-icon svg {
    width: 15px;
    height: 15px;
  }

  .model-copy strong {
    font-size: 10px;
    letter-spacing: 0.08em;
  }

  .model-copy small,
  .model-index {
    display: none;
  }

  .model-item.is-active {
    background: rgba(var(--accent-rgb), 0.13);
  }

  .model-item.is-active .model-icon {
    color: var(--accent);
  }

  .sensor-panel {
    display: none;
  }

  .control-deck {
    right: calc(12px + env(safe-area-inset-right));
    bottom: calc(82px + env(safe-area-inset-bottom));
    width: min(298px, calc(100vw - 24px));
    max-height: calc(100vh - 180px);
    overflow: auto;
    opacity: 0;
    transform: translateY(18px) scale(0.97);
    pointer-events: none;
    transform-origin: bottom right;
  }

  .control-deck.is-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }

  .deck-close {
    position: absolute;
    top: 10px;
    right: 10px;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.025);
    color: #6d7e91;
  }

  .deck-close svg {
    width: 12px;
    height: 12px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.4;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .deck-head {
    padding-right: 23px;
  }

  .palette-fab {
    position: absolute;
    z-index: 19;
    right: calc(14px + env(safe-area-inset-right));
    bottom: calc(82px + env(safe-area-inset-bottom));
    display: flex;
    align-items: center;
    gap: 7px;
    height: 46px;
    padding: 0 14px 0 8px;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 999px;
    background: rgba(8, 14, 23, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: #dce7f4;
    font-size: 10px;
    letter-spacing: 0.1em;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.3);
    transition: opacity 0.25s, transform 0.25s var(--ease);
  }

  .palette-fab:active {
    transform: scale(0.95);
  }

  .control-deck.is-open ~ .palette-fab {
    opacity: 0;
    pointer-events: none;
  }

  .fab-orb {
    width: 30px;
    height: 30px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 50%;
    background: conic-gradient(from 45deg, #ff4560, #ffb545, #5dff9a, #5ef0ff, #b35cff, #ff4560);
    box-shadow: 0 0 13px rgba(var(--accent-rgb), 0.28);
  }

  .camera-preview {
    top: calc(106px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    width: 132px;
    border-radius: 14px;
  }

  .preview-top,
  .preview-bottom {
    left: 8px;
    right: 8px;
    font-size: 5.5px;
  }

  .preview-top {
    top: 7px;
  }

  .preview-bottom {
    bottom: 7px;
  }

  .preview-bottom #gestureText {
    font-size: 8px;
  }

  .corner {
    width: 9px;
    height: 9px;
  }

  .corner.tl,
  .corner.tr {
    top: 23px;
  }

  .corner.bl,
  .corner.br {
    bottom: 21px;
  }

  .corner.tl,
  .corner.bl {
    left: 8px;
  }

  .corner.tr,
  .corner.br {
    right: 8px;
  }

  .toast {
    bottom: calc(150px + env(safe-area-inset-bottom));
    font-size: 10px;
  }

  .modal {
    padding: 12px;
  }

  .modal-card {
    padding: 26px 20px 20px;
    border-radius: 22px;
    max-height: 88vh;
  }

  .modal-card h2 {
    font-size: 25px;
    padding-right: 20px;
  }

  .modal-lead {
    font-size: 10.5px;
  }

  .gesture-list {
    grid-template-columns: 1fr;
    margin-top: 20px;
  }

  .gesture-list article {
    min-height: 0;
    padding: 13px;
  }

  .modal-note {
    font-size: 8.5px;
  }

  .modal-actions {
    justify-content: stretch;
  }

  .modal-actions button {
    flex: 1;
    height: 42px;
    padding: 0 10px;
    font-size: 9.5px;
  }

  .loading p {
    font-size: 8.5px;
  }
}

@media (max-width: 380px) {
  .brand-copy small {
    display: none;
  }

  .cam-button span {
    display: none;
  }

  .cam-button {
    width: 38px;
    padding: 0;
    justify-content: center;
  }

  .status-pill {
    max-width: calc(100vw - 84px);
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
