:root {
  color-scheme: dark;
  --bg: #000000;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-strong: #101716;
  --surface-elevated: rgba(16, 23, 22, 0.94);
  --border: rgba(255, 255, 255, 0.14);
  --border-strong: rgba(255, 255, 255, 0.24);
  --text: #f3f5f8;
  --text-muted: #9ba5b5;
  --accent: #7be8c2;
  --accent-dim: rgba(123, 232, 194, 0.14);
  --accent-border: rgba(123, 232, 194, 0.45);
  --accent-ink: #041912;
  --danger: #ffb2aa;
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.65);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fafcfb;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --surface-elevated: rgba(248, 252, 250, 0.96);
  --border: rgba(27, 38, 44, 0.14);
  --border-strong: rgba(27, 38, 44, 0.24);
  --text: #1b262c;
  --text-muted: #536672;
  --accent: #0d7356;
  --accent-dim: rgba(13, 115, 86, 0.10);
  --accent-border: rgba(13, 115, 86, 0.38);
  --accent-ink: #ffffff;
  --danger: #b42318;
  --shadow-lg: 0 20px 52px rgba(20, 43, 58, 0.16);
}

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

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  transition: background-color 0.28s ease, color 0.28s ease;
}

body {
  display: flex;
  flex-direction: column;
  isolation: isolate;
}

/* TG Timer Ambient Glows */
.ambience {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: -1;
}

.glow {
  position: absolute;
  width: min(46vw, 440px);
  aspect-ratio: 1;
  border-radius: 50%;
  opacity: 0.18;
  will-change: transform, opacity;
}

.glow-mint {
  background: radial-gradient(circle, #51d6aa, transparent 68%);
  top: 8%;
  left: -12%;
  animation: driftMint 20s ease-in-out infinite alternate;
}

.glow-blue {
  background: radial-gradient(circle, #6b82ef, transparent 68%);
  right: -10%;
  bottom: -10%;
  animation: driftBlue 26s ease-in-out infinite alternate;
}

.glow-white {
  width: min(32vw, 360px);
  background: radial-gradient(circle, #7be8c2, transparent 70%);
  top: -16%;
  left: 42%;
  opacity: 0.08;
  animation: driftSoft 28s ease-in-out infinite alternate;
}

[data-theme="light"] .glow-mint { opacity: 0.11; }
[data-theme="light"] .glow-blue { opacity: 0.09; }
[data-theme="light"] .glow-white { opacity: 0.05; }

@keyframes driftMint {
  0% { opacity: 0.10; transform: translate3d(0, 0, 0) scale(0.95); }
  100% { opacity: 0.19; transform: translate3d(5vw, 4vh, 0) scale(1.06); }
}

@keyframes driftBlue {
  0% { opacity: 0.09; transform: translate3d(0, 0, 0) scale(1.04); }
  100% { opacity: 0.18; transform: translate3d(-5vw, -4vh, 0) scale(0.94); }
}

@keyframes driftSoft {
  0% { opacity: 0.04; transform: translate3d(-3vw, 2vh, 0) scale(0.94); }
  100% { opacity: 0.11; transform: translate3d(4vw, 5vh, 0) scale(1.06); }
}

button {
  font: inherit;
  cursor: pointer;
  color: inherit;
  touch-action: manipulation;
}

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Header: Profile pic top-left, TG Scan + icon center-top, Settings top-right */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) clamp(14px, 4vw, 32px) 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

[data-theme="light"] .app-header {
  background: rgba(250, 252, 251, 0.84);
}

.header-left {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-width: 0;
}

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

.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.profile-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px 3px 3px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  transition: transform 0.15s ease, border-color 0.2s ease, background 0.2s ease;
  max-width: 170px;
}

.profile-pill-btn:hover {
  border-color: var(--accent-border);
  transform: translateY(-1px);
}

.profile-pill-btn:active {
  transform: scale(0.96);
}

.profile-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  display: grid;
  place-items: center;
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 700;
  font-size: 13.5px;
  border: 1px solid var(--accent-border);
  flex-shrink: 0;
}

.profile-name-label {
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 440px) {
  .profile-pill-btn {
    padding: 2px;
    border-radius: 50%;
  }
  .profile-name-label {
    display: none;
  }
}

.brand-center-lockup {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 0;
  padding: 4px 8px;
  border-radius: 12px;
}

.brand-center-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  display: block;
}

.brand-center-text {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.5px;
  white-space: nowrap;
}

