/* ═══════════════════════════════════════════════════════
   PULSAR — DEVICE DIAGNOSTICS
   Light mode · Muted purple accent
   Fonts: Plus Jakarta Sans · JetBrains Mono

   TABLE OF CONTENTS
   ─────────────────
    1. Design Tokens
    2. Reset & Base
    3. Layout
    4. Header & Brand
    5. Label
    6. Panel
    7. Device Info List
    8. Rows
    9. Subtests
   10. Badges & Summary
   11. Buttons
   12. Status Indicators
   13. Progress & Timer
   14. Overlay
   15. Sheet (Bottom Sheet)
   16. Dialog (Fullscreen)
   17. Camera Controls
   18. Touch / Color / Gyro Dialogs
   19. Share Section
   20. Scan Modal
   21. Browser Notice
   22. Utilities & Scrollbar
   23. Keyframes
═══════════════════════════════════════════════════════ */

/* ─── 1. DESIGN TOKENS ───────────────────────────────── */
:root {
  /* Surfaces */
  --bg-void: #f6f6f6;
  --bg-base: #ffffff;
  --bg-surface: #f9fafc;
  --bg-raised: #e9eaee;
  --bg-input: #ffffff;
  --bg-hover: #e2e4ea;

  /* Borders */
  --border-faint: rgba(0, 0, 0, 0.04);
  --border-subtle: rgba(0, 0, 0, 0.07);
  --border-default: rgba(0, 0, 0, 0.12);
  --border-strong: rgba(0, 0, 0, 0.18);

  /* Accent */
  --accent: #8223d2;
  --accent-hover: #a24be6;
  --accent-dim: rgba(130, 35, 210, 0.12);
  --accent-mid: rgba(130, 35, 210, 0.2);
  --accent-fg: #ffffff;

  /* Success */
  --success: #2f9e67;
  --success-dim: rgba(47, 158, 103, 0.12);
  --success-ring: rgba(47, 158, 103, 0.2);

  /* Error */
  --error: #d25c5c;
  --error-dim: rgba(210, 92, 92, 0.12);
  --error-ring: rgba(210, 92, 92, 0.2);

  /* Warning */
  --warn: #c99236;
  --warn-dim: rgba(201, 146, 54, 0.12);
  --warn-ring: rgba(201, 146, 54, 0.22);

  /* Text */
  --text-primary: #1b1c1f;
  --text-secondary: #5a5f6a;
  --text-muted: #9aa0aa;

  /* Typography */
  --font-sans: "Plus Jakarta Sans", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", monospace;

  /* Radii */
  --r-xs: 2px;
  --r-sm: 6px;
  --r-md: 9px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-pill: 9999px;

  /* Spacing */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 20px;
  --s6: 24px;
  --s7: 28px;
  --s8: 32px;
  --s10: 40px;

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-snap: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 110ms;
  --dur-base: 190ms;
  --dur-slow: 300ms;
}

/* ─── 2. RESET & BASE ────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  background: var(--bg-void);
  scroll-behavior: auto;
  overflow-anchor: none;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.2;
  color: var(--text-primary);
  background: var(--bg-void);
  max-width: 960px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  appearance: none;
  -webkit-appearance: none;
}

img {
  display: block;
  max-width: 100%;
}

/* ─── 3. LAYOUT ──────────────────────────────────────── */
.app {
  width: 100%;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s5);
  padding: 0 var(--s5) var(--s6);
}

#device-section,
#tests-section {
  min-width: 0;
}

@media (min-width: 780px) {
  .grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
  }
}

/* ─── 4. HEADER & BRAND ──────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: transparent;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  padding: var(--s4) var(--s5);
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
}

.brand__mark {
  width: 56px;
  min-width: 56px;
  aspect-ratio: 1 / 1;
  border-radius: var(--r-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}

.brand__mark::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 10px,
    rgba(0, 0, 0, 0.05) 10px,
    rgba(0, 0, 0, 0.05) 11px
  );
  z-index: 2;
  pointer-events: none;
}

.brand__ekg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 0 3px rgba(130, 35, 210, 0.35))
    drop-shadow(0 0 8px rgba(130, 35, 210, 0.18));
  opacity: 0.15;
  stroke-dasharray: 140;
  stroke-dashoffset: 140;
  animation: ekgTrace 1.8s linear infinite;
  will-change: stroke-dashoffset, opacity, filter;
}

.brand__text {
  flex: 1;
  min-width: 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand__name {
  font-family: var(--font-sans);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--text-primary);
  line-height: 1;
}

.brand__sub {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.11em;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ─── 5. LABEL ───────────────────────────────────────── */
.label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: var(--s3);
  user-select: none;
}

