:root {
  --ink: #05080d;
  --cyan: #29d3ff;
  --blue: #2b7cff;
  --green: #3ddc97;
  --amber: #ffcb47;
  --pink: #ff5470;
  font-family: 'Bricolage Grotesque', sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: #02040a;
  overflow: hidden;
  font-family: 'Bricolage Grotesque', sans-serif;
  color: #eaf6ff;
}
#root { height: 100vh; }

.app-root {
  position: relative;
  height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: radial-gradient(120% 80% at 50% 0%, #0a1524 0%, #02040a 70%);
  box-shadow: 0 0 60px rgba(41,211,255,.12);
  overflow: hidden;
}

/* ---- camera stage ---- */
.stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #000;
  display: flex; align-items: center; justify-content: center;
}
.video-feed {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.cam-error {
  text-align: center; padding: 24px;
  display: flex; flex-direction: column; align-items: center;
}
.cam-error-text { color: rgba(202,238,255,.8); max-width: 20rem; line-height: 1.5; }

/* top bar */
.top-bar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px;
  z-index: 8;
  background: linear-gradient(180deg, rgba(2,6,14,.75), transparent);
  backdrop-filter: blur(4px);
}
.brand {
  font-weight: 300; font-size: 17px; letter-spacing: -.02em;
  display: flex; align-items: baseline; gap: 4px;
}
.brand .pro {
  font-weight: 800;
  background: linear-gradient(90deg, var(--cyan), var(--green));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.status-pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px; font-weight: 700;
  padding: 6px 12px; border-radius: 999px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  color: #cdeeff;
  transition: all .25s;
}
.status-pill.ok {
  background: rgba(61,220,151,.18); border-color: rgba(61,220,151,.5); color: var(--green);
}

/* guide frame */
.guide-wrap {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 4; pointer-events: none;
}
.guide-frame {
  position: relative;
  width: 34%; height: 44%;
  border-radius: 40px;
  transition: box-shadow .25s;
}
.guide-frame.seek {
  box-shadow: 0 0 0 9999px rgba(2,6,14,.5), 0 0 24px rgba(255,203,71,.3);
  animation: seekpulse 1.6s ease-in-out infinite;
}
.guide-frame.ok {
  box-shadow: 0 0 0 9999px rgba(2,6,14,.5), 0 0 34px rgba(61,220,151,.6);
}
@keyframes seekpulse {
  0%,100% { box-shadow: 0 0 0 9999px rgba(2,6,14,.5), 0 0 18px rgba(255,203,71,.25); }
  50% { box-shadow: 0 0 0 9999px rgba(2,6,14,.5), 0 0 30px rgba(255,203,71,.55); }
}
.corner {
  position: absolute; width: 26px; height: 26px;
  border: 3px solid var(--amber);
  transition: border-color .25s;
}
.guide-frame.ok .corner { border-color: var(--green); }
.corner.tl { top: -2px; left: -2px; border-right: none; border-bottom: none; border-radius: 16px 0 0 0; }
.corner.tr { top: -2px; right: -2px; border-left: none; border-bottom: none; border-radius: 0 16px 0 0; }
.corner.bl { bottom: -2px; left: -2px; border-right: none; border-top: none; border-radius: 0 0 0 16px; }
.corner.br { bottom: -2px; right: -2px; border-left: none; border-top: none; border-radius: 0 0 16px 0; }
.scan-line {
  position: absolute; left: 10%; right: 10%; height: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  box-shadow: 0 0 12px var(--cyan);
  animation: scan 2.4s ease-in-out infinite;
}
@keyframes scan { 0%,100% { top: 8%; } 50% { top: 90%; } }

