:root {
  --bg: #08111f;
  --bg-2: #0d1728;
  --card: rgba(10, 18, 32, 0.78);
  --card-strong: rgba(14, 25, 42, 0.9);
  --line: rgba(255, 255, 255, 0.08);
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #7c3aed;
  --primary-2: #4f46e5;
  --success: #10b981;
  --danger: #ef4444;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  --bg: #eef3fb;
  --bg-2: #dde7f5;
  --card: rgba(255, 255, 255, 0.88);
  --card-strong: rgba(255, 255, 255, 0.94);
  --line: rgba(15, 23, 42, 0.08);
  --text: #0f172a;
  --muted: #475569;
  --primary: #7c3aed;
  --primary-2: #4f46e5;
  --success: #059669;
  --danger: #dc2626;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(124, 58, 237, 0.24), transparent 32%),
    radial-gradient(circle at top right, rgba(16, 185, 129, 0.16), transparent 28%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--text);
}

body {
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  transition:
    transform 0.18s ease,
    opacity 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

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

.safe-hidden-input {
  display: none;
}

.safe-shell {
  width: 100%;
  min-height: 100vh;
}

.safe-frame {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  padding: 18px 14px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.safe-top-card,
.safe-hero-card,
.safe-info-card,
.safe-empty-card,
.picker-sheet,
.scanner-sheet,
.scanner-stage-card {
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.safe-top-card {
  border-radius: 30px;
  padding: 18px;
}

.safe-top-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  gap: 12px;
  align-items: start;
}

.icon-btn,
.primary-btn,
.secondary-btn,
.ghost-btn {
  border-radius: 16px;
}

.icon-btn {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.06);
  color: var(--text);
  font-size: 20px;
}

.primary-btn,
.secondary-btn,
.ghost-btn {
  min-height: 50px;
  border: 1px solid var(--line);
  padding: 0 16px;
  font-weight: 800;
}

.primary-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  border: 0;
  box-shadow: 0 14px 30px rgba(79, 70, 229, 0.28);
}

.secondary-btn {
  background: rgba(255,255,255,.06);
  color: var(--text);
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.safe-title-wrap h1 {
  margin: 4px 0 8px;
  font-size: 34px;
  line-height: 1.02;
  letter-spacing: -0.04em;
}

.safe-subtitle {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.label-mini {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
}

.safe-hero-card {
  border-radius: 30px;
  padding: 22px 18px;
}

.safe-hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.safe-hero-badge,
.safe-status-chip,
.scanner-mode-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.safe-hero-badge {
  background: rgba(124, 58, 237, 0.18);
  color: #ddd6fe;
}

.safe-status-chip,
.scanner-mode-chip {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.05);
  color: var(--text);
}

.safe-hero-card h2 {
  margin: 16px 0 10px;
  font-size: 28px;
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.safe-hero-card p,
.safe-info-card p,
.safe-empty-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.safe-storage-card {
  margin-top: 16px;
  padding: 14px;
  border-radius: 22px;
  background: var(--card-strong);
  border: 1px solid var(--line);
}

.safe-storage-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.safe-storage-title {
  margin-top: 4px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.safe-storage-value {
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
}

.safe-storage-bar {
  margin-top: 14px;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(255,255,255,.07);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.04);
}

.safe-storage-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(135deg, var(--success), #34d399);
  box-shadow: 0 0 24px rgba(16,185,129,.28);
}

.safe-storage-meta {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.safe-quick-actions {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.safe-quick-actions-single {
  grid-template-columns: 1fr;
}

.safe-main-add-btn {
  min-height: 56px;
  font-size: 18px;
  border-radius: 20px;
}

.safe-grid {
  display: grid;
  gap: 12px;
}

.safe-info-card {
  border-radius: 24px;
  padding: 18px;
  background: var(--card-strong);
}

.safe-info-card h3 {
  margin: 8px 0;
  font-size: 21px;
  letter-spacing: -0.03em;
}

.safe-empty-card {
  border-radius: 28px;
  padding: 24px 18px;
  text-align: center;
}

.safe-empty-icon {
  width: 68px;
  height: 68px;
  margin: 0 auto 14px;
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  background:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,.22), transparent 35%),
    linear-gradient(135deg, rgba(124,58,237,.28), rgba(79,70,229,.18));
  border: 1px solid var(--line);
}

.safe-empty-card h3 {
  margin: 0 0 8px;
  font-size: 24px;
  letter-spacing: -0.03em;
}

/* picker */

.picker-sheet-backdrop,
.scanner-sheet-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding:
    max(16px, calc(env(safe-area-inset-top) + 12px))
    16px
    max(16px, calc(env(safe-area-inset-bottom) + 8px));
  background: rgba(3, 8, 18, 0.64);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.picker-sheet-backdrop {
  z-index: 700;
}

.scanner-sheet-backdrop {
  z-index: 600;
}

.picker-sheet-backdrop.active,
.scanner-sheet-backdrop.active {
  display: flex;
}

.picker-sheet,
.scanner-sheet {
  width: min(780px, 100%);
  max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 32px);
  overflow: auto;
  border-radius: 28px;
  padding: 16px;
}

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

.picker-sheet-title,
.scanner-sheet-title {
  margin-top: 4px;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.03em;
}

.scanner-close-btn {
  font-size: 24px;
  line-height: 1;
}

.picker-sheet-actions {
  display: grid;
  gap: 10px;
}

.picker-action-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  color: var(--text);
  text-align: left;
}

.picker-action-primary {
  box-shadow: 0 0 0 1px rgba(124,58,237,.18) inset;
}

.picker-action-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--line);
}

.picker-action-text {
  display: grid;
  gap: 4px;
}