.brand-center-text span {
  font-weight: 450;
  color: var(--text-muted);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  place-items: center;
  transition: transform 0.16s ease, background 0.18s ease, border-color 0.18s ease;
}

.icon-btn:hover {
  border-color: var(--accent-border);
  background: var(--accent-dim);
}

.icon-btn:active {
  transform: scale(0.92);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.settings-button svg {
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.settings-button:hover svg {
  transform: rotate(35deg);
}

.settings-button.spinning svg {
  animation: gearSpin 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes gearSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Main Workspace */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 20px clamp(14px, 4vw, 28px) 118px;
}

.vault-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  animation: fadeSlideUp 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

.vault-title-group h1 {
  margin: 0;
  font-size: clamp(22px, 4vw, 28px);
  font-weight: 600;
  letter-spacing: -0.7px;
}

.vault-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.privacy-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}

.vault-actions-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-wrap svg {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: min(230px, 60vw);
  min-height: 40px;
  padding: 8px 14px 8px 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  font-weight: 550;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease;
}

.pill-btn:hover {
  border-color: var(--accent-border);
  transform: translateY(-1px);
}

.pill-btn:active {
  transform: scale(0.96);
}

.pill-btn.primary {
  background: linear-gradient(135deg, rgba(123, 232, 194, 0.26), rgba(123, 232, 194, 0.10));
  border-color: var(--accent-border);
  color: #b4fbe2;
}

[data-theme="light"] .pill-btn.primary {
  background: linear-gradient(135deg, #0d7356, #0a5c45);
  border-color: #0a5c45;
  color: #ffffff;
}

.pill-btn.danger {
  color: var(--danger);
  border-color: rgba(255, 178, 170, 0.32);
}

[data-theme="light"] .pill-btn.danger {
  border-color: rgba(180, 35, 24, 0.28);
}

/* Empty State */
.empty-vault {
  margin-top: 22px;
  padding: clamp(28px, 6vw, 48px) 22px;
  border-radius: 26px;
  border: 1px solid var(--border);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.015));
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: fadeSlideUp 0.36s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="light"] .empty-vault {
  background: linear-gradient(145deg, #ffffff, #eff6f3);
}

.scanner-radar {
  width: 84px;
  height: 84px;
  margin: 0 auto 18px;
  border-radius: 22px;
  border: 1px solid var(--accent-border);
  background: var(--accent-dim);
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.scanner-radar::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  height: 2px;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  animation: radarSweep 2.4s ease-in-out infinite;
}

@keyframes radarSweep {
  0% { top: 20%; opacity: 0.4; }
  50% { top: 78%; opacity: 1; }
  100% { top: 20%; opacity: 0.4; }
}

.scanner-radar svg {
  width: 40px;
  height: 40px;
  color: var(--accent);
}

.empty-vault h2 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.4px;
}

.empty-vault p {
  margin: 0 auto 22px;
  max-width: 440px;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text-muted);
}

.feature-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 22px;
}

.feature-chip {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-weight: 550;
}

/* Document Grid */
.docs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.doc-card {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s ease, box-shadow 0.2s ease;
  animation: fadeSlideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.doc-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-border);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.22);
}

.doc-thumb-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
  cursor: pointer;
}

[data-theme="light"] .doc-thumb-wrap {
  background: #edf3f0;
}

.doc-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
}

.doc-page-badge {
  position: absolute;
  bottom: 10px;
  right: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 650;
  background: rgba(0, 0, 0, 0.72);
  color: #7be8c2;
  border: 1px solid rgba(123, 232, 194, 0.4);
  backdrop-filter: blur(8px);
}

.doc-card-body {
  padding: 13px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.doc-card-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.doc-card-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.doc-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.doc-mini-btn {
  flex: 1;
  min-height: 34px;
  padding: 5px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  font-size: 12.5px;
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.doc-mini-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent-border);
}

.doc-mini-btn.del {
  flex: 0 0 34px;
  padding: 0;
  color: var(--danger);
}

/* Bottom Center Camera Dock */
.bottom-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 18;
  pointer-events: none;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: 14px 20px max(18px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 35%, transparent);
}

