:root {
  --bg: #fff1f4;
  --bg2: #ffe6ef;
  --panel: #ffffff;
  --ink: #5a3e4d;
  --ink-soft: #9a7c8a;
  --line: #f1d9e2;
  --accent: #ff5d8f;
  --accent-d: #e8447a;
  --shadow: 0 10px 30px rgba(150, 80, 110, 0.16);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg), var(--bg2));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- Birthday banner ---------- */
.bday-banner {
  flex: 0 0 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 9px 44px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.2px;
  color: #6a3550;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
  background: linear-gradient(90deg, #ffb3c9, #ffe08a, #b9e8d0, #c3b6f2, #ffb3c9);
  background-size: 300% 100%;
  animation: bdayShimmer 9s linear infinite;
  border-bottom: 1px solid rgba(255, 255, 255, 0.5);
}
@keyframes bdayShimmer { to { background-position: 300% 50%; } }
.bday-x {
  position: absolute;
  right: 12px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px;
  border: none; border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  color: #6a3550; font-weight: 800; font-size: 12px; line-height: 1;
  cursor: pointer;
}
.bday-x:hover { background: rgba(255, 255, 255, 0.75); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand { font-size: 20px; font-weight: 800; letter-spacing: 0.2px; }
.brand .logo { font-size: 22px; }
.actions { display: flex; align-items: center; gap: 8px; }
.sep { width: 1px; height: 24px; background: var(--line); margin: 0 2px; }

.btn {
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 8px 13px;
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.15s ease, background 0.15s;
  box-shadow: 0 1px 0 rgba(0,0,0,0.02);
}
.btn:hover { box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; box-shadow: none; }
.btn.icon { padding: 8px 11px; font-size: 18px; line-height: 1; }
.btn.primary { background: var(--accent); border-color: var(--accent-d); color: #fff; }
.btn.primary:hover { background: var(--accent-d); }
.btn.ghost { background: transparent; }

/* ---------- Layout ---------- */
.layout { flex: 1 1 auto; display: flex; min-height: 0; }
.stage {
  flex: 1 1 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-width: 0;
}
#cake {
  touch-action: none;
  border-radius: 18px;
  cursor: crosshair;
}
.stage-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: var(--ink-soft);
  background: rgba(255,255,255,0.7);
  padding: 5px 12px;
  border-radius: 20px;
  pointer-events: none;
  transition: opacity 0.2s;
}

/* ---------- Panel ---------- */
.panel {
  flex: 0 0 300px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.group h3 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--ink-soft);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.group .hint { font-size: 10px; text-transform: none; letter-spacing: 0; font-weight: 600; }
.group.grow { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

/* collapsible sections */
.group.collapsible .ghead { cursor: pointer; user-select: none; align-items: center; }
.group.collapsible .ghead .chev { margin-left: auto; font-size: 11px; transition: transform 0.15s; }
.group.collapsible:not(.open) .ghead .chev { transform: rotate(-90deg); }
.group.collapsible:not(.open) .gbody { display: none; }

/* message section */
.text-in { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; font-weight: 600; color: var(--ink); background: #fffafc; }
.msg-row { display: flex; gap: 8px; margin-top: 8px; }
.msg-row select { flex: 1; min-width: 0; padding: 8px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; font-weight: 600; background: #fffafc; color: var(--ink); }
.msg-colors { display: flex; gap: 6px; margin: 11px 0; flex-wrap: wrap; }
.mini-swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.mini-swatch.sel { box-shadow: 0 0 0 2px var(--accent); }
.btn.full { width: 100%; }
.tiny { margin: 8px 0 0; font-size: 11px; color: var(--ink-soft); }

/* segmented control (tiers) */
.seg { display: flex; gap: 6px; }
.seg-btn { flex: 1; padding: 9px 4px; border: 1px solid var(--line); border-radius: 10px;
  background: #fffafc; font: inherit; font-weight: 700; font-size: 13px; color: var(--ink); cursor: pointer; }
.seg-btn:hover { box-shadow: var(--shadow); }
.seg-btn.sel { border-color: var(--accent); background: #fff0f5; box-shadow: 0 0 0 2px rgba(255,93,143,0.18); }

/* drip toggle */
.drip-row { display: flex; align-items: center; justify-content: space-between; }
.drip-label { font-weight: 700; font-size: 13px; }
.toggle { min-width: 56px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: #f0e6ec; font: inherit; font-weight: 800; font-size: 12px; color: var(--ink-soft); cursor: pointer; }
.toggle.on { background: var(--accent); border-color: var(--accent-d); color: #fff; }

/* pattern stepper (< name >) */
.stepper { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.step-btn { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 9px;
  background: #fffafc; font-size: 18px; line-height: 1; font-weight: 800; color: var(--ink); cursor: pointer; padding: 0; }
.step-btn:hover { box-shadow: var(--shadow); }
.step-name { flex: 1; text-align: center; font-weight: 800; font-size: 13px; color: var(--ink);
  background: #fff0f5; border: 1px solid var(--line); border-radius: 9px; padding: 6px 4px; }

/* palette categories */
.palette { display: flex; flex-direction: column; gap: 0; }
.palette-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 8px; }
.palette-cat { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--ink-soft); margin: 12px 2px 6px; }
.palette-cat:first-child { margin-top: 0; }
.topping-btn.armed { border-color: var(--accent); background: #fff0f5;
  box-shadow: 0 0 0 3px rgba(255,93,143,0.18); }

.shapes { display: flex; gap: 8px; flex-wrap: wrap; }
.shape-btn {
  width: 52px; height: 52px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  padding: 0;
  display: grid; place-items: center;
  transition: border-color 0.12s, transform 0.06s;
}
.shape-btn:hover { transform: translateY(-1px); }
.shape-btn.sel { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,93,143,0.15); }

input[type=range] {
  width: 100%;
  accent-color: var(--accent);
  height: 26px;
}

.flavors { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.flavor-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: none; background: none; cursor: pointer; padding: 2px;
}
.swatch {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px var(--line), 0 3px 6px rgba(0,0,0,0.08);
  transition: transform 0.08s;
}
.flavor-btn:hover .swatch { transform: scale(1.08); }
.flavor-btn.sel .swatch { box-shadow: 0 0 0 2px var(--accent), 0 3px 8px rgba(0,0,0,0.12); }
.flavor-btn small { font-size: 10px; color: var(--ink-soft); font-weight: 600; }

.palette {
  display: flex;
  flex-direction: column;
  padding: 2px;
}
.topping-btn {
  touch-action: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffafc;
  cursor: grab;
  padding: 6px 2px 5px;
  transition: transform 0.06s, box-shadow 0.15s;
  user-select: none;
}
.topping-btn:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.topping-btn:active { cursor: grabbing; }
.topping-btn small { font-size: 9.5px; color: var(--ink-soft); font-weight: 700; }
.topping-btn canvas { pointer-events: none; }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; }
.modal[hidden] { display: none; }
.backdrop { position: absolute; inset: 0; background: rgba(70, 40, 55, 0.4); backdrop-filter: blur(2px); }
.sheet {
  position: relative;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(80,40,60,0.35);
  width: min(460px, 92vw);
  max-height: 88vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sheet.wide { width: min(820px, 94vw); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 18px; }
.x { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--ink-soft); }
.sheet-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--line);
}

.export-body { display: flex; gap: 18px; padding: 18px 20px; flex-wrap: wrap; }
.export-preview {
  background: repeating-conic-gradient(#eee 0% 25%, #fff 0% 50%) 50% / 20px 20px;
  border-radius: 14px; overflow: hidden;
  width: 240px; height: 240px; flex: 0 0 auto;
}
.export-grid { display: flex; flex-direction: column; gap: 12px; flex: 1 1 180px; }
.export-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.export-grid select, .export-grid input {
  font: inherit; font-weight: 600; color: var(--ink);
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fffafc;
}

.gallery-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px; padding: 18px 20px; overflow-y: auto;
}
.cake-card {
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  background: #fffafc; display: flex; flex-direction: column;
}
.cake-card .thumb { background: #fff7ea; display: grid; place-items: center; }
.cake-card .meta { padding: 8px 10px; }
.cake-card .name { font-weight: 800; font-size: 14px; }
.cake-card .date { font-size: 11px; color: var(--ink-soft); }
.cake-card .row { display: flex; gap: 6px; padding: 0 10px 10px; }
.cake-card .row .btn { flex: 1; padding: 6px; font-size: 12px; }
.gallery-empty { padding: 40px; text-align: center; color: var(--ink-soft); grid-column: 1/-1; }

/* Report a problem */
.report-body { padding: 18px 20px 22px; }
.report-intro { margin: 0 0 16px; font-size: 14px; color: var(--ink-soft); }
.report-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.report-opt {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 18px 10px; border: 1px solid var(--line); border-radius: 14px;
  background: #fffafc; cursor: pointer; font: inherit; font-weight: 800; font-size: 14px; color: var(--ink);
  transition: transform 0.06s, box-shadow 0.15s, border-color 0.12s;
}
.report-opt:hover { box-shadow: var(--shadow); transform: translateY(-2px); border-color: var(--accent); }
.report-opt:active { transform: translateY(0); }
.ro-emoji { font-size: 28px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 22px;
  font-weight: 700; font-size: 14px; z-index: 100; opacity: 0;
  transition: opacity 0.2s, transform 0.2s; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .panel { flex: 0 0 auto; max-height: 46vh; border-left: none; border-top: 1px solid var(--line); }
  .brand { font-size: 17px; }
  .actions .btn span, .actions { gap: 6px; }
}