/* lock countdown ring */
.lock-ring {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
.lock-svg { width: 72px; height: 72px; transform: rotate(-90deg); }
.lock-bg { fill: rgba(2,6,14,.55); stroke: rgba(255,255,255,.15); stroke-width: 4; }
.lock-fg {
  fill: none; stroke: var(--green); stroke-width: 4; stroke-linecap: round;
  transition: stroke-dashoffset .1s linear;
  filter: drop-shadow(0 0 6px var(--green));
}
.lock-num {
  position: absolute;
  font-family: 'JetBrains Mono', monospace; font-weight: 800; font-size: 26px;
  color: #fff; text-shadow: 0 0 10px var(--green);
}

.detect-chip {
  margin-top: 22px;
  font-size: 13px; font-weight: 600;
  padding: 6px 14px; border-radius: 999px;
  backdrop-filter: blur(6px);
  transition: all .25s;
}
.detect-chip.seek { background: rgba(255,203,71,.15); color: var(--amber); border: 1px solid rgba(255,203,71,.4); }
.detect-chip.ok   { background: rgba(61,220,151,.2); color: var(--green); border: 1px solid rgba(61,220,151,.6); }

/* mode toggle */
.mode-toggle {
  position: absolute; top: 58px; left: 16px; z-index: 7;
  font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 12px;
  padding: 7px 13px; border-radius: 999px; cursor: pointer;
  border: 1px solid rgba(255,255,255,.2);
  backdrop-filter: blur(6px);
  transition: all .2s;
}
.mode-toggle.auto { background: rgba(41,211,255,.2); border-color: rgba(41,211,255,.5); color: var(--cyan); box-shadow: 0 0 16px rgba(41,211,255,.3); }
.mode-toggle.manual { background: rgba(255,255,255,.08); color: #cdeeff; }

/* clarity bar (horizontal, bottom of stage) */
.clarity-wrap {
  position: absolute; left: 16px; right: 16px; bottom: 16px;
  z-index: 5; display: flex; flex-direction: column; gap: 6px;
}
.clarity-track {
  width: 100%; height: 8px;
  background: rgba(255,255,255,.1);
  border-radius: 999px; overflow: hidden;
  border: 1px solid rgba(255,255,255,.15);
}
.clarity-fill { height: 100%; border-radius: 999px; transition: width .18s, background .25s; }
.clarity-label {
  font-size: 11px; font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
  text-align: center;
}

/* flash */
.flash-overlay {
  position: absolute; inset: 0; z-index: 20;
  background: #fff;
  animation: flashfade .3s ease-out forwards;
}
@keyframes flashfade { 0% { opacity: 1; } 100% { opacity: 0; } }

/* controls */
.controls {
  position: relative; z-index: 7;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 34px calc(18px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, #02040a 40%, rgba(2,6,14,.6));
}
.torch, .history-btn {
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.18);
  color: #eaf6ff; font-size: 22px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  position: relative; transition: all .2s;
}
.torch:disabled { opacity: .3; }
.torch.on { background: rgba(255,203,71,.25); border-color: var(--amber); box-shadow: 0 0 20px rgba(255,203,71,.5); }
.history-btn { overflow: visible; }
.hist-thumb { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.hist-count {
  position: absolute; top: -4px; right: -4px;
  background: var(--cyan); color: #02040a;
  font-size: 11px; font-weight: 800; font-family: 'JetBrains Mono', monospace;
  min-width: 20px; height: 20px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.shutter {
  width: 78px; height: 78px; border-radius: 50%;
  border: none; background: transparent; cursor: pointer;
  position: relative; padding: 0;
  transition: transform .2s;
}
.shutter.ready { transform: scale(1.06); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1.06); } 50% { transform: scale(1.12); } }
.shutter-ring { position: absolute; inset: 0; border-radius: 50%; padding: 5px; }
.shutter-core {
  position: absolute; inset: 8px; border-radius: 50%;
  background: linear-gradient(135deg, #eaf6ff, #b7e6ff);
  box-shadow: inset 0 0 0 3px #02040a;
  display: flex; align-items: center; justify-content: center;
}
.shutter-hint {
  font-family: 'JetBrains Mono', monospace; font-size: 10px; font-weight: 800;
  color: #02040a; letter-spacing: .05em;
}
.shutter:active .shutter-core { background: var(--cyan); }

/* modals */
.modal-back {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(2,4,10,.82); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; animation: fadein .2s;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 400px;
  background: linear-gradient(160deg, #0d1a2c, #071019);
  border: 1px solid rgba(41,211,255,.2);
  border-radius: 22px; padding: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
  animation: pop .3s cubic-bezier(.2,1.2,.4,1);
}
@keyframes pop { from { transform: scale(.9) translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-title { font-size: 20px; font-weight: 700; margin: 0 0 14px; letter-spacing: -.02em; }

.preview-img-wrap {
  display: flex; justify-content: center; margin-bottom: 12px;
}
.modal-img {
  max-height: 42vh; max-width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.preview-meta { display: flex; gap: 10px; justify-content: center; margin-bottom: 12px; flex-wrap: wrap; }
.meta-chip {
  font-family: 'JetBrains Mono', monospace; font-size: 12px; font-weight: 700;
  background: rgba(1,6,12,.6); border: 1px solid rgba(255,255,255,.1);
  padding: 5px 12px; border-radius: 999px; color: #cdeeff;
}
.ocr-status { display: flex; align-items: center; gap: 8px; color: var(--cyan); font-size: 13px; margin-bottom: 12px; justify-content: center; }
.ocr-read { text-align: center; font-size: 14px; color: rgba(202,238,255,.75); margin-bottom: 12px; }
.ocr-num { font-family: 'JetBrains Mono', monospace; font-weight: 800; font-size: 18px; color: var(--green); letter-spacing: 2px; }
.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(41,211,255,.3); border-top-color: var(--cyan);
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.modal-actions { display: flex; gap: 12px; }
.btn {
  flex: 1; padding: 15px; border-radius: 14px; font-weight: 800; font-size: 16px;
  cursor: pointer; border: none; transition: all .15s; font-family: inherit;
}
.btn.primary { background: linear-gradient(135deg, var(--cyan), var(--blue)); color: #02040a; }
.btn.primary:active { transform: scale(.97); }
.btn.danger { background: rgba(255,84,112,.15); color: var(--pink); border: 1px solid rgba(255,84,112,.5); }
.btn.danger:active { transform: scale(.97); background: rgba(255,84,112,.28); }
.btn.wide { width: 100%; flex: none; margin-top: 8px; }
.modal-tip { text-align: center; font-size: 11.5px; color: rgba(202,238,255,.45); margin: 12px 0 0; }

.upload-btn {
  background: linear-gradient(135deg, var(--cyan), var(--blue)); color: #02040a;
  font-weight: 700; padding: 12px 22px; border-radius: 12px; cursor: pointer;
}

/* drawer / gallery */
.drawer {
  width: 100%; max-width: 440px;
  max-height: 88vh; overflow-y: auto;
  background: linear-gradient(160deg, #0d1a2c, #071019);
  border: 1px solid rgba(41,211,255,.2);
  border-radius: 22px; padding: 20px;
  animation: pop .3s cubic-bezier(.2,1.2,.4,1);
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.close-x { background: none; border: none; color: #cdeeff; font-size: 20px; cursor: pointer; }
.hist-list { display: flex; flex-direction: column; gap: 10px; }
.empty { color: rgba(202,238,255,.5); text-align: center; padding: 30px 8px; font-style: italic; line-height: 1.6; }
.hist-item {
  display: flex; gap: 12px; align-items: center;
  background: rgba(1,6,12,.5); border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px; padding: 10px;
}
.hist-item-img { width: 44px; height: 64px; object-fit: cover; border-radius: 8px; }
.hist-item-body { flex: 1; }
.hist-val { font-family: 'JetBrains Mono', monospace; font-weight: 800; font-size: 20px; color: var(--green); }
.hist-val.muted { color: rgba(202,238,255,.35); font-size: 14px; font-style: italic; }
.hist-unit { font-size: 12px; color: var(--cyan); font-weight: 700; }
.hist-time { font-size: 11px; color: rgba(202,238,255,.45); }
.hist-clar { font-size: 11px; color: var(--amber); font-weight: 700; margin-top: 2px; }
.del { background: none; border: none; font-size: 16px; cursor: pointer; opacity: .5; }
.del:hover { opacity: 1; }

/* onboarding */
.onboard { text-align: center; }
.onboard-lead { font-size: 14px; color: rgba(202,238,255,.75); margin: 0 0 14px; line-height: 1.5; }
.onboard-list { text-align: left; list-style: none; padding: 0; margin: 8px 0 14px; }
.onboard-list li { padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.07); font-size: 14px; color: #dbf1ff; }
.onboard-tip { font-size: 12.5px; color: var(--amber); margin: 4px 0 8px; line-height: 1.5; }

.footer { text-align: center; margin-top: 16px; font-size: 12px; }
.footer a { color: var(--cyan); text-decoration: none; opacity: .7; }
.footer a:hover { opacity: 1; text-decoration: underline; }

.hidden { display: none; }