*,
*::before,
*::after {
  box-sizing: border-box;
}

/* 레트로: 지뢰찾기식 베젤 + 블랙 필드 + 형광 녹 (옛 LCD / 퐁 느낌) */
:root {
  --field: #0a0a0a;
  --desktop: #4a4a4a;
  --panel: #b8b8b8;
  --panel-dark: #2a2a2a;
  --panel-inset: #1a1a1a;
  --bevel-light: #e8e8e8;
  --bevel-mid: #808080;
  --bevel-dark: #1a1a1a;
  --phosphor: #39ff14;
  --phosphor-dim: #2bc40f;
  --text-on-dark: #c8ffc8;
  --text-muted: #6a8a6a;
  --lcd-green: #9acd32;
  --danger: #ff3333;
  --danger-dim: #cc2222;
  --safe: var(--phosphor);
  --radius: 0px;
  --border-chunky: 3px;
  --font-pixel: "Galmuri14", "Galmuri11", monospace;
  --font-score: "VT323", "Galmuri14", monospace;
}

html {
  height: 100%;
  height: -webkit-fill-available;
}

body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  min-height: -webkit-fill-available;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--text-on-dark);
  font-family: var(--font-pixel);
  font-size: 14px;
  line-height: 1.35;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: none;
  font-smooth: never;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  background: var(--desktop);
  background-image: repeating-linear-gradient(
    180deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.12) 2px,
    rgba(0, 0, 0, 0.12) 4px
  );
}

@media (min-width: 641px) {
  body {
    overflow: hidden;
  }
}

#app {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: var(--field);
  min-height: 100%;
  min-height: -webkit-fill-available;
  min-height: 100dvh;
  border: var(--border-chunky) solid var(--bevel-dark);
  box-shadow:
    inset 0 0 0 2px var(--bevel-mid),
    0 0 0 4px var(--panel);
}

#webcam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  z-index: 0;
  filter: grayscale(0.35) contrast(1.15) brightness(0.88);
}

.scouter-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: rgba(0, 20, 0, 0.18);
  box-shadow: inset 0 0 0 1px rgba(57, 255, 20, 0.15);
}

.scouter-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.25) 2px,
    rgba(0, 0, 0, 0.25) 4px
  );
  pointer-events: none;
}

.scouter-overlay::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse 75% 60% at 50% 50%,
    transparent 40%,
    rgba(0, 0, 0, 0.35) 100%
  );
  pointer-events: none;
}

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  pointer-events: none;
  z-index: 2;
}

/* 지뢰찾기 창 하단 느낌 */
#status {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  margin: 0;
  padding: 0.45rem 0.75rem;
  padding-left: calc(0.75rem + env(safe-area-inset-left, 0px));
  padding-right: calc(0.75rem + env(safe-area-inset-right, 0px));
  font-family: var(--font-pixel);
  font-size: 12px;
  letter-spacing: 0.04em;
  line-height: 1.3;
  color: #1a1a1a;
  background: var(--panel);
  border-top: 2px solid var(--bevel-light);
  border-left: 2px solid var(--bevel-light);
  border-right: 2px solid var(--bevel-dark);
  border-bottom: 2px solid var(--bevel-dark);
  border-radius: var(--radius);
  max-width: min(92vw, 28rem);
  text-align: center;
  z-index: 30;
}

#status:empty {
  display: none;
}

.camera-start {
  position: fixed;
  left: 50%;
  bottom: calc(3.75rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 35;
  margin: 0;
  padding: 0.5rem 1rem;
  font-family: var(--font-pixel);
  font-size: 13px;
  letter-spacing: 0.06em;
  color: #111;
  background: var(--panel);
  border-top: 2px solid var(--bevel-light);
  border-left: 2px solid var(--bevel-light);
  border-right: 2px solid var(--bevel-dark);
  border-bottom: 2px solid var(--bevel-dark);
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: 2px 2px 0 #0a0a0a;
}

.camera-start:hover {
  filter: brightness(1.08);
}

.camera-start:active {
  transform: translateX(-50%) translate(1px, 1px);
  box-shadow: 1px 1px 0 #0a0a0a;
}

.camera-start:focus-visible {
  outline: 2px dashed var(--phosphor);
  outline-offset: 3px;
}

.camera-start[hidden] {
  display: none !important;
}

/* 스카우터 렌즈: 카메라 화면 왼쪽 위 오버레이 */
.hud {
  position: absolute;
  left: max(0.35rem, env(safe-area-inset-left, 0px));
  top: max(0.35rem, env(safe-area-inset-top, 0px));
  z-index: 15;
  text-align: left;
  pointer-events: none;
  width: auto;
  max-width: min(46vw, 10.5rem);
}

.hud[hidden] {
  display: none !important;
}

.hud-frame {
  position: relative;
  padding: 0.35rem 0.45rem 0.42rem;
  background: rgba(0, 12, 2, 0.82);
  border: 2px solid rgba(57, 255, 20, 0.88);
  border-radius: 3px;
  box-shadow:
    0 0 14px rgba(57, 255, 20, 0.38),
    inset 0 0 24px rgba(57, 255, 20, 0.06),
    3px 3px 0 rgba(0, 0, 0, 0.55);
}

/* 렌즈 코너 포인트 */
.hud-frame::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  pointer-events: none;
  box-shadow:
    inset 3px 3px 0 rgba(57, 255, 20, 0.35),
    inset -3px -3px 0 rgba(0, 0, 0, 0.45);
  opacity: 0.85;
}

