:root {
  --bg: #000000;
  --surface: #0a0a0d;
  --surface-2: #121217;
  --border: #1c1c24;
  --text: #f4f4f6;
  --text-dim: #71717a;
  --accent-grad: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%);
  --accent-pink: #ec4899;
  --accent-purple: #8b5cf6;
  --radius: 8px;
}

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

html {
  background-color: var(--bg);
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  min-height: 100vh;
  overflow-x: clip;
}

.hidden {
  display: none !important;
}

/* Minimal Sticky Top Bar */
.topbar {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 9px 14px;
}

.topbar-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding-right: 4px;
  user-select: none;
  flex-shrink: 0;
}

.brand-claw {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 6px rgba(236, 72, 153, 0.35));
  transition: transform 0.15s ease;
}

.brand:hover .brand-claw {
  transform: translateY(1px);
}

.brand-name {
  font-weight: 600;
  font-size: 0.96rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

/* Search Form */
.search-form {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-box {
  position: relative;
  flex: 1 1 150px;
  min-width: 120px;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 11px;
  color: var(--text-dim);
  pointer-events: none;
}

#tagInput {
  width: 100%;
  height: 34px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 30px 0 32px;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s ease;
}

#tagInput:focus {
  border-color: var(--accent-purple);
}

#tagInput::-webkit-search-cancel-button,
#tagInput::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

.clear-btn {
  position: absolute;
  right: 7px;
  background: transparent;
  color: var(--text-dim);
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 2px 5px;
}

.clear-btn:hover {
  color: var(--text);
}

/* Autocomplete Dropdown */
.ac-menu {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  background: #08080b;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.9);
  z-index: 80;
  max-height: 260px;
  overflow-y: auto;
}

.ac-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  border-bottom: 1px solid #111116;
}

.ac-item:last-child {
  border-bottom: none;
}

.ac-item:hover,
.ac-item.active {
  background: var(--surface-2);
}

