@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Orbitron:wght@400;700;900&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --scanner-top: max(74px, env(safe-area-inset-top));
  --scanner-bottom: max(130px, env(safe-area-inset-bottom));
  --scanner-side: 16px;
}

html, body { 
  width: 100%; height: 100%; 
  overflow: hidden; 
  background: #000; 
  font-family: 'Share Tech Mono', monospace; 
  color: #00ffcc;
}

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

/* Camera Stream */
#camera-stream {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: 1;
  filter: none;
}

/* Subtle camera vignette */
#crt-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(circle at center, rgba(0, 0, 0, 0) 48%, rgba(0, 0, 0, 0.42) 100%),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0) 26%, rgba(0, 0, 0, 0.22));
}

/* Scanline Animation */
.scanline {
  position: absolute;
  left: var(--scanner-side);
  right: var(--scanner-side);
  top: var(--scanner-top);
  height: 2px;
  z-index: 11;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(0, 255, 204, 0.95), transparent);
  box-shadow: 0 0 14px rgba(0, 255, 204, 0.85), 0 0 34px rgba(0, 255, 204, 0.35);
  opacity: 0.78;
  animation: scanline 3.8s ease-in-out infinite;
}

@keyframes scanline {
  0% { transform: translateY(0); opacity: 0; }
  8% { opacity: 0.78; }
  92% { opacity: 0.78; }
  100% { transform: translateY(calc(100vh - var(--scanner-top) - var(--scanner-bottom) - 2px)); opacity: 0; }
}

/* Status Bar */
#status-bar {
  position: absolute;
  top: 0; left: 0; width: 100%;
  padding: max(15px, env(safe-area-inset-top)) 25px 18px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  z-index: 10;
  background: linear-gradient(to bottom, rgba(0,0,0,0.9), transparent);
  font-family: 'Orbitron', sans-serif;
  text-shadow: 0 0 5px #00ffcc;
}

.status-left { display: flex; flex-direction: column; gap: 5px; }

#status-text {
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 2px;
  animation: blink 2s infinite;
}

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

.sys-info { font-size: 10px; color: #00ccaa; font-family: 'Share Tech Mono'; }

.mode-toggle label {
  display: flex; align-items: center; gap: 8px;
  font-size: 10px; cursor: pointer; letter-spacing: 1px;
  padding: 7px 9px;
  border: 1px solid rgba(0, 255, 204, 0.28);
  background: rgba(0, 20, 15, 0.42);
  backdrop-filter: blur(6px);
}
.mode-toggle input { cursor: pointer; accent-color: #00ffcc; }

/* Camera State */
.camera-state {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 12px;
  padding: 28px;
  background: radial-gradient(circle at 50% 35%, rgba(0, 255, 204, 0.12), rgba(0, 0, 0, 0.95) 58%);
  color: #d9fff7;
}

.camera-state.hidden {
  opacity: 0;
  pointer-events: none;
}

.camera-state .state-code {
  color: #ff0055;
  font-family: 'Orbitron', sans-serif;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 2px;
  text-shadow: 0 0 10px rgba(255, 0, 85, 0.7);
}

.camera-state h1 {
  max-width: 520px;
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(24px, 7vw, 44px);
  line-height: 1.08;
  color: #fff;
  text-shadow: 0 0 18px rgba(0, 255, 204, 0.5);
}

.camera-state p {
  max-width: 520px;
  color: #aaffea;
  font-size: 15px;
  line-height: 1.6;
}

.camera-state button {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid #00ffcc;
  background: rgba(0, 255, 204, 0.12);
  color: #00ffcc;
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(0, 255, 204, 0.18);
}

/* Processing State */
.processing-overlay {
  position: absolute;
  inset: 0;
  z-index: 45;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.processing-overlay.hidden {
  opacity: 0;
}

#locked-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.34;
  filter: saturate(0.7) contrast(1.08);
}

.processing-overlay::before {
  content: '';
  position: absolute;
  inset: var(--scanner-top) var(--scanner-side) var(--scanner-bottom) var(--scanner-side);
  border: 1px solid rgba(255, 0, 85, 0.62);
  box-shadow: inset 0 0 34px rgba(255, 0, 85, 0.12), 0 0 24px rgba(255, 0, 85, 0.18);
}

.processing-card {
  position: absolute;
  left: 50%;
  bottom: calc(var(--scanner-bottom) + 16px);
  width: min(520px, calc(100vw - 32px));
  transform: translateX(-50%);
  padding: 14px;
  background: linear-gradient(135deg, rgba(16, 0, 8, 0.82), rgba(0, 18, 16, 0.78));
  border: 1px solid rgba(255, 0, 85, 0.62);
  color: #d9fff7;
  backdrop-filter: blur(9px);
  box-shadow: 0 0 22px rgba(255, 0, 85, 0.2);
}

.processing-code {
  color: #ff0055;
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 2px;
  margin-bottom: 6px;
}

.processing-title {
  font-family: 'Orbitron', sans-serif;
  color: #fff;
  font-size: 16px;
  font-weight: 900;
  line-height: 1.25;
  text-shadow: 0 0 10px rgba(255, 0, 85, 0.42);
}

.processing-detail {
  margin-top: 5px;
  color: #aaffea;
  font-size: 12px;
  line-height: 1.45;
}

.processing-steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 12px;
}

.processing-steps span {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(0, 255, 204, 0.22);
  color: rgba(170, 255, 234, 0.62);
  font-size: 10px;
  text-align: center;
  background: rgba(0, 0, 0, 0.28);
}

.processing-steps span.complete {
  border-color: rgba(0, 255, 204, 0.52);
  color: #00ffcc;
}

.processing-steps span.active {
  border-color: #ff0055;
  color: #fff;
  background: rgba(255, 0, 85, 0.2);
  box-shadow: 0 0 12px rgba(255, 0, 85, 0.28);
}

/* Advanced Scanner Reticle */
#scanner-container {
  position: absolute;
  inset: var(--scanner-top) var(--scanner-side) var(--scanner-bottom) var(--scanner-side);
  z-index: 10;
  pointer-events: none;
  border: 1px solid rgba(0, 255, 204, 0.2);
  box-shadow: inset 0 0 40px rgba(0, 255, 204, 0.05);
}

