:root {
  --font-main: 'Outfit', 'Hind Siliguri', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* 60% Dominant (Base & Backgrounds) */
  --bg-app: #F5F5F5;
  --bg-card: #FFFFFF;
  --bg-card-subtle: #EDEDED;
  --bg-card-muted: #F8F8F8;
  
  /* 30% Structural (Dark Charcoal / Espresso & Content) */
  --color-dark: #1C110D;
  --text-main: #1C110D;
  --text-muted: #5C524E;
  --text-dim: #8A7E79;
  --border-subtle: rgba(28, 17, 13, 0.08);
  --border-card: rgba(28, 17, 13, 0.12);
  
  /* 10% Accent (Vibrant Utsho Red) */
  --accent-brand: #E82429;
  --accent-brand-hover: #CF171C;
  --accent-brand-light: rgba(232, 36, 41, 0.08);
  --accent-brand-glow: rgba(232, 36, 41, 0.28);

  /* Status Colors */
  --color-success: #15803D;
  --color-success-bg: rgba(21, 128, 61, 0.10);
  --color-wrong: #E82429;
  --color-wrong-bg: rgba(232, 36, 41, 0.10);
  --color-blank: #716661;
  --color-blank-bg: rgba(113, 102, 97, 0.10);
  --color-warning: #D97706;
  
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 4px 20px -2px rgba(28, 17, 13, 0.06), 0 1px 4px 0 rgba(28, 17, 13, 0.04);
  --shadow-lg: 0 12px 36px -4px rgba(28, 17, 13, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-main);
  background: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 14px 12px 36px;
  background-image: 
    radial-gradient(at 0% 0%, rgba(232, 36, 41, 0.05) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(28, 17, 13, 0.04) 0px, transparent 50%);
  background-attachment: fixed;
}

.app-container {
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px 2px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo-wrapper {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.brand-logo-img {
  height: 44px;
  width: auto;
  max-width: 140px;
  object-fit: contain;
  display: block;
}

.brand-badge-fallback {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-brand);
  color: #FFFFFF;
  place-items: center;
  font-size: 22px;
  font-weight: 800;
}

.header-info {
  min-width: 0;
}

.header-info h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--color-dark);
  line-height: 1.15;
  white-space: nowrap;
}

.subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 600;
  line-height: 1.3;
}

.key-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  background: #FFFFFF;
  color: var(--color-dark);
  border: 1px solid var(--border-card);
  box-shadow: 0 2px 6px rgba(28, 17, 13, 0.04);
  white-space: nowrap;
  flex-shrink: 0;
}

.key-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-warning);
}

.key-pill.loaded .dot {
  background: var(--color-success);
  box-shadow: 0 0 8px rgba(21, 128, 61, 0.5);
}

@media (max-width: 540px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 4px 2px 2px;
  }

  .brand-group {
    width: 100%;
    gap: 10px;
  }

  .brand-logo-img {
    height: 40px;
    max-width: 120px;
  }

  .header-info h1 {
    font-size: 20px;
  }

  .subtitle {
    font-size: 11.5px;
  }

  .key-pill {
    align-self: flex-start;
    font-size: 11.5px;
    padding: 5px 11px;
  }
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border-card);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-title-group .icon {
  font-size: 24px;
}

.card-title-group h2 {
  font-size: 17px;
  font-weight: 750;
  color: var(--color-dark);
  line-height: 1.3;
}

.card-sub {
  font-size: 13px;
  color: var(--text-muted);
}

.card-sub code {
  background: var(--bg-card-subtle);
  color: var(--color-dark);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
}

.btn-sm {
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--border-card);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-ghost {
  background: var(--bg-card-muted);
  color: var(--color-dark);
}

.btn-ghost:hover {
  background: var(--bg-card-subtle);
}

/* Key Selector Group */
.key-selector-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
  width: 100%;
}

.key-selector-group .select-wrapper {
  width: 100%;
  position: relative;
}

.key-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-card-muted);
  color: var(--color-dark);
  padding: 11px 36px 11px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-card);
  font-family: inherit;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23E82429%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 10px auto;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.key-select:focus {
  outline: none;
  border-color: var(--accent-brand);
  box-shadow: 0 0 0 3px var(--accent-brand-light);
}

.key-actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.key-action-btn {
  display: flex !important;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  width: 100%;
  text-align: center;
  border-radius: var(--radius-sm);
  background: var(--color-dark);
  color: #FFFFFF;
  border: 1px solid var(--color-dark);
  cursor: pointer;
  transition: all 0.2s;
}

.key-action-btn:hover {
  background: #2D1D17;
}