.ac-count {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Minimal Controls & Buttons */
.minimal-select {
  height: 34px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 8px;
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
}

.minimal-select.full {
  width: 100%;
}

.minimal-select:focus {
  border-color: var(--accent-purple);
}

.minimal-select.active-filter {
  border-color: var(--accent-pink);
  color: #f9a8d4;
  box-shadow: 0 0 0 1px rgba(236, 72, 153, 0.28);
}

.btn-gradient {
  height: 34px;
  background: var(--accent-grad);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0 13px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn-gradient:hover:not(:disabled) {
  opacity: 0.92;
}

.btn-gradient:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-gradient:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-ghost {
  height: 34px;
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 10px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.btn-ghost:hover,
.btn-ghost.active {
  color: var(--text);
  border-color: var(--accent-purple);
}

.btn-ghost.tiny {
  height: 26px;
  padding: 0 8px;
  font-size: 0.74rem;
}

.btn-icon {
  width: 34px;
  height: 34px;
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-icon:hover {
  color: var(--text);
  border-color: var(--accent-purple);
}

.btn-pwa-install {
  height: 34px;
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.btn-pwa-install svg {
  color: var(--accent-pink);
  flex-shrink: 0;
}

.btn-pwa-install:hover,
.btn-pwa-install.ready {
  color: var(--text);
  border-color: rgba(236, 72, 153, 0.55);
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.18);
}

@media (display-mode: standalone) {
  .btn-pwa-install {
    display: none !important;
  }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.count-label {
  font-size: 0.76rem;
  color: var(--text-dim);
  padding: 0 4px;
  font-variant-numeric: tabular-nums;
}

/* Main Content & Masonry Columns */
.main-area {
  flex: 1;
  padding: 10px 10px 40px;
}

.warning-banner {
  background: #140d14;
  border: 1px solid #3b1d38;
  color: #f9a8d4;
  padding: 8px 12px;
  border-radius: var(--radius);
  margin-bottom: 10px;
  font-size: 0.8rem;
}

.empty-state {
  margin: 18vh auto;
  text-align: center;
  padding: 0 16px;
}

.empty-title {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.empty-sub {
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* True Aspect Ratio Masonry Grid */
.masonry-grid {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
}

.masonry-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ref-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  opacity: 1;
  transition: border-color 0.15s ease;
  user-select: none;
}

.ref-card.selected {
  border-color: var(--accent-pink);
  box-shadow: 0 0 0 1px var(--accent-purple);
}

.card-img-wrap {
  position: relative;
  width: 100%;
  display: block;
  background: #050507;
  cursor: zoom-in;
  overflow: hidden;
}

.card-img-wrap img {
  width: 100%;
  height: auto;
  display: block;
  opacity: 1;
}

.card-img-wrap .card-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

/* Minimal Card Overlay Controls */
.card-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 7px;
}

.overlay-top,
.overlay-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.overlay-bottom,
.src-tag {
  opacity: 0;
  transition: opacity 0.15s ease;
}

.ref-card:hover .overlay-bottom,
.ref-card:hover .src-tag,
.ref-card.selected .overlay-bottom,
.ref-card.selected .src-tag {
  opacity: 1;
}

/* Always subtly visible on touch devices so mobile users can 1-tap Copy or Select */
@media (hover: none), (pointer: coarse) {
  .overlay-bottom,
  .src-tag {
    opacity: 1;
  }
}

.select-box {
  pointer-events: auto;
  width: 25px;
  height: 25px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.72);
  border: 1.5px solid rgba(255, 255, 255, 0.38);
  color: transparent;
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: border-color 0.12s ease, transform 0.1s ease;
}

.select-box:hover {
  border-color: var(--accent-pink);
  transform: scale(1.05);
}

.ref-card.selected .select-box {
  background: var(--accent-grad);
  border-color: transparent;
  color: #fff;
}

.src-tag {
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.65);
  background: rgba(0, 0, 0, 0.65);
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card-btn-row {
  margin-left: auto;
  display: flex;
  gap: 5px;
  pointer-events: auto;
}

.card-pill-btn {
  background: rgba(0, 0, 0, 0.78);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 0.74rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 0.12s ease, border-color 0.12s ease;
}

.card-pill-btn.study-card-btn {
  border-color: rgba(236, 72, 153, 0.45);
  color: #fbcfe8;
}

.card-pill-btn:hover,
.card-pill-btn.study-card-btn:hover {
  background: var(--accent-grad);
  border-color: transparent;
  color: #fff;
}

.card-pill-btn.copied {
  background: var(--accent-grad);
  border-color: transparent;
  color: #fff;
}

/* Infinite Scroll Sentinel */
.scroll-sentinel {
  width: 100%;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 0;
}

.loading-indicator {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 0.82rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent-pink);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Minimal OLED Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000000;
  display: flex;
  flex-direction: column;
}

.lb-bar {
  background: rgba(0, 0, 0, 0.9);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.lb-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.lb-source {
  color: var(--text);
  font-weight: 600;
  text-transform: capitalize;
}

.lb-ext {
  color: var(--accent-pink);
  text-decoration: none;
}

.lb-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.lb-close {
  background: transparent;
  color: var(--text-dim);
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 6px;
  cursor: pointer;
}

.lb-close:hover {
  color: var(--text);
}

.lb-body {
  flex: 1;
  position: relative;
  display: flex;
  overflow: hidden;
}

.lb-stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.lb-stage:active {
  cursor: grabbing;
}

.lb-canvas-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.lb-canvas-wrap.grayscale {
  filter: grayscale(100%);
}

#lbImage,
#lbVideo {
  max-width: 94vw;
  max-height: calc(100vh - 58px);
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.grid-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.grid-line {
  position: absolute;
  background: rgba(255, 255, 255, 0.35);
}

.grid-line.v1 {
  top: 0;
  bottom: 0;
  left: 33.333%;
  width: 1px;
}

.grid-line.v2 {
  top: 0;
  bottom: 0;
  left: 66.666%;
  width: 1px;
}

.grid-line.h1 {
  left: 0;
  right: 0;
  top: 33.333%;
  height: 1px;
}

.grid-line.h2 {
  left: 0;
  right: 0;
  top: 66.666%;
  height: 1px;
}

.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(10, 10, 13, 0.75);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-nav:hover {
  border-color: var(--accent-pink);
}

.lb-nav.prev {
  left: 12px;
}

.lb-nav.next {
  right: 12px;
}

.lb-drawer {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(290px, 85vw);
  background: rgba(5, 5, 7, 0.95);
  border-left: 1px solid var(--border);
  padding: 14px;
  overflow-y: auto;
  z-index: 20;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 0.78rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 10px;
}

.tag-pill {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 7px;
  font-size: 0.75rem;
  cursor: pointer;
}

.tag-pill:hover {
  color: var(--text);
  border-color: var(--accent-pink);
}

.tag-pill.artist {
  background:
    linear-gradient(#0c0714, #0c0714) padding-box,
    var(--accent-grad) border-box;
  border: 1.5px solid transparent;
  color: #f9a8d4;
  font-weight: 600;
  box-shadow: 0 0 10px rgba(236, 72, 153, 0.28);
}

.tag-pill.artist:hover {
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 0 14px rgba(139, 92, 246, 0.5);
}

/* Settings Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-box {
  background: #07070a;
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  overflow: hidden;
}

.modal-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}

.modal-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.field input {
  height: 34px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 10px;
  font-size: 0.85rem;
  outline: none;
}

.field input:focus {
  border-color: var(--accent-purple);
}

.seg-row {
  display: flex;
  gap: 6px;
}

.seg-opt {
  flex: 1;
  height: 32px;
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.78rem;
  cursor: pointer;
}

.seg-opt.active {
  background: var(--accent-grad);
  color: #fff;
  border-color: transparent;
  font-weight: 600;
}

.modal-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Minimal Toast */
.toast-wrap {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.toast {
  background: #0c0c10;
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-pink);
  border-radius: var(--radius);
  padding: 8px 13px;
  font-size: 0.8rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.85);
}

/* Collage Preview & Export Modal */
.collage-stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 18px;
  background: #000000;
  cursor: grab;
  touch-action: none;
}

.collage-stage:active {
  cursor: grabbing;
}

.collage-canvas {
  max-width: 100%;
  max-height: calc(100vh - 155px);
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center center;
}

.pose-select {
  width: 112px;
  max-width: 120px;
  text-overflow: ellipsis;
}

#sourceSelect,
#ratingSelect {
  width: 98px;
  max-width: 108px;
  text-overflow: ellipsis;
}

.collage-email-panel {
  background: #060609;
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.email-row,
.smtp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.email-row input,
.smtp-row input {
  flex: 1 1 180px;
  height: 34px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 11px;
  font-size: 0.85rem;
  outline: none;
}

.email-row input:focus,
.smtp-row input:focus {
  border-color: var(--accent-purple);
}

.collage-footer {
  background: rgba(0, 0, 0, 0.92);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Medium / Split-Screen Window (< 920px):
   Row 1: Brand (left) + Actions (right-aligned)
   Row 2: Full-width Search + Pose + Source + Rating + Pull */
@media (max-width: 920px) {
  .topbar-main {
    flex-wrap: wrap;
    row-gap: 7px;
  }
  .brand {
    order: 1;
  }
  .topbar-actions {
    order: 2;
    margin-left: auto;
  }
  .search-form {
    order: 3;
    flex: 1 1 100%;
    width: 100%;
  }
}

/* Compact Mobile (< 580px):
   Row 1: Brand (left) + Compact Actions (right)
   Row 2: Search input + Pull button
   Row 3: Pose + Source + Rating in 3 equal columns */
@media (max-width: 580px) {
  .topbar {
    padding: 8px 10px;
  }
  .brand-name {
    font-size: 0.88rem;
  }
  .topbar-actions {
    gap: 4px;
  }
  .topbar-actions .btn-ghost,
  .topbar-actions .btn-gradient,
  .btn-pwa-install {
    height: 30px;
    padding: 0 8px;
    font-size: 0.74rem;
  }
  .topbar-actions .btn-icon {
    width: 30px;
    height: 30px;
  }
  .search-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }
  .search-box {
    grid-column: 1 / 3;
    min-width: 0;
  }
  #pullImagesBtn {
    grid-column: 3 / 4;
    width: 100%;
  }
  .pose-select,
  #sourceSelect,
  #ratingSelect {
    width: 100%;
    max-width: none;
  }
  .main-area {
    padding: 6px 6px 36px;
  }
  .masonry-grid,
  .masonry-col {
    gap: 6px;
  }
  .collage-stage {
    padding: 8px;
  }
}

/* ---------------------------------------------------------------------------
   Study Mode — 2-Layer Vector Art Canvas Window (Mobile & Desktop/Tablet)
   --------------------------------------------------------------------------- */
.study-modal {
  z-index: 115;
  background: #000000;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  flex-direction: column;
}

.study-mode-launch-btn {
  box-shadow: 0 0 16px rgba(236, 72, 153, 0.35);
}

/* Top Bar: Strictly 1 row on Desktop, Tablet & Mobile */
.study-topbar {
  position: relative;
  z-index: 40;
  background: rgba(6, 6, 9, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: calc(6px + env(safe-area-inset-top, 0px)) 12px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.study-modal.study-ui-hidden .study-topbar,
.study-modal.study-ui-hidden .study-dock {
  display: none !important;
}

.study-topbar-left,
.study-topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.study-topbar-center {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.study-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 700;
  font-size: 0.84rem;
  padding-right: 4px;
  white-space: nowrap;
}

.study-badge svg {
  stroke: var(--accent-pink);
  flex-shrink: 0;
}

/* History Group (Undo / Redo / Clear) */
.study-history-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: #0c0c12;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
}

.study-history-group .study-icon-btn {
  height: 28px;
  border: none;
  background: transparent;
  padding: 0 8px;
  border-radius: 6px;
}

.study-history-group .study-icon-btn:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.study-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 32px;
  padding: 0 9px;
  font-size: 0.76rem;
  font-weight: 500;
}

.study-icon-btn svg {
  flex-shrink: 0;
}

.study-history-group .study-clear-btn:hover:not(:disabled) {
  color: #fda4af;
}

/* Layers & Opacity Bar */
.study-layers-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #0c0c12;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px 6px;
  height: 32px;
}