.label::after {
  content: "";
  flex: 1;
  height: 2px;
  background: var(--border-faint);
}

/* ─── 6. PANEL ───────────────────────────────────────── */
.panel {
  background: var(--bg-base);
  border: 1px solid var(--border-faint);
  border-radius: var(--r-xl);
}

.panel__inner {
  padding: var(--s6) var(--s5);
  animation: sectionIn var(--dur-slow) var(--ease-out) both;
}

.panel__head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-bottom: var(--s4);
}

.panel__head--flush {
  margin-bottom: var(--s3);
}

.panel__head .label {
  flex: 1;
}

/* ─── 7. DEVICE INFO LIST ────────────────────────────── */
#device-info {
  display: flex;
  flex-direction: column;
}

#device-info .row .icon {
  font-size: 18px;
  color: var(--text-muted);
  text-align: center;
  justify-self: center;
}

#device-info .row .label-text {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#device-info .row .value {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-primary);
  text-align: right;
  letter-spacing: 0.01em;
  white-space: nowrap;
  margin-left: auto;
}

/* ─── 8. ROWS ────────────────────────────────────────── */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  padding: 8px var(--s2);
  border-radius: var(--r-sm);
  transition: background var(--dur-fast);
  min-height: 34px;
}

/* Test rows */
#tests {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

#tests .row {
  padding: 8px var(--s4);
  cursor: pointer;
  border: 1px solid var(--border-subtle);
}

#tests .row span {
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

#tests .row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--r-sm);
}

/* Shared element: chevron / re-run icon */
.row__action {
  font-size: 18px;
  color: var(--text-secondary);
  flex-shrink: 0;
  margin-left: auto;
  pointer-events: none;
  align-self: center;
  transition: color var(--dur-fast);
}

/* Result row */
.row--result {
  padding: 8px var(--s4) !important;
}

/* Group row */
.row--group {
  align-items: flex-start !important;
  padding: 8px var(--s4) !important;
  gap: var(--s3) !important;
}

/* Shared inner structure for result and group rows */
.row__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.row--result .row__body {
  gap: 1px;
}

