/* ═══════════════════════════════════════════════════════════════
   DIPPIN DOTS - Studio Page
   The craft table. Warm amber light pad. Everything at hand.
═══════════════════════════════════════════════════════════════ */

/* ── Layout ── */
.studio-layout {
  display: grid;
  grid-template-columns: 56px 1fr 280px;
  grid-template-rows: 56px 1fr 44px;
  grid-template-areas:
    "topbar topbar topbar"
    "tools  canvas panel"
    "status status status";
  height: 100dvh;
  overflow: hidden;
  background: var(--velvet);
}

/* ── Top bar ── */
.studio-topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  background: var(--velvet-mid);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  z-index: 20;
}
.studio-logo {
  font-size: 1.1rem;
  font-weight: 900;
  color: transparent;
  background: linear-gradient(90deg, var(--amethyst-lt), var(--rose-lt));
  -webkit-background-clip: text;
  background-clip: text;
  white-space: nowrap;
  text-decoration: none;
  flex-shrink: 0;
}
.prompt-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
}
#prompt-input {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.12);
  border-radius: var(--r-xl);
  color: var(--ink);
  padding: var(--sp-2) var(--sp-4);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}
#prompt-input::placeholder { color: var(--ink-muted); }
#prompt-input:focus {
  border-color: var(--amethyst);
  background: rgba(123,79,212,0.1);
}
#generate-btn {
  flex-shrink: 0;
  font-size: 0.85rem;
  padding: var(--sp-2) var(--sp-4);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}
#save-btn, #mute-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--ink-dim);
  border-radius: var(--r-md);
  padding: var(--sp-1) var(--sp-3);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
#save-btn:hover, #mute-btn:hover { background: rgba(255,255,255,0.12); color: var(--ink); }
#mute-btn, #zen-btn {
  font-size: 1rem;
  padding: var(--sp-1) var(--sp-2);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--ink-dim);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.2s;
}
#zen-btn:hover { background: rgba(255,255,255,0.12); }
#zen-btn.active {
  background: linear-gradient(135deg, rgba(56,128,216,0.35), rgba(123,79,212,0.3));
  box-shadow: 0 0 14px rgba(56,128,216,0.4);
}
/* Photo button, paint from her own pictures */
#photo-btn {
  flex-shrink: 0;
  font-size: 1.05rem;
  padding: var(--sp-1) var(--sp-2);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--ink-dim);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
#photo-btn:hover { background: rgba(255,255,255,0.12); }
#photo-btn:active { transform: scale(0.92); }
/* Action buttons show a word on desktop, a glyph on phones */
.btn-ico { display: none; font-size: 1.05rem; line-height: 1; }
.topbar-actions .btn-txt { display: inline; }

/* ── Left tool dock ── */
.tool-dock {
  grid-area: tools;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) 0;
  background: var(--velvet-mid);
  border-right: 1px solid rgba(255,255,255,0.06);
  z-index: 10;
}
.tool-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  position: relative;
}
.tool-btn:hover { background: rgba(255,255,255,0.08); color: var(--ink); }
.tool-btn.active {
  background: linear-gradient(135deg, rgba(123,79,212,0.35), rgba(240,96,144,0.2));
  color: var(--amethyst-lt);
  box-shadow: inset 0 0 0 1.5px rgba(123,79,212,0.5);
}
.tool-btn:active { transform: scale(0.9); }
.tool-label {
  font-size: 0.52rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
}
.tool-divider {
  width: 28px;
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: var(--sp-1) 0;
}

/* ── Canvas area ── */
.canvas-area {
  grid-area: canvas;
  position: relative;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #2A1845 0%, var(--velvet) 100%);
}
/* Light pad glow - the illuminated surface beneath the canvas */
.canvas-area::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center,
    rgba(255,240,200,0.06) 0%,
    rgba(255,230,180,0.02) 40%,
    transparent 70%);
  pointer-events: none;
  z-index: 0;
}
#canvas-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: crosshair;
}