.camera-fab {
  pointer-events: auto;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 62px;
  padding: 0 26px;
  border-radius: 999px;
  border: 1px solid var(--accent-border);
  background: linear-gradient(135deg, #7be8c2, #36c496);
  color: #031a12;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
  box-shadow: 0 12px 34px rgba(123, 232, 194, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
}

[data-theme="light"] .camera-fab {
  background: linear-gradient(135deg, #0d7356, #13946f);
  color: #ffffff;
  box-shadow: 0 12px 30px rgba(13, 115, 86, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.camera-fab:hover {
  transform: translateY(-3px) scale(1.03);
}

.camera-fab:active {
  transform: scale(0.94);
}

.camera-fab svg {
  width: 24px;
  height: 24px;
}

.camera-fab-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 999px;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: fabPulse 2.8s ease-out infinite;
  pointer-events: none;
}

@keyframes fabPulse {
  0% { transform: scale(0.95); opacity: 0.55; }
  100% { transform: scale(1.18, 1.32); opacity: 0; }
}

/* Camera Scan Overlay Screen */
.camera-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #050707;
  color: #f3f5f8;
  display: flex;
  flex-direction: column;
  animation: cameraSlideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes cameraSlideUp {
  0% { opacity: 0; transform: translateY(28px) scale(0.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.camera-top-bar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.78), rgba(0, 0, 0, 0));
}

.cam-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(15, 20, 19, 0.72);
  color: #f3f5f8;
  font-size: 13.5px;
  font-weight: 550;
  backdrop-filter: blur(12px);
  transition: transform 0.14s ease, border-color 0.16s ease, background 0.16s ease;
}

.cam-pill-btn:active {
  transform: scale(0.94);
}

.cam-pill-btn[data-active="true"] {
  border-color: #7be8c2;
  color: #7be8c2;
  background: rgba(123, 232, 194, 0.16);
}

.flash-control-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.flash-popover {
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(14, 20, 19, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(16px);
  z-index: 25;
  animation: popInDown 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
}

@keyframes popInDown {
  0% { opacity: 0; transform: translate(-50%, -8px) scale(0.94); }
  100% { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

.flash-opt {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 13px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: #cdd4de;
  font-size: 13px;
  font-weight: 550;
}

.flash-opt[aria-checked="true"] {
  background: #7be8c2;
  color: #031a12;
  font-weight: 700;
}

.camera-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: #030404;
}

#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#camera-guide-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.camera-shutter-flash {
  position: absolute;
  inset: 0;
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
  z-index: 10;
}

.camera-shutter-flash.flash-go {
  animation: shutterFlash 0.26s ease-out;
}

@keyframes shutterFlash {
  0% { opacity: 0.72; }
  100% { opacity: 0; }
}

.camera-fallback {
  position: absolute;
  inset: 16px;
  border-radius: 22px;
  border: 1px dashed rgba(123, 232, 194, 0.45);
  background: rgba(12, 18, 17, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 12px;
  z-index: 6;
}

.camera-fallback h3 {
  margin: 0;
  font-size: 19px;
}

.camera-fallback p {
  margin: 0;
  max-width: 340px;
  color: #9ba5b5;
  font-size: 13.5px;
  line-height: 1.5;
}

.camera-mode-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px 4px;
  background: rgba(5, 7, 7, 0.92);
}

.cam-mode-pill {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: #9ba5b5;
  font-size: 13px;
  font-weight: 550;
  transition: all 0.18s ease;
}

.cam-mode-pill[aria-checked="true"] {
  background: rgba(123, 232, 194, 0.16);
  border-color: rgba(123, 232, 194, 0.42);
  color: #7be8c2;
}

.camera-bottom-bar {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 12px clamp(16px, 5vw, 36px) max(20px, env(safe-area-inset-bottom));
  background: rgba(5, 7, 7, 0.96);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.cam-bottom-left {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}

.cam-bottom-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.gallery-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: #f3f5f8;
  font-size: 11.5px;
  font-weight: 550;
}

.gallery-btn:active {
  transform: scale(0.94);
}

.shutter-btn {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: 4px solid #7be8c2;
  background: rgba(123, 232, 194, 0.15);
  padding: 5px;
  display: grid;
  place-items: center;
  transition: transform 0.14s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.shutter-btn-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.12s ease, background 0.15s ease;
}

.shutter-btn:hover .shutter-btn-inner {
  background: #d8fff1;
}

.shutter-btn:active {
  transform: scale(0.9);
}

.shutter-btn:active .shutter-btn-inner {
  transform: scale(0.86);
}

.tray-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tray-btn.bump {
  animation: trayBump 0.36s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes trayBump {
  0% { transform: scale(1); }
  45% { transform: scale(1.16); }
  100% { transform: scale(1); }
}

.tray-thumb {
  width: 48px;
  height: 54px;
  border-radius: 10px;
  object-fit: cover;
  background: #141c1a;
  display: block;
}

.tray-count {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 999px;
  background: #7be8c2;
  color: #031a12;
  font-size: 12px;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
}

.tray-done-label {
  font-size: 12.5px;
  font-weight: 650;
  padding-right: 6px;
  color: #7be8c2;
}

.fly-thumb {
  position: fixed;
  z-index: 60;
  border-radius: 14px;
  object-fit: cover;
  border: 2px solid #7be8c2;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  transition: left 0.44s cubic-bezier(0.22, 1, 0.36, 1),
              top 0.44s cubic-bezier(0.22, 1, 0.36, 1),
              width 0.44s cubic-bezier(0.22, 1, 0.36, 1),
              height 0.44s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.44s ease,
              transform 0.44s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Scan Studio Screen */
.studio-screen {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  animation: fadeSlideUp 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

.studio-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-elevated);
}

.studio-title-input {
  flex: 1;
  min-width: 0;
  max-width: 280px;
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
}

.studio-title-input:focus {
  border-color: var(--accent-border);
  background: var(--surface);
  outline: none;
}

.studio-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 14px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.35);
}

[data-theme="light"] .studio-stage {
  background: #e9f0ed;
}

.studio-canvas-wrap {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  display: grid;
  place-items: center;
  touch-action: none;
}

#studio-canvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.42);
  display: block;
}

#studio-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.loupe-canvas {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 104px;
  height: 104px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 8;
}

.studio-pages-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  overflow-x: auto;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.studio-page-chip {
  position: relative;
  flex-shrink: 0;
  width: 46px;
  height: 58px;
  border-radius: 8px;
  border: 2px solid var(--border);
  overflow: hidden;
  padding: 0;
  background: var(--surface);
}

.studio-page-chip[aria-current="true"] {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.studio-page-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.studio-page-num {
  position: absolute;
  bottom: 2px;
  right: 2px;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.72);
  color: #ffffff;
}

.studio-controls {
  padding: 10px 14px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface-elevated);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.studio-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.studio-tab-btn {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}

.studio-tab-btn[aria-selected="true"] {
  background: var(--accent-dim);
  border-color: var(--accent-border);
  color: var(--accent);
}

.filter-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.filter-pill {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: left;
  min-width: 104px;
}

.filter-pill[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.filter-pill strong {
  display: block;
  font-size: 13px;
}

.filter-pill span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.tune-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.tune-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.tune-item input[type="range"] {
  accent-color: var(--accent);
  width: 100%;
}

.studio-footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
}

/* Dialogs (TG Timer style: Welcome Sign-In, Guest Mode, Theme Onboarding) */
dialog {
  width: min(430px, calc(100% - 24px));
  max-height: min(92vh, calc(100svh - 24px));
  margin: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  overflow: visible;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
}

#welcome-dialog::backdrop,
#guest-warning-dialog::backdrop,
#theme-onboarding-dialog::backdrop {
  background: var(--bg) !important;
  backdrop-filter: none !important;
}