.row__header {
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.row--group .row__header {
  justify-content: space-between;
}

.row__header strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.row--group .row__header > span {
  font-size: 15px;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.row--group .row__header > strong {
  font-size: 14px;
}

.row__header .row__action {
  margin-left: auto;
}

.row__detail {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  display: block;
  line-height: 1.5;
}

/* ─── 9. SUBTESTS ────────────────────────────────────── */
.subtests {
  --branch: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-left: var(--branch);
  margin-left: 6px;
  position: relative;
}

/* .subtests::before {
  content: "";
  position: absolute;
  left: 0;
  bottom: 100%;
  height: calc(var(--s2) + 1px);
  width: 2px;
  background: #f0efef;
} */

.subtest {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 2px 0;
  position: relative;
}

.subtest::before {
  content: "";
  position: absolute;
  left: calc(-1 * var(--branch));
  top: -1px;
  bottom: -1px;
  width: 2px;
  background: #f0efef;
}

.subtest:last-child::before {
  bottom: auto;
  height: 10px;
}

.subtest__header {
  display: flex;
  align-items: center;
  gap: var(--s2);
  position: relative;
}

.subtest__header::before {
  content: "";
  position: absolute;
  left: calc(-1 * var(--branch));
  width: calc(var(--branch) - 3px);
  top: 50%;
  transform: translateY(-50%);
  height: 2px;
  background: #f0efef;
}

.subtest > span {
  font-size: 12px;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.subtest > div > strong {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  display: block;
}

/* Smaller status icons inside subtests */
.subtest .status,
.subtest__header .status {
  font-size: 14px;
  width: 11px;
  height: 11px;
}

/* ─── 10. BADGES & SUMMARY ───────────────────────────── */
.badge {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge i {
  font-size: 15px;
  font-weight: 400;
}

.badge--pass {
  background: var(--success-dim);
  color: var(--success);
  border: 1px solid var(--success-ring);
}

.badge--warn {
  background: var(--warn-dim);
  color: var(--warn);
  border: 1px solid var(--warn-ring);
}

.badge--fail {
  background: var(--error-dim);
  color: var(--error);
  border: 1px solid var(--error-ring);
}

.summary {
  display: flex;
  gap: var(--s2);
  flex-wrap: wrap;
  align-items: center;
}

.summary--inline {
  margin-bottom: var(--s3);
  animation: sectionIn var(--dur-base) var(--ease-out) both;
}

/* Count badge next to section label */
.count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

/* ─── 11. BUTTONS ────────────────────────────────────── */

/* Shared inner elements */
.btn__spinner {
  display: none;
  width: 15px;
  height: 15px;
  border: 1.5px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent-fg);
  border-radius: var(--r-pill);
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}

.btn__icon {
  font-size: 16px;
  flex-shrink: 0;
}

.btn__label {
  flex: 1;
  text-align: center;
  line-height: 1;
}

/* Busy state */
.btn--busy .btn__spinner {
  display: block;
}
.btn--busy .btn__icon {
  display: none;
}

/* Primary */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  padding: 0 var(--s5);
  width: 50%;
  height: 52px;
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--accent-fg);
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition:
    background var(--dur-fast),
    transform var(--dur-fast) var(--ease-snap),
    opacity var(--dur-fast);
}

.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-primary:active {
  transform: scale(0.98);
  opacity: 0.92;
}
.btn-primary:disabled {
  background: var(--bg-raised);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  pointer-events: none;
}

/* Small modifier — used for the header run button */
.btn--sm {
  height: 40px;
  padding: 0 var(--s4);
  font-size: 12px;
  border-radius: var(--r-sm);
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: auto;
}

/* Secondary */
.btn-secondary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: 46px;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  margin-top: var(--s5);
  transition:
    background var(--dur-fast),
    border-color var(--dur-fast);
}

.btn-secondary:active {
  background: var(--bg-surface);
}
.btn-secondary i {
  font-size: 14px;
}

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
}

.btn-ghost:hover {
  background: var(--bg-surface);
  border-color: var(--border-strong);
}

.btn-ghost .btn__spinner {
  border-color: var(--border-default);
  border-top-color: var(--text-secondary);
}

/* Trigger */
.btn-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: 48px;
  border-radius: var(--r-md);
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  transition:
    background var(--dur-fast),
    border-color var(--dur-fast);
}

.btn-trigger:active {
  background: var(--bg-surface);
}
.btn-trigger i {
  font-size: 16px;
}

/* Result (pass / fail confirmation) */
.btn-result {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: 50px;
  border-radius: var(--r-md);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition:
    transform var(--dur-fast) var(--ease-snap),
    opacity var(--dur-fast);
}

.btn-result:active {
  transform: scale(0.97);
}
.btn-result i {
  font-size: 16px;
}

.btn-result--pass {
  background: var(--success-dim);
  color: var(--success);
  border: 1px solid var(--success-ring);
}

.btn-result--fail {
  background: var(--error-dim);
  color: var(--error);
  border: 1px solid var(--error-ring);
}

/* Copy button (scan modal) */
.btn-copy {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--r-sm);
  background: var(--accent-dim);
  border: 1px solid var(--accent-mid);
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 2px 10px rgba(130, 35, 210, 0.12);
  cursor: pointer;
  transition:
    background var(--dur-fast),
    border-color var(--dur-fast),
    color var(--dur-fast),
    transform var(--dur-fast);
}

.btn-copy:hover {
  background: var(--accent-mid);
}
.btn-copy:active {
  transform: scale(0.96);
}
.btn-copy i {
  font-size: 13px;
}

/* ─── 12. STATUS INDICATORS ──────────────────────────── */
.status {
  font-size: 18px;
  flex-shrink: 0;
  align-self: center;
  line-height: 1;
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition:
    color var(--dur-base),
    background var(--dur-base);
}

.status--pass {
  color: var(--success);
  background: var(--success-dim);
}
.status--fail {
  color: var(--error);
  background: var(--error-dim);
}
.status--partial {
  color: var(--warn);
  background: var(--warn-dim);
}
.status--pending {
  color: var(--border-default);
  background: transparent;
}