.btn-ghost.study-layer-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 8px;
  border-radius: 5px;
  font-size: 0.73rem;
  font-weight: 600;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
}

.study-layer-chip .layer-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3f3f46;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.btn-ghost.study-layer-chip.active {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--text);
}

.study-layer-chip.active .layer-dot.l1 {
  background: #38bdf8;
  box-shadow: 0 0 6px rgba(56, 189, 248, 0.7);
}

.study-layer-chip.active .layer-dot.l2 {
  background: var(--accent-pink);
  box-shadow: 0 0 6px rgba(236, 72, 153, 0.7);
}

.study-opacity-wrap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 2px;
}

.study-opacity-slider {
  width: 68px;
  accent-color: var(--accent-pink);
  cursor: pointer;
}

.btn-ghost.study-palm-btn {
  height: 32px;
  padding: 0 10px;
  min-width: 96px;
  text-align: center;
  font-weight: 600;
  background: #0c0c12;
}

.btn-ghost.study-palm-btn.active {
  background: rgba(236, 72, 153, 0.14);
  border-color: var(--accent-pink);
  color: #fbcfe8;
}

.study-mobile-layers-btn {
  display: none;
  position: relative;
  height: 32px;
  padding: 0 8px;
  gap: 4px;
}

.study-mobile-layers-badge {
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.study-zoom-btn {
  height: 32px;
  padding: 0 8px;
  min-width: 48px;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.study-save-btn {
  height: 32px;
  padding: 0 11px;
}

.study-zen-btn {
  width: 32px;
  height: 32px;
  padding: 0;
}

.study-restore-ui-btn {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 12px;
  z-index: 35;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.65);
}

.study-restore-ui-btn:hover {
  border-color: var(--accent-pink);
}

/* ---------------------------------------------------------------------------
   Bottom Studio Dock (Floating Pill on Desktop/Tablet Landscape, Docked Bar on Mobile)
   --------------------------------------------------------------------------- */
.study-dock {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  max-width: calc(100vw - 20px);
  pointer-events: auto;
}

.study-dock-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(10, 10, 15, 0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 6px 10px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.8);
}