dialog[open] {
  animation: dialogPopIn 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes dialogPopIn {
  0% { opacity: 0; transform: translateY(14px) scale(0.975); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-box {
  position: relative;
  padding: 30px 24px 24px;
  background: #101716f2;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-height: min(92vh, calc(100svh - 24px));
  overflow-y: auto;
}

[data-theme="light"] .auth-box {
  background: #ffffff;
  border-color: rgba(27, 38, 44, 0.16);
}

.auth-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  display: block;
  margin: 0 auto 14px;
}

.auth-box h2 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 600;
}

.auth-desc {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

.corner-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 20px;
  display: grid;
  place-items: center;
}

.tg-auth-pill-group {
  display: flex;
  align-items: center;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(123, 232, 194, 0.24), rgba(123, 232, 194, 0.08));
  border: 1px solid var(--accent-border);
  overflow: hidden;
}

[data-theme="light"] .tg-auth-pill-group {
  background: linear-gradient(135deg, #d7f3e8, #ecf9f4);
}

.tg-signin-pill-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  font-size: 15px;
  font-weight: 600;
}

.tg-signin-pill-btn img {
  width: 22px;
  height: 22px;
  border-radius: 6px;
}

.tg-chevron-btn {
  width: 46px;
  min-height: 48px;
  border: 0;
  border-left: 1px solid var(--accent-border);
  background: transparent;
  display: grid;
  place-items: center;
}

.tg-chevron-btn svg {
  transition: transform 0.22s ease;
}

.tg-chevron-btn[aria-expanded="true"] svg {
  transform: rotate(90deg);
}

