:root {
  --bg: #0b0f14;
  --card: #151b23;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.18);
  --text: #e6edf3;
  --muted: #9aa7b5;
  --border: #2a333f;
  --danger: #ef4444;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: none;
  border-radius: 16px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.14s ease, opacity 0.14s ease, background 0.14s ease;
}

button:active {
  transform: scale(0.98);
}

.primary {
  background: var(--accent);
  color: #fff;
}

.secondary {
  background: #2a333f;
  color: var(--text);
}

.small-btn {
  padding: 10px 14px;
  font-size: 0.92rem;
}

.small-btn.active {
  background: var(--accent);
  color: #fff;
}

.shutter-btn {
  min-width: 132px;
  padding: 17px 24px;
}

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
  gap: 16px;
  text-align: center;
}

.hidden { display: none !important; }

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.7rem;
}

h2 {
  font-size: 1.3rem;
}

p {
  color: var(--muted);
}

input[type="password"] {
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 1.2rem;
  text-align: center;
  width: 200px;
}

.scanner-shell {
  justify-content: flex-start;
  align-items: stretch;
  gap: 12px;
  padding:
    max(10px, env(safe-area-inset-top))
    12px
    max(12px, calc(12px + env(safe-area-inset-bottom)));
}

.scanner-topbar,
.scanner-workspace,
.scanner-bottombar {
  width: min(100%, 640px);
  margin: 0 auto;
}

.scanner-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  background: #111822;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
}

.toggle-pill input {
  inline-size: 18px;
  block-size: 18px;
  accent-color: var(--accent);
}

.scanner-workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scanner-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #0e141c, #111822);
  overflow: hidden;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

.stage-panel {
  position: absolute;
  inset: 0;
}

.scanner-video,
.scanner-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.scanner-video {
  object-fit: contain;
  background: #05080c;
}

.scanner-overlay {
  pointer-events: none;
}

.editor-wrap,
.preview-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

#editor-image,
#editor-overlay {
  position: absolute;
}

#editor-overlay {
  touch-action: none;
}

.preview-wrap {
  flex-direction: column;
  gap: 10px;
}

.preview-wrap img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 18px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.pdf-note {
  display: grid;
  place-items: center;
  inline-size: 100%;
  block-size: 100%;
  padding: 24px;
  border-radius: 18px;
  border: 1px dashed var(--border);
  background: rgba(11, 15, 20, 0.46);
  line-height: 1.5;
}

.scanner-guide,
.hold-steady {
  position: absolute;
  left: 12px;
  right: 12px;
  border-radius: 16px;
  background: rgba(11, 15, 20, 0.78);
  backdrop-filter: blur(8px);
}

.scanner-guide {
  bottom: 12px;
  padding: 12px 14px;
  font-size: 0.94rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
}

.scanner-guide.error {
  color: #fecaca;
}

#scanner-retry-btn {
  flex: 0 0 auto;
  border-radius: 12px;
  padding: 8px 12px;
}

.hold-steady {
  top: 12px;
  padding: 10px 12px;
  text-align: left;
}

.hold-steady-track {
  margin-top: 8px;
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.hold-steady-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #60a5fa, #3b82f6);
  transition: width 0.08s linear;
}

.thumbs {
  display: flex;
  gap: 8px;
  min-height: 72px;
  overflow-x: auto;
  padding: 2px 2px 4px;
  scrollbar-width: thin;
}

.thumb {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
  border: 2px solid var(--border);
  background: #111822;
  flex: 0 0 auto;
}

.thumb.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-label {
  position: absolute;
  right: 5px;
  bottom: 5px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(11, 15, 20, 0.8);
  color: #fff;
  font-size: 0.72rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.scanner-bottombar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.review-hint {
  min-height: 20px;
  font-size: 0.94rem;
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.controls > button {
  flex: 1 1 120px;
}

.bottom-sheet {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: max(12px, calc(12px + env(safe-area-inset-bottom)));
  padding: 12px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: rgba(21, 27, 35, 0.98);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.38);
  text-align: left;
  z-index: 10;
}

.sheet-grabber {
  width: 46px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  margin: 0 auto 12px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.company-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: min(42vh, 320px);
  overflow-y: auto;
}

.company-btn {
  width: 100%;
  text-align: left;
  background: #111822;
  color: var(--text);
  border: 1px solid var(--border);
}

.result-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(11, 15, 20, 0.72);
  z-index: 12;
}

.result-card {
  width: min(100%, 360px);
  padding: 22px;
  border-radius: 24px;
  background: rgba(21, 27, 35, 0.98);
  border: 1px solid var(--border);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.38);
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.overlay-controls {
  width: 100%;
}

.big { font-size: 3.2rem; }
.error { color: var(--danger); }

@media (max-width: 480px) {
  .screen {
    padding-left: 12px;
    padding-right: 12px;
  }

  h1 {
    font-size: 1.5rem;
  }

  .scanner-topbar {
    align-items: stretch;
  }

  .filter-bar {
    justify-content: center;
  }

  .toggle-pill {
    justify-content: center;
  }

  .controls > button {
    flex-basis: calc(50% - 5px);
  }

  .controls > .shutter-btn,
  #use-btn,
  #continue-btn,
  #again-btn,
  #try-again-btn {
    flex-basis: 100%;
  }
}