/* Tool cursor overrides */
#canvas-wrap[data-tool="tweezers"] { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Ctext y='20' font-size='18'%3E✂%3C/text%3E%3C/svg%3E") 8 8, crosshair; }
#canvas-wrap[data-tool="roller"]   { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Ctext y='20' font-size='18'%3E🖨%3C/text%3E%3C/svg%3E") 8 8, default; }
#canvas-wrap[data-wax="empty"][data-tool="pen"] { cursor: not-allowed; }
#canvas-wrap[data-held="yes"] { cursor: cell; }

/* ── Right panel ── */
.studio-panel {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  background: var(--velvet-mid);
  border-left: 1px solid rgba(255,255,255,0.07);
  overflow: hidden;
}
.panel-section {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.panel-section-title {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: var(--sp-2);
}

/* ── Wax pad ── */
#wax-pad {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 56px;
  border-radius: var(--r-md);
  background: radial-gradient(ellipse at 35% 35%, #E8D0A0, #B0904A);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5), inset 0 1px 3px rgba(255,255,255,0.3);
  cursor: pointer;
  transition: transform 0.1s var(--ease-spring), box-shadow 0.15s;
  font-size: 0.7rem;
  font-weight: 700;
  color: rgba(80,50,10,0.7);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 auto;
  -webkit-user-select: none;
  user-select: none;
}
#wax-pad:hover  { transform: scale(1.05); box-shadow: 0 6px 20px rgba(0,0,0,0.6), inset 0 1px 3px rgba(255,255,255,0.3); }
#wax-pad:active { transform: scale(0.95); }
#wax-pad.pulse-hint {
  animation: waxPulse 0.4s ease 0s 3;
}
#wax-pad.wax-loaded {
  box-shadow: 0 0 20px var(--gold), 0 4px 16px rgba(0,0,0,0.5);
  transition: box-shadow 0.2s;
}
@keyframes waxPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 4px 16px rgba(0,0,0,0.5); }
  50%       { transform: scale(1.08); box-shadow: 0 0 28px var(--gold), 0 4px 16px rgba(0,0,0,0.5); }
}

/* ── In-app camera ── */
.cam-overlay {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  background: #000;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.cam-overlay.open { opacity: 1; }
.cam-stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cam-video, .cam-shot {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cam-msg {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(80%, 320px);
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.95rem;
  font-weight: 600;
}
.cam-cancel {
  position: absolute;
  top: calc(env(safe-area-inset-top) + var(--sp-3));
  right: var(--sp-4);
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.45);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.cam-controls {
  padding: var(--sp-5) var(--sp-5) calc(env(safe-area-inset-bottom) + var(--sp-6));
  background: #000;
}
.cam-live {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cam-live[hidden], .cam-confirm[hidden] { display: none; }
.cam-flip, .cam-library-ico {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.cam-flip:active, .cam-library-ico:active { transform: scale(0.92); }
.cam-flip:disabled { opacity: 0.3; }
.cam-shutter {
  width: 76px; height: 76px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.35);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
}
.cam-shutter span {
  width: 58px; height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--amethyst-lt), var(--rose));
  display: block;
  box-shadow: var(--glow-amethyst);
}
.cam-shutter:active { transform: scale(0.92); }
.cam-shutter:disabled { opacity: 0.4; }
.cam-confirm {
  display: flex;
  gap: var(--sp-3);
  justify-content: center;
}

/* ── Drill finish toggle ── */
.drill-toggle {
  display: flex;
  gap: var(--sp-2);
}
.drill-toggle button {
  flex: 1;
  padding: var(--sp-2) var(--sp-2);
  border-radius: var(--r-md);
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: var(--ink-dim);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, border-color 0.18s, box-shadow 0.18s;
}
.drill-toggle button em {
  font-style: normal;
  font-size: 0.6rem;
  opacity: 0.7;
  letter-spacing: 0.06em;
}
.drill-toggle button:hover { color: var(--ink); border-color: rgba(255,255,255,0.22); }
.drill-toggle button.active {
  background: linear-gradient(135deg, rgba(123,79,212,0.4), rgba(240,96,144,0.22));
  color: var(--ink);
  border-color: rgba(123,79,212,0.55);
  box-shadow: 0 0 16px rgba(123,79,212,0.3);
}

/* ── Finale: gentle parallax lift + warm bloom when the painting completes ── */
.canvas-area.finale-lift #canvas-wrap { animation: finaleLift 1.6s var(--ease-out); }
.canvas-area.finale-lift { animation: finaleGlow 1.6s var(--ease-out); }
@keyframes finaleLift {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.035); }
  100% { transform: scale(1); }
}
@keyframes finaleGlow {
  0%, 100% { filter: brightness(1); }
  35%      { filter: brightness(1.28); }
}