.key-action-btn:active {
  transform: scale(0.98);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Key Content */
.key-content {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: all 0.3s ease-in-out;
}

.key-content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.key-name-badge {
  font-size: 11px;
  font-weight: 750;
  color: var(--accent-brand);
  background: var(--accent-brand-light);
  padding: 3px 9px;
  border-radius: 6px;
  border: 1px solid rgba(232, 36, 41, 0.2);
}

.key-content.collapsed {
  display: none;
}

.muted {
  font-size: 13px;
  color: var(--text-muted);
}

/* TOUCH TARGET FILE INPUTS */
.touch-target {
  position: relative !important;
  overflow: hidden !important;
  cursor: pointer !important;
  display: flex !important;
}

.touch-target input[type="file"],
.file-upload-row input[type="file"],
.file-btn input[type="file"] {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  opacity: 0 !important;
  cursor: pointer !important;
  z-index: 20 !important;
  font-size: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
}

.file-btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-card-muted);
  color: var(--color-dark);
  font-size: 13px;
  font-weight: 700;
  border: 1px solid var(--border-card);
  transition: background 0.2s;
  white-space: nowrap;
}

.file-btn:hover {
  background: var(--bg-card-subtle);
}

.key-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  gap: 6px;
  margin-top: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}

.key-chip {
  background: var(--bg-card-muted);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.key-chip .q-num {
  color: var(--text-dim);
  font-weight: 700;
  font-size: 11px;
}

.key-chip .q-ans {
  color: var(--accent-brand);
  font-weight: 800;
}

/* Scanner Card */
.guide-box {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 180px;
  margin: 16px 0;
  background: var(--bg-card-muted);
  border-radius: var(--radius-md);
  border: 2px dashed var(--border-card);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.guide-corner {
  position: absolute;
  width: 18px;
  height: 18px;
  border-color: var(--accent-brand);
  border-style: solid;
  pointer-events: none;
}

.guide-corner.top-left { top: 10px; left: 10px; border-width: 3px 0 0 3px; }
.guide-corner.top-right { top: 10px; right: 10px; border-width: 3px 3px 0 0; }
.guide-corner.bottom-left { bottom: 10px; left: 10px; border-width: 0 0 3px 3px; }
.guide-corner.bottom-right { bottom: 10px; right: 10px; border-width: 0 3px 3px 0; }

.guide-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  padding: 12px;
}

.guide-text .camera-icon {
  font-size: 26px;
}

.guide-hint {
  font-size: 11px;
  color: var(--text-dim);
}

/* Live Viewfinder Stream Box */
.live-stream-box {
  position: relative;
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-dark);
  margin: 16px 0;
  aspect-ratio: 4 / 3;
  max-height: 340px;
}

.live-stream-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.live-overlay-guide {
  position: absolute;
  inset: 16px;
  border: 2px solid var(--accent-brand);
  border-radius: var(--radius-sm);
  pointer-events: none;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 8px;
}

.live-guide-label {
  background: rgba(28, 17, 13, 0.75);
  color: #FFFFFF;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
}

.live-controls {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 30;
}

.live-shutter-btn {
  padding: 12px 24px;
  border-radius: 30px;
}

/* Action Buttons */
.scan-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.btn-primary, .btn-secondary {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-brand);
  color: #FFFFFF;
  box-shadow: 0 4px 18px var(--accent-brand-glow);
}

.btn-primary:hover {
  background: var(--accent-brand-hover);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: var(--color-dark);
  color: #FFFFFF;
  border: 1px solid var(--color-dark);
}

.btn-secondary:hover {
  background: #2D1D17;
}

.btn-secondary:active {
  transform: scale(0.98);
}

.btn-content {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 1;
}

.btn-icon {
  font-size: 20px;
}

.btn-label {
  font-size: 15px;
  font-weight: 750;
}

@media (max-width: 480px) {
  .btn-primary, .btn-secondary {
    padding: 13px 10px;
  }
  .btn-label {
    font-size: 13.5px;
    white-space: nowrap;
  }
}

/* Scan Status / Spinner Box */
.scan-status-box {
  margin-top: 14px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--bg-card-muted);
  border: 1px solid var(--border-card);
  display: flex;
  align-items: center;
  gap: 12px;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(232, 36, 41, 0.2);
  border-top-color: var(--accent-brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.status-msg {
  font-size: 14px;
  color: var(--accent-brand);
  font-weight: 700;
}

.status {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  display: none;
}

.status.show {
  display: block;
}

.status.ok {
  background: var(--color-success-bg);
  color: var(--color-success);
  font-weight: 650;
}

.status.err {
  background: var(--color-wrong-bg);
  color: var(--color-wrong);
  font-weight: 650;
}

/* Result Card */
.result-card {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-card);
  box-shadow: var(--shadow-card);
  animation: slideUp 0.35s ease-out;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.result-meta-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-success {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--color-success);
  background: var(--color-success-bg);
  border: 1px solid rgba(21, 128, 61, 0.2);
  padding: 4px 10px;
  border-radius: 12px;
}

