:root {
  --bg0: #fff4ec;
  --bg1: #ffd9e6;
  --bg2: #ffe9c8;
  --ink: #3b2430;
  --ink-soft: #714655;
  --panel: rgba(255, 255, 255, 0.8);
  --panel-solid: #fff8f4;
  --line: rgba(80, 30, 45, 0.1);
  --accent: #ef4d7d;
  --accent-2: #7a5cff;
  --gold: #d7a441;
  --shadow: 0 16px 40px rgba(80, 20, 40, 0.12);
  --radius: 22px;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: "Avenir Next", Avenir, "Segoe UI", "Trebuchet MS", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background:
    radial-gradient(1200px 600px at 15% -10%, var(--bg1), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, var(--bg2), transparent 50%),
    var(--bg0);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body.lab {
  --bg0: #120814;
  --bg1: #3a0d4a;
  --bg2: #0c2a4a;
  --ink: #ffeef7;
  --ink-soft: #e9c4d8;
  --panel: rgba(20, 8, 28, 0.72);
  --panel-solid: #1a0b22;
  --line: rgba(255, 180, 230, 0.16);
  --shadow: 0 16px 50px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
  background:
    radial-gradient(800px 500px at 10% 0%, #ff2d8a33, transparent 55%),
    radial-gradient(700px 500px at 100% 10%, #2de1ff33, transparent 50%),
    radial-gradient(900px 700px at 50% 100%, #7a5cff44, transparent 50%),
    var(--bg0);
}

#app {
  height: 100%;
  height: 100dvh;
  display: grid;
  grid-template-columns: 1fr 360px;
  grid-template-rows: auto 1fr;
  padding: calc(12px + var(--safe-t)) 12px 12px;
  gap: 12px;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 8px 8px 10px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  flex: 0 0 auto;
  filter: drop-shadow(0 6px 8px rgba(180, 40, 80, 0.25));
}
.titles h1 {
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 2vw, 1.7rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.tag {
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 600;
  margin-top: 2px;
}

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

.toggle-btn, .icon-btn, .mini-btn, .chip, .action {
  font-family: inherit;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.toggle-btn:hover, .icon-btn:hover, .mini-btn:hover, .chip:hover, .action:hover {
  transform: translateY(-1px);
}
.toggle-btn:active, .icon-btn:active, .mini-btn:active, .chip:active, .action:active {
  transform: translateY(1px) scale(0.98);
}

.toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 8px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
}
.toggle-orb {
  width: 28px; height: 16px;
  border-radius: 99px;
  background: #e9d5dc;
  position: relative;
  display: inline-block;
}
.toggle-orb::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform 0.2s ease, background 0.2s ease;
}
.toggle-btn[aria-pressed="true"] {
  background: linear-gradient(90deg, #7a5cff, #ff4d9a);
  color: #fff;
  border-color: transparent;
}
.toggle-btn[aria-pressed="true"] .toggle-orb { background: rgba(255,255,255,.28); }
.toggle-btn[aria-pressed="true"] .toggle-orb::after {
  transform: translateX(12px);
  background: #fff59a;
}

.icon-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  font-size: 1.05rem;
  display: grid;
  place-items: center;
}
.icon-btn[aria-pressed="true"] { opacity: 0.55; }

.stage-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  background: #fff;
}
body.lab .stage-wrap {
  border-color: rgba(255, 120, 220, 0.3);
  box-shadow: 0 0 0 1px rgba(120, 255, 255, 0.15), 0 20px 60px rgba(255, 0, 160, 0.2);
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#stage.is-grabbing { cursor: grabbing; }
#stage.tool-cursor { cursor: crosshair; }

.hint {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: rgba(255,255,255,.86);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(60,20,40,.12);
  animation: hint-in 0.6s ease both;
  transition: opacity 0.5s ease, transform 0.5s ease;
}
body.lab .hint { background: rgba(20,8,28,.92); color: #ffeef7; border: 1px solid rgba(255,180,230,.35); }
.hint.hide { opacity: 0; transform: translate(-50%, 8px); }
@keyframes hint-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
}

.studio {
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 14px 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.studio-tools {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 2px;
}
.studio .row.actions {
  flex: 0 0 auto;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  background: var(--panel-solid);
  margin: 0 -14px -4px;
  padding-left: 14px;
  padding-right: 14px;
  padding-bottom: 6px;
  border-radius: 0 0 20px 20px;
}

.row h2 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  margin-bottom: 8px;
  font-weight: 800;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip, .action {
  appearance: none;
  padding: 7px 11px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 0.78rem;
  line-height: 1.1;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
}

.chip[aria-pressed="true"], .action[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(239, 77, 125, 0.22);
  background: #fff;
}
body.lab .chip[aria-pressed="true"],
body.lab .action[aria-pressed="true"] {
  background: #2a1233;
  box-shadow: 0 0 0 3px rgba(255, 80, 180, 0.35);
}

.chip .swatch, .chip .glyph {
  width: 18px; height: 18px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: inset 0 2px 3px rgba(255,255,255,.55), 0 1px 2px rgba(0,0,0,.15);
}
.chip .glyph {
  display: grid; place-items: center;
  font-size: 0.85rem;
  background: #fff3f6;
  border-radius: 6px;
  width: 22px; height: 22px;
}
body.lab .chip .glyph { background: #3a1844; }

.swatches .chip { padding: 6px 10px 6px 8px; }
.swatches .chip .swatch {
  width: 22px; height: 22px;
  background: var(--flav);
  position: relative;
}
.swatches .chip .swatch::after {
  content: "";
  position: absolute;
  top: 3px; left: 5px;
  width: 8px; height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,.65);
}

.flavor-wrap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mini-btn {
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
  min-height: 36px;
}
.mini-btn[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.layer-picks {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.layer-slot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,.5);
  border: 1px solid var(--line);
  font-size: 0.72rem;
  font-weight: 700;
}
body.lab .layer-slot { background: rgba(255,255,255,.06); }
.layer-slot select {
  font: inherit;
  font-weight: 700;
  border: 0;
  background: transparent;
  color: inherit;
  max-width: 140px;
}

.actions .action {
  background: linear-gradient(180deg, #fff, #ffe9f0);
  border-radius: 16px;
}
body.lab .actions .action { background: linear-gradient(180deg, #3a1844, #241028); }
body.lab .action.primary {
  background: linear-gradient(180deg, #ff7aa2, #ef4d7d);
  color: #fff;
  border-color: transparent;
}
body.lab .action.gold {
  background: linear-gradient(180deg, #f6d889, #d7a441);
  color: #3b2430;
  border-color: transparent;
}
.action.primary {
  background: linear-gradient(180deg, #ff7aa2, #ef4d7d);
  color: #fff;
  border-color: transparent;
}
.action.gold {
  background: linear-gradient(180deg, #f6d889, #d7a441);
  color: #3b2430;
  border-color: transparent;
}

@media (max-width: 980px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    padding: calc(8px + var(--safe-t)) 8px calc(8px + var(--safe-b));
    gap: 8px;
  }
  .studio {
    max-height: 46dvh;
    border-radius: 20px 20px 16px 16px;
    padding: 10px 10px calc(8px + var(--safe-b));
    gap: 8px;
  }
  .studio .row.actions {
    margin: 0 -10px calc(-2px - var(--safe-b));
    padding: 8px 10px calc(8px + var(--safe-b));
    border-radius: 0 0 16px 16px;
  }
  .row { min-width: 0; }
  .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
  .chip, .action { flex: 0 0 auto; }
  .titles .tag { display: none; }
  .toggle-btn span:last-child { display: none; }
  .toggle-btn { padding: 8px; }
}

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