/* ── Sorting tray ── */
.tray-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.tray-actions {
  display: flex;
  justify-content: flex-end;
}
#sorting-tray {
  min-height: 90px;
  /* a beveled resin tray, recessed, with a soft inner shadow */
  background:
    linear-gradient(180deg, rgba(0,0,0,0.34), rgba(0,0,0,0.18));
  border-radius: var(--r-md);
  border: 1px solid rgba(255,255,255,0.06);
  box-shadow:
    inset 0 2px 6px rgba(0,0,0,0.55),
    inset 0 -1px 0 rgba(255,255,255,0.05);
  padding: var(--sp-3);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#sorting-tray:hover {
  border-color: rgba(123,79,212,0.4);
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.55), 0 0 16px rgba(123,79,212,0.18);
}
.tray-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 90px;
  opacity: 0.4;
}
.tray-empty .tray-icon { font-size: 1.8rem; }
.tray-empty p { font-size: 0.75rem; text-align: center; line-height: 1.4; }
.tray-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}
.tray-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}
.tray-name { font-size: 0.75rem; font-weight: 700; flex: 1; color: var(--ink); }
.tray-count { font-family: var(--font-mono); font-size: 0.7rem; color: var(--ink-dim); }
.tray-gems {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.tray-gem {
  position: relative;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  /* domed resin bead with an aurora sheen */
  background-image:
    radial-gradient(circle at 34% 30%, rgba(255,255,255,0.85) 0%, rgba(255,255,255,0) 38%),
    radial-gradient(circle at 70% 75%, rgba(0,0,0,0.28) 0%, rgba(0,0,0,0) 55%);
  box-shadow: 0 1px 3px rgba(0,0,0,0.5), inset 0 0 3px rgba(255,255,255,0.25);
  cursor: pointer;
  transition: transform 0.12s var(--ease-spring), filter 0.12s;
}
.tray-gem:hover { transform: scale(1.35) translateY(-1px); filter: brightness(1.15) saturate(1.2); }
.tray-more { font-size: 0.7rem; color: var(--ink-muted); align-self: center; }
.tray-tap-hint { font-size: 0.65rem; color: var(--ink-muted); text-align: center; margin-top: var(--sp-2); }

/* Tray shaking */
.tray-shaking { animation: trayShake 0.6s ease; }
@keyframes trayShake {
  0%  { transform: translateX(0) rotate(0deg); }
  15% { transform: translateX(-4px) rotate(-2deg); }
  30% { transform: translateX(4px) rotate(2deg); }
  45% { transform: translateX(-3px) rotate(-1.5deg); }
  60% { transform: translateX(3px) rotate(1.5deg); }
  75% { transform: translateX(-2px) rotate(-0.5deg); }
  90% { transform: translateX(2px) rotate(0.5deg); }
  100%{ transform: translateX(0) rotate(0deg); }
}

/* ── Color legend ── */
#color-legend {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-1) 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.legend-row {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  grid-template-rows: auto auto;
  column-gap: var(--sp-2);
  row-gap: 2px;
  align-items: center;
  padding: var(--sp-2) var(--sp-4);
  cursor: pointer;
  border-radius: var(--r-sm);
  margin: 0 var(--sp-2);
  transition: background 0.15s;
}
.legend-row:hover { background: rgba(255,255,255,0.05); }
.legend-row.active { background: rgba(123,79,212,0.15); }
.legend-row.color-done { opacity: 0.4; }
.legend-row.color-done .legend-name::after { content: ' ✓'; color: var(--emerald); }
.legend-dot {
  grid-column: 1;
  grid-row: 1 / 3;
  width: 14px;
  height: 14px;
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  flex-shrink: 0;
}
.legend-name  { font-size: 0.72rem; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-count { font-family: var(--font-mono); font-size: 0.65rem; color: var(--ink-muted); }
.legend-bar {
  grid-column: 2 / 4;
  height: 3px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
}
.legend-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--amethyst), var(--rose));
  border-radius: 2px;
  transition: width 0.3s var(--ease-out);
}