.reticle-ring-1 {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
  border: 0;
  border-top: 1px dashed rgba(0, 255, 204, 0.28);
  animation: none;
}

.reticle-ring-2 {
  position: absolute;
  top: 0;
  left: 50%;
  width: 1px;
  height: 100%;
  border: 0;
  border-left: 1px dashed rgba(0, 255, 204, 0.28);
  animation: none;
}

.reticle-core {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px; height: 10px;
  transform: translate(-50%, -50%);
  background: rgba(0, 255, 204, 0.35);
  border-radius: 50%;
  box-shadow: 0 0 10px #00ffcc;
  transition: all 0.3s;
}

.corner {
  position: absolute;
  width: clamp(48px, 14vw, 86px);
  height: clamp(48px, 14vw, 86px);
  border-color: rgba(0, 255, 204, 0.8);
  border-style: solid;
  transition: all 0.2s ease;
}

.top-left { top: -1px; left: -1px; border-width: 4px 0 0 4px; }
.top-right { top: -1px; right: -1px; border-width: 4px 4px 0 0; }
.bottom-left { bottom: -1px; left: -1px; border-width: 0 0 4px 4px; }
.bottom-right { bottom: -1px; right: -1px; border-width: 0 4px 4px 0; }

.scanning .corner {
  border-color: #ff0055;
  box-shadow: 0 0 20px rgba(255, 0, 85, 0.8);
  transform: scale(0.9);
}

.scanning .reticle-core {
  background: rgba(255, 0, 85, 0.5);
  box-shadow: 0 0 20px #ff0055;
  animation: pulse-core 0.5s infinite alternate;
}

@keyframes spin { 100% { transform: rotate(360deg); } }
@keyframes spin-reverse { 100% { transform: rotate(-360deg); } }
@keyframes pulse-core { 100% { transform: translate(-50%, -50%) scale(1.5); } }

/* Controls */
#controls {
  position: absolute;
  right: 0;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 0 4px;
  pointer-events: none;
}

#scan-btn {
  width: 96px;
  height: 96px;
  min-width: 96px;
  min-height: 96px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 255, 204, 0.18), rgba(0, 0, 0, 0.78) 68%);
  border: 3px solid #00ffcc;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  backdrop-filter: blur(5px);
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 24px rgba(0, 255, 204, 0.35), inset 0 0 18px rgba(0, 255, 204, 0.16);
  color: #00ffcc;
  font-family: 'Orbitron', sans-serif;
  touch-action: manipulation;
  user-select: none;
  pointer-events: auto;
}

#scan-btn::before {
  content: none;
  position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 64px; height: 64px;
  border: 1px dashed rgba(0, 255, 204, 0.8);
  border-radius: 50%;
  animation: spin 5s linear infinite;
}