.status--recording {
  color: var(--error);
  background: var(--error-dim);
  animation: statusBlink 1.1s ease-in-out infinite;
}

/* ─── 13. PROGRESS & TIMER ───────────────────────────── */
.progress {
  height: 1px;
  background: var(--border-faint);
  border-radius: var(--r-pill);
  margin-bottom: var(--s5);
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: var(--r-pill);
  transition: width 0.4s var(--ease-out);
}

#timer-bar-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 10000;
  pointer-events: none;
}

#timer-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.1s linear;
}

/* ─── 14. OVERLAY ────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(9, 9, 9, 0.72);
  z-index: 900;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.overlay::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 96px;
  height: 96px;
  border: 10px solid var(--border-default);
  border-top-color: var(--accent);
  border-radius: var(--r-pill);
  animation: overlaySpin 0.7s linear infinite;
}

/* ─── 15. SHEET (BOTTOM SHEET) ───────────────────────── */
.sheet {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  z-index: 1000;
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-bottom: none;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: var(--s5);
  padding-bottom: calc(var(--s8) + env(safe-area-inset-bottom, 0px));
  flex-direction: column;
  gap: var(--s4);
}

.sheet[style*="display: flex"],
.sheet[style*="display:flex"] {
  display: flex !important;
  animation: sheetUp var(--dur-slow) var(--ease-out) both;
}

.sheet__handle {
  width: 28px;
  height: 3px;
  background: var(--border-default);
  border-radius: var(--r-pill);
  margin: 0 auto var(--s1);
  flex-shrink: 0;
}

.sheet__head {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding-bottom: var(--s1);
}

.sheet__icon {
  font-size: 18px;
  color: var(--accent);
  flex-shrink: 0;
  margin-top: 1px;
  line-height: 1;
}

.sheet__title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 4px;
}

.sheet__desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.sheet__actions {
  display: flex;
  gap: var(--s3);
  margin-top: var(--s2);
}

#mic-timer {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  min-height: 16px;
  letter-spacing: 0.06em;
}

#waveform {
  border-radius: var(--r-sm);
  background: transparent !important;
  width: 100%;
}

/* ─── 16. DIALOG (FULLSCREEN) ────────────────────────── */
.dialog {
  display: none;
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 950;
  width: 100%;
  height: 100%;
}

.dialog__hint {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  line-height: 1.7;
  text-align: center;
  z-index: 9999;
  pointer-events: none;
  padding: var(--s3) var(--s5);
  border-radius: var(--r-md);
  background: rgba(20, 20, 22, 0.92);
  border: 1px solid var(--border-default);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  max-width: 78vw;
}

/* ─── 17. CAMERA CONTROLS ────────────────────────────── */
#camera-preview,
.photo-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cam-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px 32px;
  padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55) 0%, transparent 100%);
}

.btn-capture {
  width: 68px;
  height: 68px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 24px;
  transition:
    transform var(--dur-fast) var(--ease-snap),
    background var(--dur-fast);
}

.btn-capture:active {
  transform: scale(0.91);
  background: rgba(255, 255, 255, 0.2);
}

.btn-action {
  width: 52px;
  height: 52px;
  border-radius: var(--r-pill);
  background: rgba(14, 14, 15, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: white;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform var(--dur-fast) var(--ease-snap);
}

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

.btn-action--pass {
  background: rgba(58, 170, 114, 0.18);
  border-color: rgba(58, 170, 114, 0.32);
  color: var(--success);
}

.btn-action--fail {
  background: rgba(204, 95, 95, 0.18);
  border-color: rgba(204, 95, 95, 0.3);
  color: var(--error);
}

.preview-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 40px 32px;
  padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55) 0%, transparent 100%);
  transition: opacity var(--dur-slow) var(--ease-out);
}