/* ── Status bar ── */
.studio-status {
  grid-area: status;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-4);
  background: var(--velvet-mid);
  border-top: 1px solid rgba(255,255,255,0.07);
  font-size: 0.75rem;
  color: var(--ink-dim);
}
.status-progress-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
#progress-bar-track {
  flex: 1;
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
}
#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--amethyst), var(--rose), var(--gold));
  border-radius: 2px;
  transition: width 0.4s var(--ease-out);
}
#progress-txt { font-family: var(--font-mono); white-space: nowrap; }
.status-hint { color: var(--ink-muted); flex-shrink: 0; }

/* ── Loading overlay ── */
#loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  background: rgba(22, 13, 42, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  backdrop-filter: blur(8px);
}
#loading-overlay[hidden] { display: none; }
.loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(123,79,212,0.2);
  border-top-color: var(--amethyst);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-msg { font-size: 0.9rem; color: var(--ink-dim); font-weight: 600; }

/* ── Mobile (iPhone / iPad) ── */
@media (max-width: 768px) {
  .studio-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr auto 56px;
    grid-template-areas:
      "topbar"
      "canvas"
      "status"
      "tools";
  }

  .tool-dock {
    flex-direction: row;
    justify-content: center;
    gap: var(--sp-1);
    padding: 0 var(--sp-3);
    border-right: none;
    border-top: 1px solid rgba(255,255,255,0.07);
    height: 56px;
  }
  .tool-label { display: none; }
  .tool-divider { display: none; }
  .tool-btn { width: 44px; height: 44px; font-size: 1.3rem; }

  .studio-panel {
    display: none; /* Hidden by default on mobile - opened via panel toggle */
  }
  .studio-panel.panel-open {
    display: flex;
    position: fixed;
    inset: 56px 0 56px 0;
    z-index: 50;
    width: 100%;
    animation: slideUp 0.3s var(--ease-spring);
  }
  @keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }

  /* Panel toggle button (only on mobile) */
  .panel-toggle-btn {
    display: flex;
    position: fixed;
    bottom: calc(56px + env(safe-area-inset-bottom) + 12px);
    right: 16px;
    z-index: 40;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--amethyst), var(--rose));
    color: white;
    font-size: 1.1rem;
    align-items: center;
    justify-content: center;
    box-shadow: var(--glow-amethyst), var(--shadow-md);
    border: none;
    cursor: pointer;
    transition: transform 0.2s var(--ease-spring);
  }
  .panel-toggle-btn:active { transform: scale(0.9); }

  #toast {
    bottom: calc(env(safe-area-inset-bottom) + 70px);
  }

  /* Action buttons collapse to glyphs with a proper 44px tap target on phones */
  .topbar-actions .btn-txt { display: none; }
  .topbar-actions .btn-ico { display: inline-flex; }
  .topbar-actions .btn-small {
    min-width: 40px;
    min-height: 40px;
    padding: var(--sp-2);
  }
  #mute-btn { min-width: 40px; min-height: 40px; }
  .studio-topbar { gap: var(--sp-2); padding: 0 var(--sp-3); }
}
@media (min-width: 769px) {
  .panel-toggle-btn { display: none; }
}
