:root {
  color-scheme: light;
  --bg: #f4efe6;
  --ink: #26231f;
  --muted: #6f6a62;
  --line: #d6cbbd;
  --panel: #fffaf1;
  --accent: #0f8f8d;
  --accent-strong: #0a6f6e;
  --gold: #f2aa3b;
  --coral: #f05f5a;
  --lens-x: 50%;
  --lens-y: 50%;
  --lens-r: 128px;
  --lens-clip: polygon(50% 36%, 62% 40%, 66% 50%, 62% 60%, 50% 64%, 38% 60%, 34% 50%, 38% 40%);
  --glow-clip: polygon(50% 28%, 69% 34%, 74% 50%, 69% 66%, 50% 72%, 31% 66%, 26% 50%, 31% 34%);
  --ink-blur: 28px;
  --ink-glow: 54px;
  --compare-x: 50%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 0%, rgba(66, 183, 197, 0.22), transparent 36%),
    radial-gradient(circle at 82% 10%, rgba(240, 95, 90, 0.16), transparent 30%),
    linear-gradient(300deg, rgba(242, 170, 59, 0.2), transparent 42%),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
a {
  font: inherit;
}

.app-shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-logo {
  width: clamp(54px, 6vw, 78px);
  height: clamp(54px, 6vw, 78px);
  flex: 0 0 auto;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(10, 111, 110, 0.18));
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 3vw, 44px);
  line-height: 1;
  letter-spacing: 0;
}

.top-tools,
.top-actions,
.action-row,
.asset-grid,
.toggle-grid {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-tools {
  justify-content: flex-end;
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.follow-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(15, 143, 141, 0.22);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.84);
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
}

.follow-link:hover {
  border-color: rgba(15, 143, 141, 0.5);
  background: rgba(255, 255, 255, 0.9);
}

.help-button {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(38, 35, 31, 0.14);
  border-radius: 999px;
  background: rgba(255, 250, 241, 0.9);
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 20px;
  font-weight: 950;
  line-height: 1;
}

.help-button:hover {
  border-color: rgba(15, 143, 141, 0.46);
  background: #fff;
}

.lang-button {
  min-width: 92px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(38, 35, 31, 0.14);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(31, 28, 23, 0.44);
}

.help-overlay[hidden] {
  display: none;
}

.help-dialog {
  position: relative;
  width: min(520px, 100%);
  padding: 24px 24px 22px;
  border: 1px solid rgba(38, 35, 31, 0.14);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.97);
  box-shadow: 0 28px 70px rgba(31, 28, 23, 0.28);
}

.help-dialog h2 {
  margin: 0 42px 14px 0;
  font-size: 24px;
  line-height: 1.15;
}

.help-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(38, 35, 31, 0.14);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 22px;
  font-weight: 850;
  line-height: 1;
}

.help-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 22px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 650;
  line-height: 1.55;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.82);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.button:hover {
  border-color: rgba(15, 143, 141, 0.45);
  transform: translateY(-1px);
}

.button.primary {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  margin-top: 18px;
}

.feature-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 4px;
  margin-top: 12px;
  padding: 4px;
  border: 1px solid rgba(38, 35, 31, 0.14);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.72);
}

.feature-option {
  min-height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 900;
}

.feature-option.is-active {
  background: var(--ink);
  color: #fff;
}

.stage-frame {
  min-width: 0;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 320px;
  overflow: hidden;
  border: 1px solid rgba(38, 35, 31, 0.16);
  border-radius: 8px;
  background: #faf7ef;
  box-shadow: 0 20px 48px rgba(38, 35, 31, 0.16);
  cursor: crosshair;
  isolation: isolate;
}

.reveal-glow-video,
.reveal-video,
.lower-image-layer,
.top-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reveal-glow-video {
  z-index: 3;
  background: #10272d;
  clip-path: var(--glow-clip);
  filter: blur(var(--ink-blur)) saturate(1.34) brightness(1.16);
  opacity: 0.34;
  pointer-events: none;
  transform: scale(1.035);
  transform-origin: var(--lens-x) var(--lens-y);
}

