/* ── Design tokens ──────────────────────────────────────────────────── */
:root {
  --bg:         #080c14;
  --bg-card:    #0e1420;
  --bg-panel:   #131c2c;
  --bg-input:   #0a1220;
  --accent:     #00d4aa;
  --accent2:    #00f5c4;
  --accent-dim: rgba(0,212,170,.12);
  --border:     #1a2840;
  --border-hi:  #2a3e60;
  --text-hi:    #e8f0f8;
  --text-mid:   #7a96b8;
  --text-lo:    #3a5070;
  --red:        #ff4444;
  --amber:      #ffaa00;
  --r:          12px;
  --r-sm:       8px;
  --shadow:     0 8px 32px rgba(0,0,0,.6);
}

/* ── Reset & base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text-hi);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ── Typography ─────────────────────────────────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: .5px; }
h2 { font-size: 1.15rem; font-weight: 600; color: var(--accent); }
p  { line-height: 1.65; color: var(--text-mid); font-size: .9rem; }

/* ── Utility ────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.mono   { font-family: 'DM Mono', 'Courier New', monospace; }

/* ── Screen layout ──────────────────────────────────────────────────── */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0;
}

/* ── Permission screen ──────────────────────────────────────────────── */
#screen-permission {
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  gap: 20px;
}
.perm-logo {
  font-size: 4rem;
  filter: drop-shadow(0 0 20px var(--accent));
}
.perm-title {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent2), #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.perm-subtitle { font-size: .95rem; color: var(--text-mid); max-width: 320px; }
.features-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 340px;
  margin: 4px 0;
}
.feature-chip {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-size: .78rem;
  color: var(--text-mid);
  display: flex;
  align-items: center;
  gap: 6px;
}
.feature-chip span:first-child { font-size: 1.1rem; }
.disclaimer-note {
  font-size: .72rem;
  color: var(--text-lo);
  max-width: 300px;
  line-height: 1.5;
}
.disclaimer-link {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
#permission-error {
  color: var(--red);
  font-size: .85rem;
  background: rgba(255,68,68,.08);
  border: 1px solid rgba(255,68,68,.25);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  max-width: 300px;
}

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn-primary {
  background: linear-gradient(135deg, #00d4aa, #0096c7);
  color: #000;
  font-weight: 700;
  font-size: .95rem;
  border: none;
  border-radius: var(--r);
  padding: 14px 32px;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 4px 20px rgba(0,212,170,.4);
  min-width: 200px;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(0,212,170,.5); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .5; transform: none; cursor: default; }

.btn-secondary {
  background: var(--bg-panel);
  color: var(--text-hi);
  font-weight: 600;
  font-size: .88rem;
  border: 1px solid var(--border-hi);
  border-radius: var(--r-sm);
  padding: 10px 20px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.btn-secondary:hover { border-color: var(--accent); background: rgba(0,212,170,.06); }

.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 16px;
  color: var(--text-mid);
  font-size: .82rem;
  cursor: pointer;
  transition: all .15s;
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }
.btn-icon.flash-on { border-color: var(--amber); color: var(--amber); background: rgba(255,170,0,.06); }

/* ── Camera screen ──────────────────────────────────────────────────── */
#screen-camera {
  position: relative;
  background: #000;
}

.cam-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 30;
  padding: 12px 16px 8px;
  background: linear-gradient(to bottom, rgba(0,0,0,.75), transparent);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cam-title { font-size: .9rem; font-weight: 700; letter-spacing: 1.5px; color: var(--accent); }
.cam-time   { font-size: .72rem; color: var(--text-mid); font-family: monospace; }

/* Video */
#video-feed {
  width: 100%;
  height: 100dvh;
  object-fit: cover;
  display: block;
}

/* Overlay layers */
.cam-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

/* Viewfinder corner brackets */
.vf-corner {
  position: absolute;
  width: 28px;
  height: 28px;
  border-color: var(--accent);
  border-style: solid;
  opacity: .7;
}
.vf-corner.tl { top: 22%; left: 8%;  border-width: 2px 0 0 2px; }
.vf-corner.tr { top: 22%; right: 8%; border-width: 2px 2px 0 0; }
.vf-corner.bl { bottom: 40%; left: 8%;  border-width: 0 0 2px 2px; }
.vf-corner.br { bottom: 40%; right: 8%; border-width: 0 2px 2px 0; }

/* Stable glow ring */
#stable-ring {
  position: absolute;
  top: 20%; left: 5%;
  right: 5%; bottom: 38%;
  border-radius: 16px;
  border: 1.5px solid rgba(255,255,255,.15);
  transition: border-color .4s, opacity .4s;
  opacity: .2;
}