.badge-key {
  font-size: 11px;
  font-weight: 750;
  color: var(--color-dark);
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-card);
  padding: 3px 9px;
  border-radius: 8px;
}

.badge-inliers {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 650;
}

.score-display {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 16px;
  margin: 10px 0 16px;
  padding: 18px;
  background: var(--bg-card-muted);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-card);
}

.score-main {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.score-number {
  font-size: 66px;
  font-weight: 850;
  line-height: 1;
  color: var(--color-dark);
}

.score-total {
  font-size: 22px;
  color: var(--text-dim);
  font-weight: 700;
}

.score-percent {
  font-size: 24px;
  font-weight: 800;
  color: var(--color-success);
  background: var(--color-success-bg);
  border: 1px solid rgba(21, 128, 61, 0.2);
  padding: 4px 12px;
  border-radius: 12px;
}

/* Stats Row */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}

.stat-card {
  padding: 14px 8px;
  border-radius: var(--radius-md);
  text-align: center;
  background: var(--bg-card-muted);
  border: 1px solid var(--border-card);
}

.stat-correct {
  background: var(--color-success-bg);
  border-color: rgba(21, 128, 61, 0.25);
}

.stat-wrong {
  background: var(--color-wrong-bg);
  border-color: rgba(232, 36, 41, 0.25);
}

.stat-blank {
  background: var(--color-blank-bg);
  border-color: rgba(113, 102, 97, 0.25);
}

.stat-num {
  font-size: 24px;
  font-weight: 850;
  line-height: 1.2;
}

.stat-correct .stat-num { color: var(--color-success); }
.stat-wrong .stat-num { color: var(--color-wrong); }
.stat-blank .stat-num { color: var(--color-blank); }

.stat-lbl {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 700;
}

.result-action-row {
  margin-bottom: 16px;
}

.btn-next {
  width: 100%;
  font-size: 16px;
  padding: 16px;
}

/* Tabs */
.tab-controls {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-card);
  padding-bottom: 10px;
  margin-bottom: 14px;
}

.tab-btn {
  background: var(--bg-card-muted);
  border: 1px solid var(--border-card);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn:hover {
  background: var(--bg-card-subtle);
  color: var(--color-dark);
}

.tab-btn.active {
  color: #FFFFFF;
  background: var(--color-dark);
  border-color: var(--color-dark);
}

/* Breakdown Grid */
.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
}

.breakdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-card-muted);
  border: 1px solid var(--border-card);
  font-size: 13px;
}

.breakdown-item.status-correct {
  border-color: rgba(21, 128, 61, 0.35);
  background: rgba(21, 128, 61, 0.04);
}

.breakdown-item.status-wrong {
  border-color: rgba(232, 36, 41, 0.35);
  background: rgba(232, 36, 41, 0.04);
}

.breakdown-item.status-blank {
  border-color: var(--border-card);
  background: var(--bg-card-muted);
}

.q-badge {
  font-weight: 750;
  color: var(--text-dim);
  font-size: 12px;
}

.q-vals {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 750;
}

.val-detected {
  font-size: 14px;
}

.status-correct .val-detected { color: var(--color-success); font-weight: 800; }
.status-wrong .val-detected { color: var(--color-wrong); font-weight: 800; }
.status-blank .val-detected { color: var(--color-blank); font-weight: 800; }

.val-correct-hint {
  font-size: 11px;
  color: var(--color-success);
  background: var(--color-success-bg);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid rgba(21, 128, 61, 0.2);
  font-weight: 700;
}

.q-status-icon {
  font-size: 13px;
  font-weight: 850;
}

.status-correct .q-status-icon { color: var(--color-success); }
.status-wrong .q-status-icon { color: var(--color-wrong); }
.status-blank .q-status-icon { color: var(--text-dim); }

/* Visual Preview */
.preview-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.preview-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 650;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot-green { background: var(--color-success); }
.dot-red { background: var(--color-wrong); }
.dot-yellow { background: var(--color-warning); }

.preview-img-wrapper {
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-card);
  background: #000000;
}

.preview-img-wrapper img {
  width: 100%;
  height: auto;
  display: block;
}

/* Footer */
.app-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 8px 0;
  font-weight: 600;
}

.hidden {
  display: none !important;
}