.scan-label {
  position: relative;
  z-index: 1;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 1.5px;
  line-height: 1;
}

#scan-btn:active { transform: scale(0.96); }
#scan-btn.scanning { border-color: #ff0055; box-shadow: 0 0 30px rgba(255, 0, 85, 0.5); }
#scan-btn.scanning::before { border-color: #ff0055; animation: spin 1s linear infinite; }
#scan-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.control-hint {
  min-height: 18px;
  max-width: 220px;
  padding: 5px 12px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(0, 255, 204, 0.18);
  color: #aaffea;
  font-size: 11px;
  text-align: center;
  backdrop-filter: blur(5px);
  pointer-events: none;
}

/* Distributed Holographic HUD Overlay (Mobile-Friendly) */
#hud-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 30;
  pointer-events: none;
  transition: opacity 0.4s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  padding: max(72px, calc(env(safe-area-inset-top) + 58px)) 12px max(108px, calc(env(safe-area-inset-bottom) + 96px)) 12px;
  box-sizing: border-box;
}

#hud-overlay.hidden {
  opacity: 0;
}

.hud-panel {
  position: relative;
  pointer-events: auto;
  background: linear-gradient(135deg, rgba(0, 24, 18, 0.76), rgba(0, 0, 0, 0.62));
  backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 255, 204, 0.34);
  padding: 15px;
  color: #00ffcc;
  box-shadow: 0 0 15px rgba(0, 255, 204, 0.1), inset 0 0 10px rgba(0, 255, 204, 0.05);
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  box-sizing: border-box;
}

/* Mobile-Friendly Placements */
.hud-header {
  border-left: 3px solid #00ffcc;
  clip-path: polygon(0 0, 100% 0, calc(100% - 10px) 100%, 0 100%);
  max-height: 28vh;
  overflow-y: auto;
}

.hud-body {
  border-left: 3px solid #00ffcc;
  border-bottom: 1px solid #00ffcc;
  max-height: 42vh;
  overflow-y: auto;
}

.obj-name-container {
  display: flex; flex-direction: column;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(0, 255, 204, 0.3);
  padding-bottom: 10px;
}

#result-object {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(17px, 4.8vw, 28px);
  line-height: 1.15;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 8px #00ffcc;
  text-transform: uppercase;
  margin: 0;
  overflow-wrap: anywhere;
}

#result-status {
  font-size: 12px;
  margin-top: 5px;
  display: inline-block;
  padding: 2px 8px;
  background: rgba(0, 255, 204, 0.2);
  border: 1px solid #00ffcc;
}

