:root {
  --hoya-blue: #27306e;
  --control-blue: #1683aa;
  --header-height: clamp(48px, 7.2vh, 70px);
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #111827;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button { font: inherit; }

button:focus-visible {
  outline: 3px solid rgba(255, 255, 255, .92);
  outline-offset: 2px;
}

.lens-app {
  position: fixed;
  inset: 0;
  min-width: 700px;
  min-height: 430px;
  overflow: hidden;
  background: #263038;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
}

.app-header,
.draw-header {
  position: absolute;
  z-index: 30;
  inset: 0 0 auto;
  height: var(--header-height);
  display: grid;
  grid-template-columns: 25% 50% 25%;
  align-items: center;
  padding: 0 clamp(20px, 3.1vw, 48px);
  color: #4f5065;
  background: rgba(242, 240, 247, .96);
  border-bottom: 1px solid rgba(49, 51, 88, .22);
  box-shadow: 0 1px 6px rgba(0, 0, 0, .16);
}

.hoya-wordmark {
  color: var(--hoya-blue);
  font-size: clamp(21px, 2.15vw, 38px);
  font-weight: 500;
  letter-spacing: .07em;
}

.app-title {
  justify-self: center;
  font-size: clamp(17px, 2vw, 34px);
  font-weight: 300;
  letter-spacing: .035em;
  white-space: nowrap;
}

.header-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: clamp(16px, 2.2vw, 36px);
}

.menu-button,
.home-button {
  width: clamp(34px, 3.8vw, 54px);
  height: clamp(34px, 3.8vw, 54px);
  padding: 8px;
  border: 0;
  background: transparent;
  color: #696b7d;
  cursor: pointer;
}

.menu-button {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 4px;
}

.menu-button span {
  width: 50%;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform .24s ease, opacity .18s ease;
}

.menu-button[aria-expanded="false"] span:first-child { transform: translateY(6px) rotate(45deg); }
.menu-button[aria-expanded="false"] span:nth-child(2) { opacity: 0; }
.menu-button[aria-expanded="false"] span:last-child { transform: translateY(-6px) rotate(-45deg); }

.home-button svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}

.display-stage {
  --outside-scene-blur: 14px;
  --outside-scene-overscan: 1.05;
  position: absolute;
  inset: var(--header-height) 0 0;
  overflow: hidden;
  isolation: isolate;
  background: #798087;
}