.study-dock-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.study-dock-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

.study-tool-seg {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: #050508;
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.study-tool-seg .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 30px;
  padding: 0 10px;
  border: none;
  border-radius: 7px;
  font-size: 0.76rem;
  font-weight: 500;
  background: transparent;
}

.study-tool-seg .btn-ghost svg {
  flex-shrink: 0;
}

.study-tool-seg .btn-ghost.active {
  background: var(--accent-grad);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(236, 72, 153, 0.35);
}

/* Brush Size & Smoothing Sliders + Live Preview Dot */
.study-sliders-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.study-slider-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #050508;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px 7px;
  height: 36px;
}

.study-pill-label {
  font-size: 0.71rem;
  font-weight: 500;
  color: var(--text-dim);
  white-space: nowrap;
}

.study-brush-preview-wrap {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #101016;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.study-brush-preview-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ef4444;
  transition: width 0.08s ease, height 0.08s ease, background-color 0.12s ease;
}

.study-pill-val {
  font-size: 0.72rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 28px;
  text-align: right;
}

#studyPenSizeInput,
#studySmoothInput {
  width: 66px;
  accent-color: var(--accent-pink);
  cursor: pointer;
}

.study-step-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 0.62rem;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.study-step-btn:hover,
.study-step-btn:active {
  color: #ffffff;
  border-color: var(--accent-pink);
  background: rgba(236, 72, 153, 0.18);
}

