:root {
  --lb-ink: #4a4658;
  --lb-muted: #8b8698;
  --lb-card: #fffdf9;
  --ink: #4a4658;
  --muted: #8b8698;
  --card: #fffdf9;
  --glass: rgba(255, 253, 249, 0.72);
  --line: rgba(93, 90, 107, 0.12);
  --accent: #7f9cc4;
  --accent-soft: #e4ebf5;
  --warm: #e79f8f;
  --shadow: 0 10px 30px rgba(74, 70, 88, 0.08), 0 2px 6px rgba(74, 70, 88, 0.05);
  --radius: 24px;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: #f5f1ea;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

body.carrying, body.carrying * { cursor: grabbing !important; }

h1, h2, p { margin: 0; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ---------- Drifting ambient background ---------- */

.ambient { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.ambient span {
  position: absolute;
  width: 60vmax;
  height: 60vmax;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.55;
  animation: drift 60s ease-in-out infinite alternate;
}
.ambient span:nth-child(1) { background: #f8d9d0; left: -15vmax; top: -20vmax; }
.ambient span:nth-child(2) { background: #dbe4f4; right: -20vmax; bottom: -25vmax; animation-duration: 75s; }
.ambient span:nth-child(3) { background: #e2efdc; left: 30vw; top: 40vh; width: 40vmax; height: 40vmax; animation-duration: 90s; }

@keyframes drift {
  to { transform: translate(6vmax, 4vmax) scale(1.08); }
}

/* ---------- Layout ---------- */

.app { display: grid; grid-template-rows: auto 1fr auto; height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 38px; height: 38px; }
.brand h1 { font-size: 21px; font-weight: 700; letter-spacing: 0.2px; }
.credit { font-size: 13px; color: var(--muted); text-decoration: none; border-bottom: 1px dotted currentColor; }
.credit:hover { color: var(--ink); }
a.hand-hover { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.art-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--glass);
  box-shadow: var(--shadow);
  transition: transform 0.2s, background 0.3s;
}
.art-btn:hover { background: #fff; transform: translateY(-1px); }
.art-btn-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--muted); }
.art-btn strong { font-size: 15px; }
.art-btn svg { width: 18px; height: 18px; color: var(--muted); }

.palette-tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  margin-bottom: 10px;
  border-radius: 999px;
  background: rgba(74, 70, 88, 0.06);
}
.palette-tabs button {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 7px 4px;
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--muted);
  transition: background 0.3s, color 0.3s;
}
.palette-tabs button[aria-pressed="true"] { background: var(--ink); color: #fff; }

.top-actions { display: flex; align-items: center; gap: 8px; }

.progress-pill {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 7px 14px;
  margin-right: 6px;
  font-size: 12px;
  color: var(--muted);
  border-radius: 14px;
  background: var(--glass);
}
.progress-pill .bar { width: 120px; height: 5px; border-radius: 5px; background: var(--line); overflow: hidden; }
.progress-pill .bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #b9d3ad, #a8c8e6, #c6b6e0);
  transition: width 0.6s ease;
}

.studio {
  /* Swatches grow with the window height; two columns always fit 7 rows. */
  --blob: clamp(36px, calc((100vh - 290px) / 7 - 30px), 80px);
  --palette-w: max(184px, calc(var(--blob) * 2 + 76px));
  display: grid;
  grid-template-columns: var(--palette-w) minmax(0, 1fr) 270px;
  grid-template-areas: "palette canvas side";
  gap: 20px;
  padding: 0 24px 12px;
  min-height: 0;
}
body.hand-right .studio {
  grid-template-columns: 270px minmax(0, 1fr) var(--palette-w);
  grid-template-areas: "side canvas palette";
}
.palette { grid-area: palette; }
.canvas-wrap { grid-area: canvas; }
.side { grid-area: side; }

.panel {
  background: var(--glass);
  backdrop-filter: blur(12px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.6px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 12px;
}

/* ---------- Buttons ---------- */

.primary, .ghost-btn, .presets button {
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  transition: transform 0.2s, background 0.3s, box-shadow 0.3s;
}
.primary {
  border: 0;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 6px 16px rgba(74, 70, 88, 0.25);
}
.ghost-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.6);
}
.ghost-btn:hover, .presets button:hover { background: #fff; }
.primary:hover { transform: translateY(-1px); }
button:disabled { opacity: 0.5; cursor: default; }

/* Hover state driven by the hand cursor (pinch to click). */
button.hand-hover:not(.swatch) {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* ---------- Palette ---------- */

.palette { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }

.swatches {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 10px;
}

.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 2px 0;
  border: 0;
  background: none;
  cursor: grab;
  touch-action: none;
}
.blob-wrap { position: relative; padding: 5px; }
/* Ring that fills up as the hand closes over a colour. */
.blob-wrap::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: conic-gradient(var(--ink) calc(var(--grab, 0) * 1turn), rgba(74, 70, 88, 0.12) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3.5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3.5px));
  opacity: 0;
  transition: opacity 0.2s;
}
.swatch.hand-hover .blob-wrap::before { opacity: 1; }
.swatch .blob {
  display: block;
  width: var(--blob);
  height: var(--blob);
  background: var(--paint);
  border-radius: 58% 42% 55% 45% / 48% 58% 42% 52%;
  box-shadow:
    inset -5px -7px 0 rgba(0, 0, 0, 0.05),
    inset 6px 6px 12px rgba(255, 255, 255, 0.55),
    0 4px 10px rgba(74, 70, 88, 0.14);
  transition: transform 0.35s cubic-bezier(.3, 1.5, .5, 1), opacity 0.3s;
}
.swatch:nth-child(even) .blob { border-radius: 45% 55% 42% 58% / 56% 44% 56% 44%; }
.swatch:nth-child(3n) .blob { border-radius: 52% 48% 60% 40% / 42% 55% 45% 58%; }
.swatch .name { font-size: 12px; color: var(--muted); }
.swatch:hover .blob,
.swatch.hand-hover .blob { transform: scale(calc(1.06 + var(--grab, 0) * -0.14)) rotate(-4deg); }
.swatch.lifted .blob { transform: scale(0.82); opacity: 0.55; }