.reveal-video,
.lower-image-layer {
  z-index: 4;
  background: #10272d;
  clip-path: var(--lens-clip);
  filter: saturate(1.24) contrast(1.09) brightness(1.06);
  transform: scale(1.075);
  transform-origin: var(--lens-x) var(--lens-y);
}

.top-layer {
  z-index: 2;
  pointer-events: none;
}

.top-image-layer {
  mix-blend-mode: multiply;
}

.top-video-layer {
  background: #111;
}

.is-hidden {
  display: none;
}

.lens-glass,
.lens-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transform: none;
}

.lens-glass {
  z-index: 5;
  background:
    radial-gradient(circle at calc(var(--lens-x) - 18%) calc(var(--lens-y) - 18%), rgba(255, 255, 255, 0.56), transparent 0 9%, transparent 18%),
    radial-gradient(circle at var(--lens-x) var(--lens-y), rgba(255, 255, 255, 0.05), transparent 54%, rgba(9, 68, 82, 0.18) 78%, rgba(255, 255, 255, 0.18) 100%);
  box-shadow:
    inset -16px -18px 28px rgba(4, 47, 57, 0.16),
    inset 14px 12px 24px rgba(255, 255, 255, 0.24);
  clip-path: var(--lens-clip);
  mix-blend-mode: screen;
}

.lens-ring {
  z-index: 6;
  background:
    radial-gradient(circle at var(--lens-x) var(--lens-y), transparent calc(var(--lens-r) * 0.72), rgba(255, 247, 225, 0.72) calc(var(--lens-r) * 0.96), rgba(17, 159, 166, 0.2) calc(var(--lens-r) + var(--ink-glow)), transparent calc(var(--lens-r) + var(--ink-glow) + 42px));
  clip-path: var(--glow-clip);
  filter: blur(calc(var(--ink-blur) * 0.32));
  mix-blend-mode: screen;
}

.lost-state {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 50%;
  max-width: min(70%, 360px);
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.86);
  color: var(--muted);
  font-weight: 700;
  text-align: center;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 160ms ease;
  pointer-events: none;
}

.stage.is-lost .lost-state {
  opacity: 1;
}

.stage.is-idle .lost-state {
  opacity: 0;
}

.stage.is-idle .lens-ring,
.stage.is-idle .lens-glass,
.stage.is-idle .reveal-glow-video,
.stage.is-idle .reveal-video,
.stage.is-lost .lens-ring,
.stage.is-lost .lens-glass,
.stage.is-lost .reveal-glow-video,
.stage.is-lost .reveal-video {
  opacity: 0;
}

.compare-ui {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: none;
  pointer-events: none;
}

.compare-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--compare-x);
  width: 3px;
  background: rgba(255, 250, 241, 0.95);
  box-shadow:
    0 0 0 1px rgba(38, 35, 31, 0.22),
    0 0 28px rgba(15, 143, 141, 0.26);
  transform: translateX(-50%);
}

.compare-divider::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(38, 35, 31, 0.18);
  border-radius: 999px;
  background: rgba(255, 250, 241, 0.96);
  box-shadow: 0 10px 24px rgba(31, 28, 23, 0.22);
  color: var(--accent-strong);
  content: "↔";
  display: grid;
  font-size: 18px;
  font-weight: 950;
  line-height: 1;
  place-items: center;
  transform: translate(-50%, -50%);
}

.compare-slider {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
  pointer-events: auto;
}

.stage.is-compare {
  cursor: ew-resize;
}

.stage.is-compare .compare-ui {
  display: block;
}

.stage.is-compare .lost-state,
.stage.is-compare .lens-ring,
.stage.is-compare .lens-glass,
.stage.is-compare .reveal-glow-video {
  opacity: 0;
}

.stage.is-compare .reveal-video,
.stage.is-compare .lower-image-layer {
  z-index: 3;
  clip-path: none;
  filter: none;
  opacity: 1;
  transform: none;
}

.stage.is-compare .top-layer {
  z-index: 5;
  clip-path: inset(0 calc(100% - var(--compare-x)) 0 0);
  mix-blend-mode: normal;
  opacity: 1;
}