.picker-action-text b {
  font-size: 17px;
  letter-spacing: -0.02em;
}

.picker-action-text small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

/* scanner */

.scanner-stage-card {
  border-radius: 24px;
  padding: 14px;
  background: var(--card-strong);
}

.scanner-stage-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.scanner-status-text {
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
}

.scanner-preview-shell {
  margin-top: 14px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.03);
  min-height: 250px;
  overflow: hidden;
  position: relative;
  padding-bottom: 64px;
}

.scanner-video,
.scanner-preview-image {
  display: block;
  width: 100%;
  height: auto;
  max-height: 56vh;
  object-fit: cover;
  background: #000;
}

.scanner-empty-state {
  min-height: 250px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 18px;
  color: var(--muted);
  line-height: 1.6;
}

.scanner-guide-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.scanner-guide-frame {
  position: absolute;
  left: 8%;
  top: 10%;
  width: 84%;
  height: 74%;
  border-radius: 18px;
  box-shadow:
    0 0 0 9999px rgba(3,8,18,.24),
    inset 0 0 0 2px rgba(255,255,255,.92),
    0 0 0 1px rgba(124,58,237,.28);
}

.scanner-guide-corner {
  position: absolute;
  width: 26px;
  height: 26px;
  border-color: #8b5cf6;
  border-style: solid;
  border-width: 0;
  box-shadow: 0 0 20px rgba(139,92,246,.35);
}

.scanner-guide-corner-tl {
  top: -2px;
  left: -2px;
  border-top-width: 4px;
  border-left-width: 4px;
  border-top-left-radius: 12px;
}

.scanner-guide-corner-tr {
  top: -2px;
  right: -2px;
  border-top-width: 4px;
  border-right-width: 4px;
  border-top-right-radius: 12px;
}

.scanner-guide-corner-bl {
  bottom: -2px;
  left: -2px;
  border-bottom-width: 4px;
  border-left-width: 4px;
  border-bottom-left-radius: 12px;
}

.scanner-guide-corner-br {
  bottom: -2px;
  right: -2px;
  border-bottom-width: 4px;
  border-right-width: 4px;
  border-bottom-right-radius: 12px;
}

.corner-editor-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  z-index: 3;
}

.scanner-hint-badge {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  transform: none;
  min-height: 40px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: rgba(15,23,42,.88);
  border: 1px solid rgba(255,255,255,.12);
  color: #f8fafc;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  white-space: normal;
  text-align: center;
  z-index: 4;
}

.pages-strip {
  margin-top: 14px;
}

.pages-strip-inner {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  align-items: stretch;
}

.page-empty-text {
  color: var(--muted);
  font-size: 14px;
  padding: 10px 4px;
}

.page-thumb-wrap {
  position: relative;
  flex: 0 0 auto;
}

.page-thumb-card,
.page-add-card {
  width: 96px;
  min-width: 96px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  padding: 8px;
  display: grid;
  gap: 8px;
  color: var(--text);
}

.page-thumb-card-active {
  box-shadow: 0 0 0 1px rgba(124,58,237,.34) inset, 0 0 20px rgba(124,58,237,.14);
}

.page-thumb-image {
  width: 100%;
  aspect-ratio: 0.72;
  object-fit: cover;
  border-radius: 12px;
  background: #fff;
}

.page-thumb-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  text-align: center;
}

.page-thumb-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 24px;
  height: 24px;
  min-height: 24px;
  border: 0;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-weight: 900;
  font-size: 14px;
  line-height: 1;
  box-shadow: 0 8px 20px rgba(239,68,68,.35);
  padding: 0;
}

.page-add-card {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.page-add-plus {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.page-add-text {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

.scanner-actions {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.scanner-actions-single {
  grid-template-columns: 1fr;
}

:root[data-theme="light"] .safe-info-card,
:root[data-theme="light"] .safe-storage-card,
:root[data-theme="light"] .picker-sheet,
:root[data-theme="light"] .scanner-stage-card {
  background: rgba(255,255,255,.96);
}

:root[data-theme="light"] .scanner-guide-frame {
  box-shadow:
    0 0 0 9999px rgba(15,23,42,.12),
    inset 0 0 0 2px rgba(15,23,42,.82),
    0 0 0 1px rgba(124,58,237,.18);
}

:root[data-theme="light"] .scanner-hint-badge {
  background: rgba(255,255,255,.96);
  color: #0f172a;
  border-color: rgba(15,23,42,.10);
}

@media (max-width: 520px) {
  .safe-frame {
    padding: 12px 10px 24px;
  }

  .safe-title-wrap h1 {
    font-size: 30px;
  }

  .safe-hero-card h2 {
    font-size: 24px;
  }

  .safe-info-card h3,
  .picker-sheet-title,
  .scanner-sheet-title {
    font-size: 20px;
  }

  .safe-storage-head,
  .safe-storage-meta,
  .scanner-stage-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .picker-sheet-backdrop,
  .scanner-sheet-backdrop {
    padding:
      max(10px, calc(env(safe-area-inset-top) + 10px))
      10px
      max(10px, calc(env(safe-area-inset-bottom) + 8px));
  }

  .picker-sheet,
  .scanner-sheet {
    border-radius: 22px;
    padding: 12px;
    max-height: calc(100vh - 20px);
  }

  .scanner-preview-shell,
  .scanner-empty-state {
    min-height: 210px;
  }

  .scanner-preview-shell {
    padding-bottom: 72px;
  }

  .scanner-actions {
    grid-template-columns: 1fr;
  }

  .page-thumb-card,
  .page-add-card {
    width: 88px;
    min-width: 88px;
  }

  .scanner-hint-badge {
    bottom: 10px;
    font-size: 11px;
    padding: 0 10px;
  }
}