/* ---------- Handedness ---------- */

.hand-toggle {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--glass);
}
.hand-toggle button {
  display: flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
}
.hand-toggle button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.hand-toggle .hand-icon { width: 16px; height: 16px; }
.hand-icon.mirrored { transform: scaleX(-1); }

.choice-label { margin-top: 20px; font-weight: 600; color: var(--ink) !important; }
.hand-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
.hand-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 10px 12px;
  border-radius: 20px;
  border: 2px solid var(--line);
  background: #fff;
  transition: border-color 0.25s, background 0.25s, transform 0.25s;
}
.hand-option .hand-icon { width: 38px; height: 38px; color: var(--muted); transition: color 0.25s, transform 0.4s; }
.hand-option .hand-icon.mirrored { transform: scaleX(-1); }
.hand-option strong { font-size: 15px; }
.hand-option small { font-size: 12px; color: var(--muted); }
.hand-option:hover { transform: translateY(-2px); }
.hand-option[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.hand-option[aria-pressed="true"] .hand-icon { color: var(--ink); }

/* ---------- Canvas ---------- */

.canvas-wrap { display: flex; min-height: 0; min-width: 0; }

.paper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: var(--card);
  border-radius: 30px;
  box-shadow: var(--shadow);
  min-height: 0;
  transition: box-shadow 1.2s ease;
}
.paper.glow { box-shadow: 0 0 0 6px rgba(198, 182, 224, 0.45), 0 0 80px rgba(198, 182, 224, 0.6); }

#art { width: 100%; height: 100%; display: block; overflow: visible; }

#art .region { transition: stroke-width 0.2s; }
#art .region.target { stroke: var(--accent); stroke-width: 5; }

/* ---------- Side panel ---------- */

.side { display: flex; flex-direction: column; gap: 14px; min-height: 0; overflow-y: auto; }

.timer-card { display: flex; flex-direction: column; align-items: center; }
.timer-card h2 { align-self: flex-start; }