.tracking-surface {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.camera-feed,
.camera-overlay {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-feed {
  transform: scaleX(-1);
}

.camera-overlay {
  pointer-events: none;
}

.control-panel {
  display: grid;
  grid-template-columns: minmax(270px, 0.9fr) minmax(210px, 0.55fr) minmax(270px, 0.75fr);
  gap: 14px 18px;
  align-items: start;
  padding: 12px;
  border: 1px solid rgba(38, 35, 31, 0.14);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.88);
  box-shadow: 0 14px 34px rgba(38, 35, 31, 0.1);
}

.action-row {
  flex-wrap: wrap;
}

.action-row .button {
  flex: 1 1 118px;
}

.status-row {
  display: grid;
  gap: 4px;
  align-self: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.tuning-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(170px, 0.85fr) repeat(2, minmax(240px, 1fr)) minmax(250px, 1fr);
  gap: 12px;
  align-items: center;
}

.mode-row,
.switch-row,
.control-row,
.file-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  min-width: 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.mode-row {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
}

.mode-segment {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
  min-width: 260px;
  padding: 3px;
  border: 1px solid rgba(38, 35, 31, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.44);
}

.mode-option {
  min-width: 0;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 850;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-option.is-active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 14px rgba(15, 143, 141, 0.2);
}

.control-row {
  display: grid;
  grid-template-columns: max-content minmax(120px, 1fr);
  justify-content: space-between;
}

.mode-row > span,
.switch-row span,
.control-row span,
.file-pick span {
  min-width: 0;
  white-space: nowrap;
}

.control-row input[type="range"] {
  width: 100%;
  min-width: 120px;
  accent-color: var(--accent);
}

.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(96px, 1fr));
  justify-content: stretch;
}

.toggle-grid .switch-row {
  min-width: 0;
}

.asset-grid {
  align-items: stretch;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.file-pick {
  position: relative;
  flex: 1;
  min-width: 120px;
  justify-content: center;
  border: 1px dashed rgba(38, 35, 31, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.34);
  cursor: pointer;
}

.file-pick input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.marker-body {
  background: #f5f1e8;
}

.marker-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  gap: 12px;
  padding: 18px;
}

.marker-card {
  display: grid;
  place-items: center;
  width: min(43vmin, 360px);
  aspect-ratio: 1;
  padding: 4%;
  background: #fff;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.22);
}

.apriltag-marker {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  image-rendering: pixelated;
}

.marker-label {
  margin: 0;
  max-width: min(86vmin, 720px);
  color: #111;
  font-size: clamp(18px, 3.2vmin, 32px);
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1.1;
  text-align: center;
  overflow-wrap: anywhere;
}

.marker-ad {
  color: var(--accent-strong);
  font-size: clamp(16px, 2.6vmin, 26px);
  font-weight: 900;
  text-align: center;
  text-decoration: none;
}

.marker-ad:hover {
  text-decoration: underline;
}

.marker-print {
  min-width: 120px;
}

@media (max-width: 980px) {
  .control-panel {
    grid-template-columns: 1fr;
    align-items: center;
  }

  .tuning-grid {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .asset-grid {
    justify-content: stretch;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw - 20px, 1440px);
    padding-top: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand-lockup {
    width: 100%;
  }

  .top-tools,
  .action-row {
    flex-wrap: wrap;
    width: 100%;
  }

  .follow-link {
    flex: 1 1 180px;
    justify-content: center;
  }

  .lang-button {
    flex: 0 0 auto;
  }

  .action-row .button {
    flex: 1 1 30%;
  }

  .stage {
    min-height: 240px;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

  .tuning-grid {
    grid-template-columns: 1fr;
  }

  .control-row input[type="range"] {
    width: min(58vw, 240px);
  }

  .mode-row {
    grid-template-columns: 1fr;
  }

  .mode-segment {
    width: 100%;
    min-width: 0;
  }

  .toggle-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #fff;
  }

  .marker-print {
    display: none;
  }

  .marker-shell {
    min-height: auto;
    padding: 0;
  }

  .marker-card {
    width: 45vmin;
    box-shadow: none;
  }
}