.camera-feed,
.camera-fallback,
.camera-tint {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.camera-feed {
  z-index: -5;
  object-fit: cover;
  background: transparent;
  -webkit-filter: blur(var(--outside-scene-blur));
  filter: blur(var(--outside-scene-blur));
  transform: scale(var(--outside-scene-overscan));
  transform-origin: center;
}

.camera-feed.is-live + .camera-fallback { opacity: 0; visibility: hidden; }

.camera-fallback {
  z-index: -6;
  overflow: hidden;
  opacity: 1;
  visibility: visible;
  background:
    linear-gradient(116deg, transparent 0 56%, rgba(28, 36, 43, .62) 56.4% 60%, transparent 60.4%),
    linear-gradient(180deg, #a8adb1 0 49%, #c5c6c4 49% 54%, #858b8d 54% 100%);
  -webkit-filter: blur(var(--outside-scene-blur)) saturate(.72);
  filter: blur(var(--outside-scene-blur)) saturate(.72);
  transform: scale(var(--outside-scene-overscan));
  transform-origin: center;
  transition: none;
}

.camera-fallback i { position: absolute; display: block; }
.fallback-wall { inset: 0 58% 25% 0; background: linear-gradient(90deg, #62696e, #aeb2b3); filter: blur(7px); }
.fallback-counter { left: 0; right: 0; top: 51%; height: 12%; background: linear-gradient(180deg, #c8d7d1, #628e87); transform: skewY(-2deg); filter: blur(2px); }
.fallback-floor { inset: 62% 0 0; background: repeating-linear-gradient(104deg, rgba(255,255,255,.16) 0 3px, transparent 3px 20vw), linear-gradient(#8e9596, #c3c1bd); }

.camera-tint {
  z-index: -3;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(30, 31, 42, .2), rgba(210, 216, 222, .04) 48%, rgba(30, 31, 42, .25));
}

.camera-control-panel {
  position: absolute;
  z-index: 12;
  top: clamp(9px, 1.6vh, 16px);
  left: 50%;
  display: grid;
  justify-items: center;
  gap: 5px;
  width: min(360px, 42vw);
  transform: translateX(-50%);
  pointer-events: none;
}

.camera-toggle {
  min-height: 40px;
  padding: 8px 18px;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 999px;
  color: #fff;
  background: rgba(19, 91, 126, .82);
  box-shadow: 0 2px 9px rgba(0,0,0,.22);
  font: 500 clamp(12px, 1.3vw, 16px)/1.1 "Segoe UI", sans-serif;
  letter-spacing: .015em;
  pointer-events: auto;
  touch-action: manipulation;
}

.camera-toggle:hover,
.camera-toggle:focus-visible { background: rgba(13, 112, 153, .92); }
.camera-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.camera-toggle:disabled { cursor: wait; opacity: .72; }
.camera-toggle[aria-pressed="true"] { background: rgba(44, 55, 65, .82); }

.camera-status {
  max-width: 100%;
  padding: 4px 9px;
  margin: 0;
  border-radius: 5px;
  color: rgba(255,255,255,.96);
  background: rgba(24, 31, 39, .68);
  font: 400 clamp(10px, 1vw, 13px)/1.25 "Segoe UI", sans-serif;
  text-align: center;
  text-wrap: balance;
}

.camera-status.is-error {
  color: #fff;
  background: rgba(111, 34, 39, .86);
}

.zone-selector {
  --zone-row-height: clamp(22px, 2.8vh, 31px);
  position: absolute;
  z-index: 9;
  top: clamp(12px, 2.8vh, 28px);
  left: clamp(20px, 3vw, 48px);
  display: flex;
  align-items: flex-start;
  gap: 4px;
}

.zone-controls {
  display: grid;
  width: clamp(54px, 5.8vw, 88px);
  background: rgba(36, 36, 49, .58);
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}

.zone-indicator {
  position: relative;
  width: clamp(17px, 1.7vw, 25px);
  height: calc(var(--zone-row-height) * 3);
  color: rgba(255,255,255,.66);
}

.zone-indicator svg {
  position: absolute;
  top: calc((var(--zone-row-height) - 18px) / 2);
  left: 0;
  width: 100%;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform .38s cubic-bezier(.22,.78,.25,1);
}

.lens-app[data-zone="mid"] .zone-indicator svg { transform: translateY(var(--zone-row-height)); }
.lens-app[data-zone="near"] .zone-indicator svg { transform: translateY(calc(var(--zone-row-height) * 2)); }
.lens-app[data-motion="active"] .zone-indicator { color: #66d6f1; filter: drop-shadow(0 0 3px rgba(40,176,211,.52)); }

.zone-button {
  height: var(--zone-row-height);
  min-height: var(--zone-row-height);
  padding: 1px 4px;
  border: 0;
  border-left: 3px solid transparent;
  color: rgba(255,255,255,.8);
  background: rgba(36, 36, 49, .16);
  font-size: clamp(9px, .78vw, 13px);
  letter-spacing: .08em;
  cursor: pointer;
}

.zone-button + .zone-button { border-top: 1px solid rgba(255,255,255,.18); }
.zone-button.is-active { border-left-color: #ca2d68; color: #fff; background: rgba(53, 52, 70, .75); }

.motion-panel {
  position: absolute;
  z-index: 11;
  top: clamp(92px, 14vh, 128px);
  left: clamp(20px, 3vw, 48px);
  display: grid;
  gap: 5px;
  width: min(280px, 27vw);
  pointer-events: none;
}

.motion-actions {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.motion-button {
  min-height: 34px;
  flex: 1 1 auto;
  padding: 6px 9px;
  border: 1px solid rgba(255,255,255,.44);
  border-radius: 5px;
  color: #fff;
  background: rgba(27, 79, 105, .8);
  box-shadow: 0 2px 7px rgba(0,0,0,.18);
  font: 500 clamp(9px, .82vw, 12px)/1.15 "Segoe UI", sans-serif;
  pointer-events: auto;
  touch-action: manipulation;
}

.motion-button.calibrate { background: rgba(50, 59, 71, .78); }
.motion-button:disabled { opacity: .45; cursor: default; }
.motion-button[aria-pressed="true"] { background: rgba(14, 112, 145, .9); }

.motion-status {
  max-width: 100%;
  padding: 4px 7px;
  margin: 0;
  border-radius: 4px;
  color: rgba(255,255,255,.94);
  background: rgba(24, 31, 39, .64);
  font: 400 clamp(9px, .76vw, 11px)/1.25 "Segoe UI", sans-serif;
  text-wrap: balance;
}

.motion-status.is-error { background: rgba(111, 34, 39, .86); }

.lens-display {
  position: absolute;
  z-index: 2;
  left: 10.8%;
  top: 2.5%;
  width: 76%;
  height: 87%;
  overflow: visible;
  pointer-events: none;
}

/* Plain canvas and SVG share these bounds and a 1000 x 650 logical space.
   Never put the canvas in foreignObject: WebKit may composite it unscaled. */
.lens-scene-layer { isolation: isolate; }
.lens-frame-layer {
  z-index: 3;
  filter: drop-shadow(0 3px 3px rgba(0,0,0,.22));
}

.lens-surface { fill: url(#lensSheen); }

.lens-glass-reflection {
  fill: none;
  stroke: url(#glassReflection);
  stroke-width: 11;
  stroke-linecap: round;
  opacity: .42;
  filter: url(#softGlassReflection);
  pointer-events: none;
}

.peripheral-mask-shape { transition: none; }

.lens-optical-scene,
.lens-canvas-host,
.lens-scene-canvas {
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
}

.lens-scene-canvas { display: block; }

.lens-edge-light,
.lens-edge-dark { fill: none; vector-effect: non-scaling-stroke; }
.lens-edge-light { stroke: rgba(255,255,255,.66); stroke-width: 2.2; transform: translate(-1px, -1px); }
.lens-edge-dark { stroke: rgba(15, 18, 23, .88); stroke-width: 3; filter: url(#softLensShadow); }

.corridor-guide {
  fill: none;
  stroke: rgba(255,255,255,.88);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.2));
  /* Geometry must match the canvas mask in the same frame. CSS path tweening
     moves only the visible guide, leaving the blur on the previous boundary. */
  transition: opacity .25s ease;
}

.lens-guides { transition: opacity .25s ease; }
.lens-guides.is-hidden { opacity: 0; }

.side-controls {
  position: absolute;
  z-index: 10;
  top: clamp(14px, 2.5vh, 26px);
  right: clamp(21px, 2.9vw, 48px);
  bottom: clamp(76px, 13vh, 126px);
  display: flex;
  width: clamp(70px, 7.2vw, 112px);
  flex-direction: column;
  align-items: center;
  gap: clamp(9px, 1.4vh, 16px);
  transition: transform .32s cubic-bezier(.22,.8,.25,1), opacity .25s ease;
}

.side-controls.is-collapsed {
  transform: translateX(calc(100% + 5vw));
  opacity: 0;
  pointer-events: none;
}

.value-control {
  width: 100%;
  padding: clamp(5px, .55vw, 9px);
  background: linear-gradient(180deg, rgba(15,120,164,.88), rgba(16,102,144,.84));
  box-shadow: 0 5px 12px rgba(7, 36, 54, .3);
}

.value-control h2 {
  margin: 0 0 4px;
  color: rgba(255,255,255,.93);
  font-size: clamp(10px, 1vw, 16px);
  font-weight: 400;
  line-height: 1;
  text-align: center;
}

.value-wheel {
  --wheel-drag-offset: 0px;
  position: relative;
  width: 100%;
  height: clamp(70px, 10.8vh, 110px);
  display: grid;
  grid-template-rows: 1fr 1.3fr 1fr;
  align-items: center;
  padding: 2px 0;
  overflow: hidden;
  border: 3px solid rgba(210,231,239,.38);
  background: linear-gradient(90deg, rgba(213,221,225,.9), rgba(247,245,241,.95), rgba(194,208,215,.9));
  color: #575968;
  box-shadow: inset 0 0 9px rgba(36,64,77,.2);
  cursor: ns-resize;
  touch-action: none;
  overscroll-behavior: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.value-wheel::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  top: 32%;
  bottom: 32%;
  border-block: 1px solid rgba(79, 101, 113, .28);
  pointer-events: none;
}

.wheel-value {
  line-height: 1;
  text-align: center;
  transform: translateY(var(--wheel-drag-offset));
  transition: transform .18s cubic-bezier(.22,.8,.25,1), opacity .16s ease;
  will-change: transform;
  pointer-events: none;
}
.wheel-value.previous,
.wheel-value.next { font-size: clamp(9px, .8vw, 13px); opacity: .52; }
.wheel-value.current {
  color: #293b4a;
  font-size: clamp(14px, 1.45vw, 23px);
  font-weight: 600;
  text-shadow: 0 1px 0 rgba(255,255,255,.75);
}
.value-wheel.is-dragging { cursor: grabbing; }
.value-wheel.is-dragging .wheel-value {
  transform: translateY(var(--wheel-drag-offset)) scale(.97);
  transition: none;
}
.value-wheel.is-snapping .wheel-value {
  transition-duration: .2s;
}

.round-control {
  flex: 0 0 auto;
  width: clamp(48px, 5.1vw, 76px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin-top: auto;
  padding: 10px;
  border: 0;
  border-radius: 50%;
  background: rgba(219, 222, 225, .78);
  color: #1180b0;
  box-shadow: 0 4px 12px rgba(0,0,0,.22);
  cursor: pointer;
  transition: transform .18s ease, background .2s ease;
}

.round-control + .round-control { margin-top: 0; }
.round-control:active { transform: scale(.94); }
.round-control.is-active { background: rgba(7, 116, 156, .82); color: rgba(215,244,251,.94); }
.round-control svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; }
.draw-control svg { stroke-width: 3; }

.drawing-canvas {
  position: absolute;
  z-index: 15;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
}

.drawing-canvas.is-enabled { pointer-events: auto; cursor: crosshair; }

.family-name {
  position: absolute;
  z-index: 9;
  left: clamp(22px, 3.3vw, 54px);
  bottom: clamp(64px, 9.1vh, 92px);
  min-width: clamp(175px, 22vw, 330px);
  padding: clamp(6px, .85vh, 10px) clamp(17px, 2vw, 32px);
  color: #eafaff;
  background: linear-gradient(90deg, rgba(19, 120, 173, .84), rgba(24, 144, 188, .72), rgba(24, 144, 188, .1));
  font-size: clamp(14px, 1.55vw, 25px);
  font-weight: 300;
  line-height: 1.1;
  transition: opacity .15s ease;
}

.family-navigation {
  position: absolute;
  z-index: 10;
  inset: auto 0 0;
  height: clamp(58px, 8.8vh, 88px);
  display: grid;
  grid-template-columns: minmax(105px, 15%) 1fr minmax(105px, 15%);
  align-items: end;
  padding: 0 clamp(20px, 3vw, 50px) clamp(8px, 1.15vh, 13px);
  background: linear-gradient(0deg, rgba(27,27,35,.83), rgba(31,32,39,.46) 72%, transparent);
}

.family-options {
  display: grid;
  grid-template-columns: repeat(8, minmax(44px, 1fr));
  align-items: end;
  gap: clamp(2px, .35vw, 6px);
}

.family-option {
  position: relative;
  height: clamp(34px, 5vh, 51px);
  overflow: hidden;
  padding: 4px 2px 8px;
  border: 0;
  border-bottom: clamp(3px, .45vh, 5px) solid color-mix(in srgb, var(--family-color), white 28%);
  color: rgba(255,255,255,.9);
  background: var(--family-color);
  font-size: clamp(7px, .65vw, 11px);
  font-weight: 650;
  letter-spacing: -.02em;
  box-shadow: inset 0 8px 10px rgba(255,255,255,.05), 0 2px 4px rgba(0,0,0,.25);
  opacity: .88;
  cursor: pointer;
  transition: height .2s ease, filter .2s ease, opacity .2s ease;
}

.family-option::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 5px;
  background: rgba(255,255,255,.2);
}

.family-option.is-active {
  height: clamp(41px, 6.2vh, 62px);
  opacity: 1;
  filter: saturate(1.12) brightness(1.09);
  outline: 1px solid rgba(255,255,255,.6);
  outline-offset: -2px;
}

.family-step {
  height: 48px;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0;
  border: 0;
  color: rgba(255,255,255,.76);
  background: transparent;
  font-size: clamp(15px, 1.6vw, 26px);
  font-weight: 300;
  cursor: pointer;
}

.family-step.next { justify-content: end; }
.family-step svg { width: clamp(25px, 2.5vw, 38px); height: 100%; fill: none; stroke: currentColor; stroke-width: 1.2; }

.draw-header {
  display: grid;
  grid-template-columns: minmax(130px, 25%) 1fr;
}

.app-header[hidden],
.draw-header[hidden] { display: none; }

.draw-tools {
  justify-self: end;
  height: 100%;
  display: flex;
  align-items: center;
  gap: clamp(4px, .7vw, 12px);
}

.pen-color,
.stroke-size,
.draw-command,
.done-drawing {
  width: clamp(34px, 3.6vw, 54px);
  height: clamp(34px, 3.6vw, 54px);
  display: grid;
  place-items: center;
  padding: 5px;
  border: 0;
  border-radius: 50%;
  color: #297bac;
  background: transparent;
  cursor: pointer;
}

.pen-color.is-active,
.stroke-size.is-active { background: rgba(22, 149, 188, .27); }

.pen-color i {
  width: 24%;
  height: 75%;
  border-radius: 7px;
  background: var(--pen);
  transform: rotate(43deg);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
}

.stroke-size i { display: block; border-radius: 50%; background: #2395bf; }
.stroke-size i.thin { width: 5px; height: 5px; }
.stroke-size i.medium { width: 12px; height: 12px; }
.stroke-size i.thick { width: 20px; height: 20px; }

.draw-command svg { width: 76%; height: 76%; fill: currentColor; }
.draw-command:disabled { opacity: .28; cursor: default; }
.tool-separator { width: 1px; height: 54%; margin: 0 2px; background: rgba(75,77,95,.2); }

.done-drawing {
  width: auto;
  min-width: clamp(52px, 5vw, 78px);
  border-radius: 3px;
  color: #55576b;
  font-size: clamp(12px, 1.1vw, 17px);
}

@media (max-height: 550px) {
  :root { --header-height: 45px; }
  .side-controls { gap: 6px; bottom: 61px; }
  .value-control { padding: 4px; }
  .value-wheel { height: 61px; }
  .round-control { width: 42px; padding: 8px; }
  .motion-panel { top: 78px; width: min(260px, 29vw); }
  .motion-button { min-height: 29px; padding: 4px 7px; }
  .family-name { bottom: 54px; }
  .family-navigation { height: 55px; padding-bottom: 5px; }
  .family-option { height: 31px; }
  .family-option.is-active { height: 38px; }
}

@media (orientation: portrait) {
  .lens-app {
    transform-origin: top left;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
