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

:root {
  --bg: #eef4ee;
  --bg-strong: #e3efe9;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-raised: #f4f8f3;
  --border: rgba(33, 59, 42, 0.09);
  --border-strong: rgba(31, 110, 67, 0.16);

  --text-1: #122018;
  --text-2: #5f6f66;
  --text-3: #7e8b82;

  --green: #1f6e43;
  --green-light: #edf9f1;
  --green-mid: #3a9e62;

  --amber: #b35c00;
  --amber-light: #fff1df;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 24px;

  --shadow-sm: 0 8px 24px rgba(17, 32, 24, 0.06);
  --shadow-md: 0 12px 30px rgba(17, 32, 24, 0.08);
  --shadow-lg: 0 22px 60px rgba(17, 32, 24, 0.12);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-1);
  background:
    radial-gradient(circle at top left, rgba(115, 180, 136, 0.12), transparent 30%),
    linear-gradient(180deg, var(--bg-strong), var(--bg));
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ─── Header ─── */
.header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(249, 249, 248, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-1);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.brand svg { color: var(--green); }

.nav {
  display: flex;
  gap: 2px;
  background: var(--surface-raised);
  padding: 3px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
}

.nav-btn {
  background: none;
  border: none;
  padding: 5px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-btn.active {
  background: var(--surface);
  color: var(--text-1);
  box-shadow: var(--shadow-sm);
}

.nav-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.nav-btn:hover:not(:disabled):not(.active) { color: var(--text-1); }

.header-end { margin-left: auto; }

.local-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--green);
  background: var(--green-light);
  padding: 4px 10px;
  border-radius: 999px;
}

.pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green-mid);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ─── Main & Tabs ─── */
main { max-width: 1080px; margin: 0 auto; padding: 28px 24px; }

.tab { display: none; }
.tab.active { display: block; }

/* ─── Scanner Layout ─── */
.scan-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 820px) {
  .scan-layout { grid-template-columns: 1fr; }
}

/* ─── Panel ─── */
.panel {
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(246,250,247,0.95));
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  backdrop-filter: blur(8px);
}

.panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
}

.step-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--amber-light);
  color: var(--amber);
}

.engine-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--green-light);
  color: var(--green);
}

/* ─── Viewfinder ─── */
.viewfinder {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #0d0d0c;
  border-radius: var(--r-md);
  overflow: hidden;
}

.viewfinder video,
.viewfinder canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

/* Crosshair rings */
.crosshair {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.ch-ring {
  position: absolute;
  border: 1.5px dashed rgba(255,255,255,0.5);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.r1 { width: 70px; height: 70px; left: 28%; top: 33%; }
.r2 { width: 70px; height: 70px; left: 72%; top: 33%; }
.r3 { width: 70px; height: 70px; left: 50%; top: 70%; }

.ch-center {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  transform: translate(-50%, -50%);
}

/* Scan bar */
.scan-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--green-mid);
  box-shadow: 0 0 8px var(--green-mid);
  z-index: 5;
  display: none;
}

.scan-bar.active {
  display: block;
  animation: sweep 1.6s ease-in-out infinite alternate;
}

@keyframes sweep {
  0% { top: 0; }
  100% { top: calc(100% - 2px); }
}

/* Empty state */
.vf-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: rgba(255,255,255,0.35);
  z-index: 3;
}

.vf-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
}

.vf-empty p { font-size: 13px; }

/* ─── Camera Actions ─── */
.cam-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.cam-actions .btn { flex: 1; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn:hover { opacity: 0.85; }

.btn-dark {
  background: var(--text-1);
  color: #fff;
}

.btn-outline {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-1);
}

.btn-outline:hover { background: var(--surface-raised); opacity: 1; }

.btn-green {
  background: var(--green);
  color: #fff;
}

.btn-full { width: 100%; }