.timer-ring { position: relative; width: 132px; height: 132px; }
.timer-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-ring circle { fill: none; stroke-width: 7; stroke-linecap: round; }
.timer-ring .track { stroke: var(--line); }
.timer-ring .arc { stroke: #a8c8e6; transition: stroke-dashoffset 0.25s linear; }
.timer-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.timer-text strong { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.timer-text span { font-size: 12px; color: var(--muted); }

.presets { display: flex; gap: 6px; margin: 12px 0 10px; }
.presets button {
  padding: 6px 12px;
  font-size: 13px;
  border: 1px solid var(--line);
  background: transparent;
}
.presets button.active { background: var(--accent-soft); border-color: transparent; }

.timer-actions { display: flex; gap: 8px; }

.prompt { margin-top: 12px; min-height: 38px; text-align: center; font-size: 13.5px; line-height: 1.45; color: var(--muted); }

.camera-card { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.preview {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 16px;
  overflow: hidden;
  background: #e9e4dc;
}
.preview video, .preview canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.preview video { transform: scaleX(-1); opacity: 0.85; }
.preview-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  color: var(--muted);
}
body.camera-on .preview-empty { display: none; }
.cam-status { font-size: 12.5px; line-height: 1.4; color: var(--muted); }
.cam-status[data-kind="error"] { color: #b06a5c; }

/* ---------- Hand cursor & carried paint ---------- */

.hand-cursor, .paint-drop {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.25s;
}
.hand-cursor.visible, .paint-drop.visible { opacity: 1; }

.hand-cursor .ring {
  --close: 0;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(74, 70, 88, 0.35), 0 6px 18px rgba(74, 70, 88, 0.25);
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, border-color 0.2s;
}
.hand-cursor .ring i {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(127, 156, 196, 0.45);
  transform: scale(calc(0.15 + var(--close) * 0.6));
  transition: transform 0.08s linear;
}
.hand-cursor.closed .ring { transform: scale(0.72); border-color: var(--warm); }
body.carrying .hand-cursor .ring { border-color: var(--carry); }

.paint-drop { z-index: 999; }
.paint-drop i {
  display: block;
  width: 50px;
  height: 50px;
  margin: -25px 0 0 -25px;
  background: var(--carry);
  border-radius: 58% 42% 55% 45% / 48% 58% 42% 52%;
  box-shadow: inset 6px 6px 10px rgba(255, 255, 255, 0.55), 0 10px 22px rgba(74, 70, 88, 0.25);
  animation: wobble 2.4s ease-in-out infinite;
}

/* Glitter: a drifting sheen over the same random flake tile used inside the artwork. */
.swatch.glitter .blob,
body.carry-glitter .paint-drop i {
  background:
    linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, 0.75) 48%, transparent 60%) 0 0 / 260% 100% no-repeat,
    var(--texture) 0 0 / 40px 40px,
    var(--paint);
  animation: sheen 3.2s ease-in-out infinite;
}
body.carry-glitter .paint-drop i {
  --paint: var(--carry);
  --texture: var(--carry-texture);
  animation: wobble 2.4s ease-in-out infinite, sheen 3.2s ease-in-out infinite;
}
.swatch.glitter:nth-child(3n) .blob { animation-delay: -1s; }
.swatch.glitter:nth-child(3n + 1) .blob { animation-delay: -2s; }
@keyframes sheen {
  0% { background-position: 130% 0, 0 0; }
  100% { background-position: -30% 0, 0 0; }
}
@keyframes wobble {
  0%, 100% { border-radius: 58% 42% 55% 45% / 48% 58% 42% 52%; transform: rotate(0deg); }
  50% { border-radius: 44% 56% 46% 54% / 56% 44% 58% 42%; transform: rotate(8deg); }
}

/* ---------- Toast & overlays ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translate(-50%, 20px);
  padding: 12px 22px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s, transform 0.5s;
  z-index: 900;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Learning Bakehouse (shared bar and nudge live in ../shared/bakehouse.css) ---------- */

.done-cta { margin-top: 16px; padding: 14px 18px; border-radius: 18px; background: var(--accent-soft); font-size: 14px !important; }
.done-cta a { color: var(--ink); font-weight: 700; }

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(245, 241, 234, 0.55);
  backdrop-filter: blur(14px);
  z-index: 800;
  animation: fade-in 0.6s ease;
}
.overlay[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; } }