/* Scan lines animation */
#scan-lines {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 3px,
    rgba(0,212,170,.03) 3px,
    rgba(0,212,170,.03) 4px
  );
  animation: scanMove 4s linear infinite;
}
@keyframes scanMove {
  from { background-position: 0 0; }
  to   { background-position: 0 100px; }
}

/* Scanning progress bar at top */
.scan-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent);
  animation: scanBar 2s ease-in-out infinite;
}
@keyframes scanBar {
  0%,100% { transform: scaleX(0); transform-origin: left; }
  50%      { transform: scaleX(1); transform-origin: left; }
}

/* Guidance text */
#guidance-text {
  position: absolute;
  bottom: 38%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  font-size: .78rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background .3s, color .3s;
}
.guidance-ok    { background: rgba(0,212,170,.2);  color: var(--accent2); border: 1px solid rgba(0,212,170,.3); }
.guidance-warn  { background: rgba(255,170,0,.2);  color: var(--amber);   border: 1px solid rgba(255,170,0,.3); }
.guidance-error { background: rgba(255,68,68,.2);  color: var(--red);     border: 1px solid rgba(255,68,68,.3); }
.guidance-info  { background: rgba(56,189,248,.2); color: #7dd3fc;        border: 1px solid rgba(56,189,248,.25); }

#orient-guidance {
  position: absolute;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  font-size: .72rem;
  padding: 4px 12px;
  border-radius: 16px;
  white-space: nowrap;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.orient-ok   { background: rgba(0,212,170,.15); color: var(--accent); }
.orient-warn { background: rgba(255,170,0,.15); color: var(--amber); }
.orient-info { background: rgba(255,255,255,.08); color: var(--text-mid); }

/* ── Bottom HUD ─────────────────────────────────────────────────────── */
.cam-hud {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  background: linear-gradient(to top, rgba(0,0,0,.92) 70%, transparent);
  padding: 12px 16px 20px;
}

/* PM & AQI live values */
.live-values {
  display: flex;
  justify-content: space-around;
  margin-bottom: 10px;
}
.live-val-card {
  text-align: center;
}
.live-val-label {
  font-size: .62rem;
  color: var(--text-lo);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  font-family: monospace;
}
.live-val-number {
  font-size: 1.7rem;
  font-weight: 800;
  font-family: 'Rajdhani', monospace;
  line-height: 1.1;
  color: var(--text-hi);
}
.live-val-unit {
  font-size: .6rem;
  color: var(--text-lo);
}
#aqi-live {
  font-size: 2.4rem;
  color: #00e400;
  transition: color .4s;
}
#aqi-cat-live {
  font-size: .68rem;
  font-family: monospace;
  transition: color .4s;
}

/* Gauge (SVG) */
.gauge-wrap {
  display: flex;
  justify-content: center;
  margin: -4px 0 4px;
}
#gauge-svg { overflow: visible; }
.gauge-track { fill: none; stroke: #1a2840; stroke-width: 10; stroke-linecap: round; }
#gauge-arc   { fill: none; stroke-width: 10; stroke-linecap: round; transition: stroke .4s; filter: drop-shadow(0 0 6px currentColor); }
#gauge-value { font-size: 22px; font-weight: 800; text-anchor: middle; dominant-baseline: middle; font-family: 'Inter', sans-serif; transition: fill .4s; }
#gauge-cat   { font-size: 7px; text-anchor: middle; font-family: 'Inter', sans-serif; transition: fill .4s; }

/* Bars */
.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}
.bar-label { font-size: .65rem; color: var(--text-lo); width: 80px; font-family: monospace; }
.bar-track { flex: 1; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.bar-fill  { height: 100%; border-radius: 2px; transition: width .3s, background .3s; }
.bar-val   { font-size: .65rem; color: var(--text-mid); width: 30px; text-align: right; }

/* Controls row */
.cam-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 10px;
}

/* ── Results screen ─────────────────────────────────────────────────── */
#screen-results {
  padding: 0;
  min-height: 100dvh;
  overflow-y: auto;
}
#res-banner {
  padding: 28px 20px 20px;
  text-align: center;
  transition: background .4s;
}
.res-aqi-display {
  font-size: 5rem;
  font-weight: 900;
  line-height: 1;
  transition: color .4s;
}
.res-aqi-icon { font-size: 2rem; margin-bottom: 6px; }
.res-cat-label {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 1px;
  margin-top: 4px;
}
.res-meta {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 12px;
  font-size: .73rem;
  color: var(--text-mid);
  font-family: monospace;
}