/* ─── Samples ─── */
.samples-row {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.samples-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

.samples {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.sample-btn {
  background: linear-gradient(180deg, #fbfdfb, #eff5f0);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  text-align: left;
}

.sample-btn:hover {
  border-color: var(--green-mid);
  box-shadow: 0 0 0 2px var(--green-light);
  transform: translateY(-1px);
}

.sample-btn img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
}

.sample-btn span {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
  padding: 5px 7px;
}

/* ─── Analysis Panel ─── */
.analysis-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding: 48px 24px;
  color: var(--text-3);
}

.idle-glyph svg { opacity: 0.4; }
.analysis-idle p { font-size: 13px; max-width: 200px; line-height: 1.5; }

.analysis-results {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.result-row {}

.result-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin-bottom: 8px;
}

/* Palette */
.palette { display: flex; gap: 6px; }

.swatch {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  border: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
}

/* Roughness */
.roughness-meter {
  display: flex;
  align-items: center;
  gap: 10px;
}

.roughness-bar {
  flex: 1;
  height: 6px;
  background: var(--surface-raised);
  border-radius: 3px;
  overflow: hidden;
}

.roughness-fill {
  height: 100%;
  width: 0;
  background: var(--green-mid);
  border-radius: 3px;
  transition: width 0.6s ease;
}

.roughness-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  min-width: 32px;
  text-align: right;
}

/* Materials */
.material-list { display: flex; flex-wrap: wrap; gap: 6px; }

.mat-tag {
  font-size: 12px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: var(--r-sm);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-2);
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
}

/* Scan status */
.scan-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-2);
}

.scan-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
}

.scan-dot.running {
  background: var(--green-mid);
  animation: pulse 1s infinite;
}

.scan-dot.done { background: var(--green-mid); }

/* ─── Quest Tab ─── */
.quest-layout { max-width: 680px; margin: 0 auto; }

.quest-panel { padding: 28px; }

.quest-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.quest-category {
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.quest-chips { display: flex; gap: 6px; }

.chip-xp, .chip-time {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}

.chip-xp { background: var(--amber-light); color: var(--amber); }
.chip-time { background: var(--surface-raised); color: var(--text-2); border: 1px solid var(--border); }

.quest-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin-bottom: 10px;
  color: var(--text-1);
}

.quest-lore {
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  line-height: 1.6;
  font-style: italic;
}

/* Objectives */
.objectives { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }

.obj-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--surface-raised);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s;
}

.obj-item.done { opacity: 0.55; }
.obj-item:hover { border-color: var(--border-strong); }

.obj-check {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 1.5px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.obj-item.done .obj-check {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-size: 11px;
}

.obj-content h4 { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.obj-content p { font-size: 12px; color: var(--text-2); }

.quest-actions { display: flex; gap: 8px; }
.quest-actions .btn { flex: 1; }

/* ─── Journal Tab ─── */
.journal-layout { max-width: 800px; margin: 0 auto; }

.stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 20px 24px;
  margin-bottom: 24px;
}

.stat { text-align: center; }
.stat-val { display: block; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; color: var(--text-1); }
.stat-key { font-size: 12px; color: var(--text-3); margin-top: 2px; display: block; }
.stat-sep { width: 1px; height: 32px; background: var(--border); }

.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-3);
  margin-bottom: 12px;
}

/* Badges */
.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
  margin-bottom: 28px;
}

.badge-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.badge-card.locked { opacity: 0.35; filter: grayscale(1); }

.badge-em {
  font-size: 24px;
  width: 44px;
  height: 44px;
  background: var(--surface-raised);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.badge-info h4 { font-size: 13px; font-weight: 600; }
.badge-info p { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* History */
.history { display: flex; flex-direction: column; gap: 8px; }

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}

.history-item strong { font-size: 13px; font-weight: 600; display: block; }
.history-item span { font-size: 11px; color: var(--text-3); margin-top: 1px; display: block; }
.history-xp { font-size: 12px; font-weight: 600; background: var(--amber-light); color: var(--amber); padding: 3px 9px; border-radius: 999px; }

.empty-note { font-size: 13px; color: var(--text-3); padding: 32px; text-align: center; }

/* ─── Audio Overlay ─── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 9, 0.6);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.overlay-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 32px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.overlay-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--surface-raised);
  border: none;
  border-radius: var(--r-sm);
  padding: 6px;
  color: var(--text-2);
  cursor: pointer;
  display: flex;
}

.overlay-status {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--green);
  background: var(--green-light);
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 20px;
}

.timer-display {
  font-size: 52px;
  font-weight: 300;
  letter-spacing: -0.03em;
  color: var(--text-1);
  font-variant-numeric: tabular-nums;
  margin-bottom: 16px;
  line-height: 1;
}

.overlay-task {
  font-size: 13px;
  color: var(--text-2);
  min-height: 40px;
  margin-bottom: 24px;
  line-height: 1.5;
  padding: 0 16px;
}

.overlay-btns { display: flex; gap: 8px; }
.overlay-btns .btn { flex: 1; }