.btn-group {
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.hint {
  text-align: center;
  color: rgba(255, 255, 255, 0.3);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.07em;
  margin-top: var(--s4);
}

/* Visibility toggles for camera / color overlays */
.btn-group--hidden,
.preview-bar--hidden,
.hint--hidden {
  opacity: 0;
  pointer-events: none;
}

/* ─── 18. TOUCH / COLOR / GYRO DIALOGS ───────────────── */
.touch-grid {
  width: 100%;
  height: 100%;
  touch-action: none;
  background: var(--bg-void);
  position: relative;
}

#gyro-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.btn-touch-clear {
  position: fixed;
  bottom: calc(var(--s5) + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  padding: 10px var(--s6);
  background: var(--error-dim);
  color: var(--error);
  border: 1px solid var(--error-ring);
  border-radius: var(--r-pill);
  font-size: 12px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  z-index: 9999;
}

#color-confirm-buttons {
  display: flex;
  justify-content: space-around;
  align-items: center;
}

/* ─── 19. SHARE SECTION ──────────────────────────────── */
.share-section {
  grid-column: 1 / -1;
}

.share__hint {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.55;
  margin-bottom: var(--s4);
}

/* Tabs */
.share__tabs {
  display: flex;
  gap: var(--s2);
  margin-bottom: var(--s5);
}

.share__tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px var(--s3);
  border-radius: var(--r-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition:
    background var(--dur-fast),
    border-color var(--dur-fast),
    color var(--dur-fast);
}

.share__tab i {
  font-size: 14px;
  line-height: 1;
}

.share__tab:hover {
  background: var(--bg-hover);
  border-color: var(--border-default);
}

.share__tab--active {
  background: var(--accent-dim);
  border-color: var(--accent-mid);
  color: var(--accent);
}

/* Stage */
.share__stage {
  display: flex;
  justify-content: center;
  min-height: 260px;
  margin-bottom: var(--s4);
  align-items: center;
}

.share__pane {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: var(--s3);
  width: 100%;
}

.share__pane--active {
  display: flex;
}

/* QR frame */
.share__qr {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: var(--r-lg);
  padding: 12px;
  box-shadow:
    0 0 0 1px var(--border-subtle),
    0 4px 24px rgba(0, 0, 0, 0.07);
}

#share-qr-target img,
#share-qr-target canvas {
  display: block;
  border-radius: var(--r-sm);
}

/* Code 128 frame */
.share__barcode {
  position: relative;
  background: #fff;
  border-radius: var(--r-lg);
  padding: 12px;
  box-shadow:
    0 0 0 1px var(--border-subtle),
    0 4px 24px rgba(0, 0, 0, 0.07);
  max-width: 100%;
}

.share__barcode-scroll {
  overflow-x: auto;
  max-width: min(80vw, 540px);
}

.share__barcode-scroll svg {
  display: block;
  height: auto;
  max-width: none;
}

.share__caption {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.share__loading {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s4) var(--s5);
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.share__spinner {
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--border-default);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}

.share__error {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 13px;
  color: var(--error);
  padding: var(--s4);
}

.share__error i {
  font-size: 16px;
}

/* Payload details */
.share__payload {
  border-top: 1px solid var(--border-faint);
  padding-top: var(--s3);
  margin-top: var(--s2);
}

.share__payload-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.share__payload-toggle::-webkit-details-marker {
  display: none;
}
.share__payload-toggle i {
  font-size: 13px;
}

.share__chevron {
  margin-left: auto;
  transition: transform var(--dur-fast);
}

.share__payload[open] .share__chevron {
  transform: rotate(180deg);
}

.share__payload-body {
  margin-top: var(--s3);
  padding: var(--s2) var(--s3);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
}

#share-payload-code {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  word-break: break-all;
  line-height: 1.65;
  display: block;
  user-select: all;
}

/* ─── 20. SCAN MODAL ─────────────────────────────────── */
.scan-modal {
  position: fixed;
  inset: 0;
  z-index: 9990;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s5);
  pointer-events: none;
}

.scan-modal--open {
  pointer-events: auto;
}

.scan-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(9, 9, 9, 0.65);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  opacity: 0;
  transition: opacity 0.3s var(--ease-out);
}

.scan-modal--open .scan-modal__backdrop {
  opacity: 1;
}

.scan-modal__card {
  position: relative;
  width: 100%;
  max-width: 540px;
  max-height: calc(100dvh - (var(--s5) * 2));
  overflow-y: auto;
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-xl);
  padding: var(--s5);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  overscroll-behavior: contain;
  transform: translateY(18px);
  opacity: 0;
  transition:
    transform 0.38s var(--ease-out),
    opacity 0.38s var(--ease-out);
}