#results-card {
  margin: 16px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: border-color .4s;
}

.pm-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
}
.pm-cell {
  background: var(--bg-card);
  padding: 14px 18px;
  text-align: center;
}
.pm-cell-label { font-size: .65rem; color: var(--text-lo); text-transform: uppercase; letter-spacing: 1px; font-family: monospace; margin-bottom: 4px; }
.pm-cell-value { font-size: 1.3rem; font-weight: 700; }
.pm-cell-aqi   { font-size: .68rem; color: var(--text-mid); margin-top: 2px; }

.section-card {
  margin: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px 18px;
}
.section-card h3 {
  font-size: .72rem;
  color: var(--text-lo);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-family: monospace;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.section-card p {
  font-size: .88rem;
  color: var(--text-mid);
  line-height: 1.6;
}
.sensitive-note {
  margin-top: 8px;
  padding: 8px 12px;
  background: rgba(255,170,0,.06);
  border-left: 3px solid var(--amber);
  border-radius: 4px;
  font-size: .82rem;
  color: #fcd34d;
}
.rec-list {
  list-style: none;
  margin-top: 6px;
}
.rec-list li {
  padding: 7px 0 7px 20px;
  position: relative;
  font-size: .86rem;
  color: var(--text-mid);
  border-bottom: 1px solid var(--border);
}
.rec-list li:last-child { border-bottom: none; }
.rec-list li::before {
  content: '›';
  position: absolute;
  left: 4px;
  color: var(--accent);
}

.results-actions {
  padding: 16px 16px 32px;
  display: flex;
  gap: 10px;
  justify-content: center;
}
.conf-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: .72rem;
  color: var(--text-mid);
  font-family: monospace;
}
.disclaimer-inline {
  padding: 0 16px 12px;
  font-size: .7rem;
  color: var(--text-lo);
  text-align: center;
  line-height: 1.5;
}

/* ── API screen ─────────────────────────────────────────────────────── */
#screen-api {
  padding: 0;
  min-height: 100dvh;
  overflow-y: auto;
}
.api-header {
  padding: 16px 16px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.api-header h2 { flex: 1; font-size: 1.1rem; }

.api-card {
  margin: 14px 16px 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px 18px;
}
.api-card h3 {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-lo);
  font-family: monospace;
  margin-bottom: 10px;
}
.api-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.api-field { display: flex; flex-direction: column; flex: 1; gap: 4px; min-width: 140px; }
.api-field label { font-size: .7rem; color: var(--text-mid); }
.api-field input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  color: var(--text-hi);
  font-size: .85rem;
  outline: none;
  transition: border-color .15s;
}
.api-field input:focus { border-color: var(--accent); }
.api-field input::placeholder { color: var(--text-lo); }
.api-hint { font-size: .69rem; color: var(--text-lo); line-height: 1.5; margin-top: 4px; }
.api-hint a { color: var(--accent); }

.status-ok    { color: var(--accent); font-size: .8rem; }
.status-error { color: var(--red);    font-size: .8rem; }

.api-result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}
.api-result-cell {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px;
  text-align: center;
}
.api-result-cell-label { font-size: .62rem; color: var(--text-lo); font-family: monospace; text-transform: uppercase; letter-spacing: 1px; }
.api-result-cell-val   { font-size: 1.1rem; font-weight: 700; margin-top: 3px; }
#api-aqi-val { font-size: 1.6rem; }

.api-station-row {
  display: flex;
  justify-content: space-between;
  font-size: .75rem;
  color: var(--text-mid);
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 4px;
}

/* ── Disclaimer modal ───────────────────────────────────────────────── */
#disclaimer-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,.75);
  display: flex;
  align-items: flex-end;
  backdrop-filter: blur(3px);
}
.modal-sheet {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  border-radius: var(--r) var(--r) 0 0;
  padding: 24px 20px 32px;
  width: 100%;
  max-height: 70dvh;
  overflow-y: auto;
}
.modal-sheet h2 { margin-bottom: 14px; }
.modal-sheet p  { margin-bottom: 12px; }
.modal-close-btn {
  margin-top: 16px;
  width: 100%;
}

/* ── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-panel);
  border: 1px solid var(--border-hi);
  border-radius: 20px;
  padding: 8px 18px;
  font-size: .82rem;
  color: var(--text-hi);
  z-index: 200;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.toast-show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-warn { border-color: rgba(255,170,0,.4); color: var(--amber); }
.toast-error { border-color: rgba(255,68,68,.4); color: var(--red); }

/* ── Scrollbar ──────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 2px; }