/* Color Swatches */
.study-color-palette {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #050508;
  padding: 5px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.study-color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--swatch, #ef4444);
  border: 2px solid rgba(255, 255, 255, 0.28);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  flex-shrink: 0;
}

.study-color-swatch:hover {
  transform: scale(1.1);
}

.study-color-swatch.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px var(--accent-pink);
  transform: scale(1.12);
}

.study-color-custom {
  position: relative;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px dashed rgba(255, 255, 255, 0.5);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  flex-shrink: 0;
  background: conic-gradient(
    from 0deg,
    #ef4444,
    #eab308,
    #22c55e,
    #06b6d4,
    #3b82f6,
    #ec4899,
    #ef4444
  );
}

.study-color-custom.active {
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 2px var(--accent-pink);
  transform: scale(1.12);
}

.study-color-custom input[type="color"] {
  position: absolute;
  inset: -4px;
  width: 32px;
  height: 32px;
  opacity: 0;
  cursor: pointer;
}

.study-color-custom span {
  background: rgba(0, 0, 0, 0.65);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

/* Canvas Stage & Viewport */
.study-stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000000;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}

.study-stage[data-tool="pan"] {
  cursor: grab;
}

.study-stage[data-tool="pan"]:active {
  cursor: grabbing;
}

.study-viewport {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
}

.study-base-canvas,
.study-draw-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

.study-eraser-cursor {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  border: 1.5px solid rgba(255, 255, 255, 0.92);
  background: rgba(236, 72, 153, 0.2);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.85);
  z-index: 20;
}

.study-gesture-hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(8, 8, 12, 0.84);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.72rem;
  pointer-events: none;
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 15;
  opacity: 1;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.study-gesture-hint.fade-out {
  opacity: 0;
  transform: translate(-50%, -6px);
}

.btn-ghost:disabled {
  opacity: 0.32;
  cursor: not-allowed;
}

/* ---------------------------------------------------------------------------
   Tablet & Compact Desktop Window (<= 1040px):
   - Allow floating dock to wrap cleanly if needed
   --------------------------------------------------------------------------- */
@media (max-width: 1040px) {
  .study-dock-inner {
    flex-wrap: wrap;
    justify-content: center;
  }
  .study-dock-divider {
    display: none;
  }
}

