:root {
  --accent: #29f0ff;
  --lock: #ffd23f;
  --ok: #3dff8a;
  --bad: #ff8a8a;
  --bg: #03121c;
  --fg: #e8f7fb;
  --muted: #8fb3bf;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #000; color: var(--fg);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#stage { position: fixed; inset: 0; }
#stage video, #stage canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#overlay .track { fill: none; stroke: var(--lock); stroke-linejoin: round; }
#overlay[data-state="cooldown"] .track { stroke: var(--ok); }
#overlay[data-state="locked"] .target, #overlay[data-state="cooldown"] .target { stroke-opacity: .2; }

.top {
  position: fixed; top: 0; left: 0; right: 0;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) calc(env(safe-area-inset-right, 0px) + 12px) 8px calc(env(safe-area-inset-left, 0px) + 12px);
  display: flex; gap: 8px; align-items: center;
  background: linear-gradient(rgba(0, 0, 0, .6), transparent);
}
#chips { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.chip[data-detected="true"] { border-color: var(--lock); box-shadow: inset 0 0 0 1px var(--lock); }
@media (max-width: 480px) {
  .top { padding-left: calc(env(safe-area-inset-left, 0px) + 8px); padding-right: calc(env(safe-area-inset-right, 0px) + 8px); }
  #chips { gap: 4px; }
  #chips .chip { flex: 1 1 auto; padding: 8px 6px; font-size: 14px; }
}
.chip {
  border: 1px solid rgba(255, 255, 255, .35); background: rgba(0, 0, 0, .35); color: var(--fg);
  border-radius: 999px; padding: 9px 15px; font: inherit; font-weight: 600; white-space: nowrap; min-height: 40px;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #012; }
#version { font-size: 11px; color: var(--muted); white-space: nowrap; }

#status {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 124px);
  max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 6px 14px 8px; border-radius: 999px; background: rgba(0, 0, 0, .6);
  font-size: 13px; pointer-events: none;
}
#progress {
  position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  background: var(--lock); transform: scaleX(0); transform-origin: left; transition: transform .12s linear;
}
#status[data-state="cooldown"] #progress { background: var(--ok); }

.toggles {
  position: fixed; right: calc(env(safe-area-inset-right, 0px) + 14px); bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  font-size: 13px; text-shadow: 0 1px 3px #000;
}
.toggles label { display: flex; gap: 6px; align-items: center; }

#shutter {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  width: 76px; height: 76px; border-radius: 50%; transform: translateX(-50%);
  border: 4px solid #fff; background: var(--accent); box-shadow: 0 0 0 4px rgba(0, 0, 0, .35);
}
#shutter:active { transform: translateX(-50%) scale(.92); }
#shutter:disabled { opacity: .4; }

.card {
  position: fixed; left: calc(env(safe-area-inset-left, 0px) + 12px); bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  width: 104px; display: flex; flex-direction: column; gap: 4px; padding: 6px;
  border: 1px solid rgba(255, 255, 255, .25); border-radius: 12px; background: rgba(0, 0, 0, .65);
  font-size: 11px; line-height: 1.25; overflow-wrap: anywhere;
}
.card[data-kind="ok"] { border-color: var(--ok); }
.card[data-kind="error"] { border-color: var(--bad); }
.card img { width: 100%; aspect-ratio: 1600 / 919; object-fit: contain; cursor: pointer; }
.link { align-self: flex-start; border: 0; padding: 0; background: none; color: var(--accent); font: inherit; text-decoration: underline; }

@media (orientation: landscape) {
  #shutter { left: auto; bottom: auto; top: 50%; right: calc(env(safe-area-inset-right, 0px) + 20px); transform: translateY(-50%); }
  #shutter:active { transform: translateY(-50%) scale(.92); }
  #status { bottom: calc(env(safe-area-inset-bottom, 0px) + 4px); }
  .toggles { bottom: calc(env(safe-area-inset-bottom, 0px) + 10px); }
  .card { left: auto; bottom: auto; right: calc(env(safe-area-inset-right, 0px) + 10px); top: calc(env(safe-area-inset-top, 0px) + 50px); width: 96px; }
}

#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .3s; }
#flash.on { opacity: .8; transition: none; }

.panel {
  position: fixed; inset: 0; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  padding: calc(env(safe-area-inset-top, 0px) + 24px) 20px calc(env(safe-area-inset-bottom, 0px) + 24px);
  text-align: center;
  background: radial-gradient(120% 90% at 50% 0%, #0b4a63 0%, #052636 55%, var(--bg) 100%);
}
.panel h1 { margin: 0; font-size: 28px; }
.panel p { margin: 0; max-width: 34em; color: var(--muted); }
.panel .small { font-size: 13px; }
.panel a { color: var(--accent); }
#error { color: var(--bad); min-height: 1.4em; }

#resultImg { max-width: 100%; max-height: 62vh; filter: drop-shadow(0 8px 24px rgba(0, 0, 0, .5)); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.btn {
  display: inline-block; border: 1px solid rgba(255, 255, 255, .4); background: rgba(255, 255, 255, .08);
  color: var(--fg); border-radius: 12px; padding: 12px 20px; font: inherit; font-weight: 600; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #012; }