.status-danger { color: #ff0055; border-color: #ff0055 !important; background: rgba(255, 0, 85, 0.2) !important; text-shadow: 0 0 5px #ff0055;}
.status-warn { color: #ffcc00; border-color: #ffcc00 !important; background: rgba(255, 204, 0, 0.2) !important; }

#close-hud {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom)); left: 12px;
  background: rgba(255, 0, 85, 0.2); 
  border: 1px solid #ff0055; 
  color: #ff0055;
  min-height: 44px;
  padding: 0 16px;
  font-family: 'Share Tech Mono'; 
  font-size: 13px; 
  cursor: pointer;
  transition: all 0.2s;
  pointer-events: auto;
}
#close-hud:hover { background: #ff0055; color: #fff; box-shadow: 0 0 10px #ff0055; }

/* Typwriter Text Areas */
.terminal-text {
  font-size: 13px; line-height: 1.6; color: #aaffea;
  margin-bottom: 15px;
  min-height: 42px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.result-summary {
  font-size: 14px;
  color: #d7fff7;
}

.tech-specs {
  margin-bottom: 14px;
  border-left: 2px solid #00ffcc;
  padding-left: 10px;
}

.tech-specs ul {
  list-style-type: none;
}
.tech-specs li::before {
  content: '> ';
  color: #00ffcc;
}

.tech-specs li {
  margin-bottom: 8px;
  color: #d7fff7;
  line-height: 1.45;
}

.section-title,
.history-disclosure summary {
  color: #00ffcc;
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 1px;
  padding-bottom: 7px;
  margin-bottom: 9px;
  border-bottom: 1px solid rgba(0, 255, 204, 0.3);
}

.history-disclosure {
  margin-top: 10px;
}

.history-disclosure summary {
  cursor: pointer;
  list-style: none;
}

.history-disclosure summary::-webkit-details-marker {
  display: none;
}

.history-text {
  font-size: 12px;
  text-align: left;
}

/* Action Commands */
.actions-container {
  display: flex; flex-direction: column; gap: 8px;
}

.action-btn {
  background: rgba(0, 40, 30, 0.8);
  border: 1px solid rgba(0, 255, 204, 0.5);
  color: #00ffcc;
  padding: 12px 15px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.action-btn:hover {
  background: rgba(0, 255, 204, 0.2);
  box-shadow: 0 0 15px rgba(0, 255, 204, 0.4);
  padding-left: 20px;
}

.action-btn::before {
  content: '';
  position: absolute;
  top: 0; left: -100%; width: 50%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(0, 255, 204, 0.4), transparent);
  transition: all 0.4s;
}

.action-btn:hover::before { left: 100%; }

/* Executing Overlay */
#executing-overlay {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

#executing-overlay.active { opacity: 1; pointer-events: all; }

.loader-bar {
  width: 200px; height: 4px;
  background: rgba(0, 255, 204, 0.2);
  margin-top: 20px;
  position: relative;
  overflow: hidden;
}

.loader-bar::after {
  content: ''; position: absolute;
  top: 0; left: 0; width: 50%; height: 100%;
  background: #00ffcc;
  animation: load 1s ease-in-out infinite alternate;
}

@keyframes load { 0% { left: 0; } 100% { left: 50%; } }

/* Glitch Effect */
.glitch {
  position: relative;
}
.glitch::before, .glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}
.glitch::before {
  left: 2px;
  text-shadow: -1px 0 red;
  clip: rect(24px, 550px, 90px, 0);
  animation: glitch-anim-2 3s infinite linear alternate-reverse;
}
.glitch::after {
  left: -2px;
  text-shadow: -1px 0 blue;
  clip: rect(85px, 550px, 140px, 0);
  animation: glitch-anim 2.5s infinite linear alternate-reverse;
}

@keyframes glitch-anim {
  0% { clip: rect(15px, 9999px, 71px, 0); }
  20% { clip: rect(35px, 9999px, 19px, 0); }
  40% { clip: rect(65px, 9999px, 93px, 0); }
  60% { clip: rect(81px, 9999px, 5px, 0); }
  80% { clip: rect(23px, 9999px, 34px, 0); }
  100% { clip: rect(9px, 9999px, 86px, 0); }
}
@keyframes glitch-anim-2 {
  0% { clip: rect(65px, 9999px, 100px, 0); }
  20% { clip: rect(10px, 9999px, 45px, 0); }
  40% { clip: rect(23px, 9999px, 76px, 0); }
  60% { clip: rect(89px, 9999px, 12px, 0); }
  80% { clip: rect(45px, 9999px, 67px, 0); }
  100% { clip: rect(12px, 9999px, 34px, 0); }
}

.cursor {
  display: inline-block;
  width: 8px; height: 15px;
  background-color: #00ffcc;
  animation: blink 1s step-end infinite;
  vertical-align: middle;
}

@media (max-width: 520px) {
  :root {
    --scanner-top: max(68px, env(safe-area-inset-top));
    --scanner-bottom: max(122px, env(safe-area-inset-bottom));
    --scanner-side: 10px;
  }

  #status-bar {
    padding-left: 12px;
    padding-right: 12px;
  }

  #status-text {
    font-size: 13px;
    letter-spacing: 1.2px;
  }

  .sys-info {
    font-size: 9px;
    max-width: 190px;
  }

  .mode-toggle label {
    max-width: 118px;
    font-size: 9px;
    line-height: 1.25;
  }

  #scanner-container {
    inset: var(--scanner-top) var(--scanner-side) var(--scanner-bottom) var(--scanner-side);
  }

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

  .hud-panel {
    padding: 12px;
  }

  .hud-header {
    max-height: 25vh;
  }

  .hud-body {
    max-height: 41vh;
  }

  .processing-card {
    bottom: calc(var(--scanner-bottom) + 10px);
    width: calc(100vw - 20px);
    padding: 12px;
  }

  .processing-title {
    font-size: 14px;
  }

  .processing-steps {
    grid-template-columns: repeat(2, 1fr);
  }

  #controls {
    bottom: max(12px, env(safe-area-inset-bottom));
    padding: 0 0 4px;
  }

  #scan-btn {
    width: 96px;
    height: 96px;
    min-width: 96px;
    min-height: 96px;
  }
}