/* ---------------------------------------------------------------------------
   Tablet Portrait & Compact Window (<= 860px):
   - Layers & Input bar moves into a sleek toggleable popover under the top bar
   - Bottom Studio Dock anchors cleanly as a full-width footer (zero canvas overlap)
   --------------------------------------------------------------------------- */
@media (max-width: 860px) {
  .study-mobile-layers-btn {
    display: inline-flex;
  }

  .study-topbar-center {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 10px;
    right: 10px;
    max-width: 460px;
    margin: 0 auto;
    background: rgba(10, 10, 16, 0.96);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 12px;
    padding: 8px 10px;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.85);
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    z-index: 50;
  }

  .study-topbar-center.mobile-open {
    display: flex;
  }

  .study-layers-bar {
    flex: 1 1 auto;
    justify-content: space-between;
  }

  .study-opacity-slider {
    width: 88px;
  }

  .study-dock {
    position: relative;
    bottom: auto;
    left: auto;
    transform: none;
    max-width: 100%;
    width: 100%;
    flex-shrink: 0;
    background: rgba(8, 8, 12, 0.96);
    border-top: 1px solid var(--border);
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  }

  .study-dock-inner {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    border-radius: 0;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
  }

  .study-dock-tools-row {
    flex-wrap: wrap;
    justify-content: center;
  }
}

/* ---------------------------------------------------------------------------
   Mobile Phones (<= 620px):
   - Single-row icon-optimized Top Bar
   - Symmetric thumb-friendly Bottom Studio Dock:
     • Tier 1: Full-width Color Swatches
     • Tier 2: Side-by-side 2-column Size & Smooth sliders with ◀ / ▶ arrows
     • Tier 3: Full-width 3-button Tool Switcher (Pen / Eraser / Move)
   --------------------------------------------------------------------------- */
@media (max-width: 620px) {
  .study-topbar {
    padding: calc(5px + env(safe-area-inset-top, 0px)) 8px 5px;
    gap: 4px;
  }

  .study-topbar-left,
  .study-topbar-right {
    gap: 4px;
  }

  .study-btn-label {
    display: none;
  }

  .study-history-group .study-icon-btn {
    width: 30px;
    height: 28px;
    padding: 0;
  }

  #studyCopyBtn {
    width: 32px;
    padding: 0;
  }

  .study-zoom-btn {
    padding: 0 6px;
    min-width: 42px;
    font-size: 0.72rem;
  }

  .study-save-btn {
    padding: 0 9px;
    font-size: 0.75rem;
  }

  .study-dock {
    padding: 6px 8px calc(7px + env(safe-area-inset-bottom, 0px));
  }

  .study-dock-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 5px;
  }

  .study-dock-colors-row {
    order: 1;
    width: 100%;
  }

  .study-dock-tools-row {
    order: 2;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 5px;
  }

  .study-sliders-group {
    order: 1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
  }

  .study-tool-seg {
    order: 2;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .study-tool-seg .btn-ghost {
    height: 30px;
    padding: 0 6px;
    font-size: 0.74rem;
    gap: 4px;
    width: 100%;
  }

  .study-color-palette {
    width: 100%;
    justify-content: space-between;
    padding: 4px 8px;
    overflow-x: auto;
  }

  .study-color-swatch,
  .study-color-custom {
    width: 24px;
    height: 24px;
  }

  .study-slider-pill {
    width: 100%;
    min-width: 0;
    justify-content: space-between;
    padding: 3px 6px;
    height: 32px;
    gap: 4px;
  }

  .study-brush-preview-wrap {
    display: none;
  }

  .study-step-btn {
    width: 20px;
    height: 20px;
    font-size: 0.58rem;
  }

  #studyPenSizeInput,
  #studySmoothInput {
    flex: 1 1 36px;
    width: 100%;
    min-width: 32px;
  }

  .study-pill-val {
    min-width: 25px;
    font-size: 0.69rem;
  }
}

@media (max-width: 390px) {
  .study-badge-text {
    display: none;
  }
  .study-pill-label {
    font-size: 0.66rem;
  }
}