.hud-measuring {
  margin: 0 0 0.15rem;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: rgba(180, 255, 170, 0.65);
}

.hud-power {
  margin: 0;
  font-family: var(--font-score);
  font-size: clamp(1.65rem, 9vw, 2.75rem);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  line-height: 1;
  color: var(--phosphor);
  text-shadow:
    0 0 10px rgba(57, 255, 20, 0.55),
    2px 2px 0 #063606;
}

.hud-power--scanning {
  animation: lcd-blink 0.8s step-end infinite;
}

.hud-power--final {
  animation: none;
  text-shadow:
    0 0 12px rgba(57, 255, 20, 0.5),
    2px 2px 0 #0a3d0a;
}

@keyframes lcd-blink {
  50% {
    opacity: 0.88;
  }
}

.hud-verdict {
  margin: 0.35rem 0 0;
  padding-top: 0.3rem;
  border-top: 1px solid rgba(57, 255, 20, 0.35);
  font-family: var(--font-pixel);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.hud-verdict--normal {
  color: var(--safe);
}

.hud-verdict--quarantine {
  color: var(--danger);
  text-shadow: 1px 1px 0 #400;
}

/* 위험: 단순 번쩍 */
body.emergency-quarantine {
  background: #2a1010;
}

body.emergency-quarantine::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  background: rgba(80, 0, 0, 0.25);
  animation: alarm-blink 0.6s step-end infinite;
}

body.emergency-quarantine::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  box-shadow: inset 0 0 0 4px var(--danger);
}

body.emergency-quarantine #app {
  z-index: 18;
  filter: contrast(1.08) brightness(0.92);
}

body.emergency-quarantine #app .scouter-overlay {
  background: rgba(40, 0, 0, 0.35);
}

body.emergency-quarantine #app .scouter-overlay::before {
  opacity: 0.5;
}

@keyframes alarm-blink {
  50% {
    opacity: 0.65;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hud-power--scanning {
    animation: none;
  }

  body.emergency-quarantine::before {
    animation: none;
  }
}

@media (max-width: 640px) {
  :root {
    --camera-preview-w: min(98vw, 520px);
    --camera-preview-h: min(
      calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 5.25rem),
      calc(var(--camera-preview-w) * 4 / 3)
    );
  }

  body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #app {
    position: fixed;
    left: 50%;
    right: auto;
    top: calc(0.35rem + env(safe-area-inset-top, 0px));
    bottom: auto;
    transform: translateX(-50%);
    width: var(--camera-preview-w);
    height: var(--camera-preview-h);
    min-height: unset;
    border: 3px solid var(--bevel-dark);
    box-shadow:
      inset 0 0 0 2px var(--bevel-mid),
      0 0 0 3px var(--panel),
      6px 6px 0 rgba(0, 0, 0, 0.4);
    overflow: hidden;
    background: var(--field);
  }

  .hud {
    left: max(0.4rem, env(safe-area-inset-left, 0px));
    top: max(0.4rem, env(safe-area-inset-top, 0px));
    max-width: min(52vw, 9.25rem);
  }

  .hud-frame {
    padding: 0.28rem 0.38rem 0.34rem;
  }

  .hud-measuring {
    font-size: 9px;
    margin-bottom: 0.12rem;
  }

  .hud-power {
    font-size: clamp(1.45rem, 11vw, 2.35rem);
  }

  .hud-verdict {
    font-size: 10px;
    margin-top: 0.28rem;
    padding-top: 0.22rem;
  }

  #status {
    font-size: 10px;
    max-width: min(96vw, 28rem);
    padding: 0.35rem 0.55rem;
  }

  .camera-start {
    font-size: 11px;
    padding: 0.42rem 0.85rem;
    bottom: calc(3.35rem + env(safe-area-inset-bottom, 0px));
  }
}