.overlay-card {
  max-width: 520px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 36px 40px;
  border-radius: 32px;
  background: var(--card);
  box-shadow: 0 30px 80px rgba(74, 70, 88, 0.18);
  text-align: center;
}
.overlay-card h2 { font-size: 26px; margin-bottom: 12px; }
.overlay-card p { font-size: 15px; line-height: 1.55; color: #6b6678; }
.overlay-card .muted { margin-top: 10px; color: var(--muted); font-size: 14px; }

.orb-deco {
  width: 74px;
  height: 74px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0%, #f8d9d0 40%, #c6b6e0 100%);
  box-shadow: 0 0 40px rgba(198, 182, 224, 0.7);
  animation: breathe 12s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { transform: scale(0.75); }
  33%, 50% { transform: scale(1); }
}

.steps {
  list-style: none;
  counter-reset: step;
  padding: 0;
  margin: 18px 0;
  display: grid;
  gap: 10px;
  text-align: left;
}
.steps li {
  counter-increment: step;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 16px;
  background: #f7f3ec;
  font-size: 14.5px;
}
.steps li::before {
  content: counter(step);
  flex: none;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  font-size: 13px;
  font-weight: 700;
}

.overlay-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 22px; }
.overlay-actions .primary, .overlay-actions .ghost-btn { padding: 13px 24px; font-size: 15px; }
.fineprint { margin-top: 18px; font-size: 12.5px !important; color: var(--muted) !important; }

/* ---------- Gallery ---------- */

.gallery-card { max-width: 900px; width: 100%; }
.gallery-card h3 {
  margin: 18px 0 10px;
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.6px;
  color: var(--muted);
}
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.art-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 10px 12px;
  border: 2px solid var(--line);
  border-radius: 20px;
  background: #fff;
  transition: transform 0.25s, border-color 0.25s, box-shadow 0.25s;
}
.art-card:hover, .art-card.hand-hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.art-card[aria-pressed="true"] { border-color: var(--accent); }
.art-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; border-radius: 12px; background: #fffdf9; }
.art-card strong { font-size: 15px; }
.art-card small { font-size: 12px; color: var(--muted); }

/* ---------- Share ---------- */

.share-card { max-width: 640px; width: 100%; }
.share-formats {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(74, 70, 88, 0.06);
}
.share-formats button {
  border: 0;
  background: transparent;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13.5px;
  color: var(--muted);
}
.share-formats button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.share-preview { display: grid; place-items: center; margin: 16px 0; min-height: 200px; }
.share-preview img {
  max-width: 100%;
  max-height: 40vh;
  border-radius: 14px;
  box-shadow: 0 14px 40px rgba(74, 70, 88, 0.18);
}
.caption-box {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: #f7f3ec;
  text-align: left;
}
.caption-box p { flex: 1; white-space: pre-line; font-size: 13px !important; line-height: 1.5 !important; }
.caption-box .ghost-btn { flex: none; padding: 7px 12px; font-size: 12.5px; }

/* ---------- Coaching & splash ---------- */

.coach {
  position: fixed;
  left: 50%;
  top: 86px;
  max-width: min(560px, 90vw);
  padding: 12px 22px;
  border-radius: 999px;
  background: rgba(255, 253, 249, 0.92);
  box-shadow: var(--shadow);
  font-size: 15px;
  text-align: center;
  pointer-events: none;
  z-index: 850;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity 0.5s, transform 0.5s;
}
.coach.show { opacity: 1; transform: translate(-50%, 0); }

.splash {
  position: fixed;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 998;
  box-shadow: 0 0 0 1px rgba(74, 70, 88, 0.12);
}

/* ---------- Smaller screens ---------- */

@media (max-width: 1100px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100vh; }
  .topbar { flex-wrap: wrap; }
  .studio, body.hand-right .studio {
    --blob: 60px;
    grid-template-columns: 1fr;
    grid-template-areas: "canvas" "palette" "side";
  }
  .swatches { grid-template-columns: repeat(7, 1fr); }
  .canvas-wrap { height: 70vh; }
  .side { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); overflow: visible; }
}