.scan-modal--open .scan-modal__card {
  transform: translateY(0);
  opacity: 1;
}

.scan-modal__close {
  position: absolute;
  top: var(--s4);
  right: var(--s4);
  width: 32px;
  height: 32px;
  border-radius: var(--r-pill);
  background: var(--bg-hover);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition:
    background var(--dur-fast),
    transform var(--dur-fast);
}

.scan-modal__close:hover {
  background: var(--bg-raised);
}
.scan-modal__close:active {
  transform: scale(0.92);
}

.scan-modal__head {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding-right: 40px;
}

.scan-modal__icon {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  background: var(--accent-dim);
  border: 1px solid var(--accent-mid);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--accent);
  flex-shrink: 0;
}

.scan-modal__meta {
  flex: 1;
  min-width: 0;
}

.scan-modal__title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 4px;
}

.scan-modal__time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.scan-modal__summary {
  display: flex;
  gap: var(--s2);
  flex-wrap: wrap;
}

/* Output panel */
.scan-modal__output {
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
}

.scan-modal__output-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s3);
  border-bottom: 1px solid var(--border-faint);
  background: var(--bg-surface);
  border-radius: var(--r-md) var(--r-md) 0 0;
}

.scan-modal__output-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.scan-modal__output-label i {
  font-size: 13px;
}

.scan-modal__text {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.75;
  padding: var(--s3);
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: all;
}

/* ─── 21. BROWSER NOTICE ─────────────────────────────── */
.notice {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(18px);
  width: min(92vw, 560px);
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: var(--s4) var(--s5);
  border-radius: var(--r-xl);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border-subtle);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.12);
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity var(--dur-base) var(--ease-out),
    transform var(--dur-base) var(--ease-out);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.notice--open {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.notice__icon {
  width: 34px;
  height: 34px;
  border-radius: var(--r-pill);
  display: flex;
  place-items: center;
  flex-shrink: 0;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 40px;
  justify-content: center;
}

.notice__body {
  flex: 1;
  min-width: 0;
}

.notice__title {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 4px;
}

.notice__text {
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-secondary);
  text-align: justify;
}

.notice__close {
  position: absolute;
  top: var(--s2);
  right: var(--s2);
  width: 24px;
  height: 24px;
  border-radius: var(--r-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition:
    background var(--dur-fast),
    transform var(--dur-fast);
}

.notice__close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

@media (max-width: 480px) {
  .notice {
    width: calc(100vw - 20px);
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    padding: var(--s3);
  }
  .notice__text {
    font-size: 12px;
  }
}

/* ─── 22. UTILITIES & SCROLLBAR ──────────────────────── */
.hidden {
  display: none !important;
}
.u-muted {
  color: var(--text-muted) !important;
}

::-webkit-scrollbar {
  width: 3px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: var(--r-pill);
}

/* ─── 23. KEYFRAMES ──────────────────────────────────── */
@keyframes sectionIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes statusBlink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.28;
  }
}

@keyframes ekgTrace {
  0% {
    opacity: 0;
    stroke-dashoffset: 140;
    filter: drop-shadow(0 0 0 rgba(130, 35, 210, 0))
      drop-shadow(0 0 0 rgba(130, 35, 210, 0));
  }
  10% {
    opacity: 0.25;
  }
  18% {
    opacity: 1;
    stroke-dashoffset: 70;
    filter: drop-shadow(0 0 4px rgba(130, 35, 210, 0.45))
      drop-shadow(0 0 10px rgba(130, 35, 210, 0.22));
  }
  32% {
    opacity: 1;
    stroke-dashoffset: 0;
    filter: drop-shadow(0 0 5px rgba(130, 35, 210, 0.5))
      drop-shadow(0 0 12px rgba(130, 35, 210, 0.24));
  }
  45% {
    opacity: 0.85;
  }
  58% {
    opacity: 0.12;
    stroke-dashoffset: 0;
    filter: drop-shadow(0 0 0 rgba(130, 35, 210, 0))
      drop-shadow(0 0 0 rgba(130, 35, 210, 0));
  }
  72% {
    opacity: 0;
    stroke-dashoffset: 140;
  }
  100% {
    opacity: 0;
    stroke-dashoffset: 140;
  }
}

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

@keyframes overlaySpin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

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