.tg-accordion-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.26s ease, opacity 0.22s ease;
  opacity: 0;
}

.tg-accordion-panel.open {
  max-height: 90px;
  opacity: 1;
}

.google-signin-pill-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  margin-top: 8px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid rgba(27, 38, 44, 0.16);
  background: #ffffff;
  color: #1f1f1f;
  font-size: 14.5px;
  font-weight: 600;
}

.google-signin-pill-btn svg {
  width: 19px;
  height: 19px;
}

.auth-divider {
  display: flex;
  align-items: center;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.auth-divider::before, .auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-divider span {
  padding: 0 12px;
}

.auth-remember-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 13.5px;
  color: var(--text-muted);
  cursor: pointer;
}

.auth-remember-label input {
  accent-color: var(--accent);
}

.tg-auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  margin: 14px 0;
}

.tg-auth-tab {
  min-height: 36px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.tg-auth-tab.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.tg-form-group {
  text-align: left;
  margin-bottom: 12px;
}

.tg-form-label {
  display: block;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.tg-form-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.tg-auth-error {
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(255, 178, 170, 0.14);
  border: 1px solid rgba(255, 178, 170, 0.35);
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
  text-align: left;
}

.tg-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.tg-card-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
}

/* Theme Onboarding Cards */
.theme-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 18px 0 14px;
}

@media (max-width: 400px) {
  .theme-cards-grid {
    grid-template-columns: 1fr;
  }
}

.theme-choice-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 8px;
  border-radius: 18px;
  border: 2px solid var(--border);
  background: var(--surface);
  transition: transform 0.16s ease, border-color 0.18s ease, background 0.18s ease;
}

.theme-choice-card:hover {
  transform: translateY(-2px);
}

.theme-choice-card[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.theme-preview-swatch {
  width: 52px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  position: relative;
  overflow: hidden;
}

.swatch-light {
  background: linear-gradient(145deg, #fafcfb, #dfeee7);
}
.swatch-light::after {
  content: "";
  position: absolute;
  bottom: 6px;
  left: 10px;
  right: 10px;
  height: 6px;
  border-radius: 999px;
  background: #0d7356;
}

.swatch-dark {
  background: linear-gradient(145deg, #000000, #12211d);
}
.swatch-dark::after {
  content: "";
  position: absolute;
  bottom: 6px;
  left: 10px;
  right: 10px;
  height: 6px;
  border-radius: 999px;
  background: #7be8c2;
}

.swatch-system {
  background: linear-gradient(135deg, #fafcfb 50%, #0a0f0e 50%);
}
.swatch-system::after {
  content: "";
  position: absolute;
  bottom: 6px;
  left: 10px;
  right: 10px;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #0d7356 50%, #7be8c2 50%);
}

.theme-choice-card strong {
  font-size: 13.5px;
}

.theme-choice-card small {
  font-size: 11px;
  color: var(--text-muted);
}

.theme-hint-note {
  margin: 0 0 18px;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Settings & Profile Subpages */
.subpage {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 20px clamp(14px, 4vw, 24px) 60px;
  animation: settingsSlideIn 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes settingsSlideIn {
  0% { opacity: 0; transform: translateX(36px); }
  100% { opacity: 1; transform: translateX(0); }
}

.page-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.page-nav h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.6px;
}

.settings-group {
  margin-top: 22px;
}

.settings-group h2 {
  margin: 0 10px 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--accent);
}

.settings-list {
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 70px;
  padding: 14px 18px;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
}

.setting-row + .setting-row {
  border-top: 1px solid var(--border);
}

.setting-copy {
  flex: 1;
  min-width: 0;
}

.setting-title {
  display: block;
  font-size: 15.5px;
  font-weight: 550;
}

.setting-detail {
  display: block;
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.setting-select {
  min-height: 38px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--accent);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
}

.toast {
  position: fixed;
  left: 50%;
  top: max(70px, calc(env(safe-area-inset-top) + 58px));
  transform: translateX(-50%);
  z-index: 70;
  padding: 9px 18px;
  border-radius: 999px;
  background: #101716f2;
  color: #7be8c2;
  border: 1px solid rgba(123, 232, 194, 0.4);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  animation: toastSlideDown 0.2s ease;
}

@keyframes toastSlideDown {
  0% { opacity: 0; transform: translate(-50%, -8px); }
  100% { opacity: 1; transform: translate(-50%, 0); }
}

[data-theme="light"] .toast {
  background: #1b262c;
  color: #ffffff;
}

@keyframes fadeSlideUp {
  0% { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
