:root {
  --bg: #fff7e8;
  --bg2: #ffeccc;
  --card: #ffffff;
  --ink: #1b1f3b;
  --muted: #555a78;
  --line: #ead9b8;
  --red: #e3000b;
  --red-ink: #c40009;
  --yellow: #ffcf00;
  --blue: #006cb7;
  --green: #00a850;
  --shadow: 0 6px 0 rgba(27, 31, 59, .12), 0 14px 30px rgba(27, 31, 59, .10);
  --vp: radial-gradient(ellipse at 50% 35%, #fefcf6 0%, #f1e6cf 70%, #e7d6b5 100%);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12152b; --bg2: #1a1e3c; --card: #1e2246; --ink: #f4f1e8; --muted: #b5b8d4; --line: #2f3566;
    --red-ink: #ff6b6b; --shadow: 0 6px 0 rgba(0,0,0,.35), 0 14px 30px rgba(0,0,0,.35);
    --vp: radial-gradient(ellipse at 50% 35%, #2a2f5e 0%, #171a36 70%, #0f1126 100%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12152b; --bg2: #1a1e3c; --card: #1e2246; --ink: #f4f1e8; --muted: #b5b8d4; --line: #2f3566;
  --red-ink: #ff6b6b; --shadow: 0 6px 0 rgba(0,0,0,.35), 0 14px 30px rgba(0,0,0,.35);
  --vp: radial-gradient(ellipse at 50% 35%, #2a2f5e 0%, #171a36 70%, #0f1126 100%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 600 16px/1.45 "Nunito", system-ui, sans-serif;
  min-height: 100dvh;
}
h1, h2, h3 { font-family: "Lilita One", "Nunito", sans-serif; font-weight: 400; letter-spacing: .3px; margin: 0; }
h3 { font-size: 1.05rem; margin: 18px 0 8px; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 10px 16px; cursor: pointer;
  background: var(--card); color: var(--ink); font-weight: 800;
  box-shadow: inset 0 0 0 2px var(--line), 0 3px 0 var(--line);
  transition: transform .12s, box-shadow .12s;
}
.btn:hover { transform: translateY(-2px); box-shadow: inset 0 0 0 2px var(--line), 0 5px 0 var(--line); }
.btn:active { transform: translateY(2px); box-shadow: inset 0 0 0 2px var(--line), 0 1px 0 var(--line); }
.btn.primary { background: var(--red); color: #fff; box-shadow: 0 4px 0 #8f0007; }
.btn.primary:hover { box-shadow: 0 6px 0 #8f0007; }
.btn.primary:active { box-shadow: 0 1px 0 #8f0007; }
.btn.big { font-size: 1.15rem; padding: 14px 24px; }
.btn.small { padding: 7px 12px; font-size: .9rem; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn:disabled { opacity: .55; cursor: wait; transform: none; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 2px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 10px; background: none; border: 0; cursor: pointer; padding: 0;
  font-family: "Lilita One", sans-serif; font-size: 1.45rem; letter-spacing: 1px; }
.logo b { color: var(--red); font-weight: 400; margin-left: 4px; }
.logo-brick { position: relative; width: 34px; height: 22px; background: var(--red); border-radius: 4px; margin-top: 6px;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.18); }
.logo-brick i { position: absolute; top: -6px; width: 10px; height: 7px; background: var(--red); border-radius: 3px 3px 0 0; }
.logo-brick i:first-child { left: 5px; } .logo-brick i:last-child { right: 5px; }
.logo:hover .logo-brick { animation: hop .5s; }
@keyframes hop { 40% { transform: translateY(-6px) rotate(-6deg); } }
.topbar-mid { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-mid input { background: transparent; border: 2px solid transparent; border-radius: 10px; padding: 6px 10px;
  font-family: "Lilita One"; font-size: 1.2rem; min-width: 0; width: 100%; max-width: 420px; }
.topbar-mid input:hover, .topbar-mid input:focus { border-color: var(--line); background: var(--card); outline: none; }
.save-state { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.topbar-right { margin-left: auto; }

.screen { padding: 0 16px; }

/* ---------- lock ---------- */
#lock { display: grid; place-items: center; min-height: 80dvh; }
.lock-card { background: var(--card); padding: 32px; border-radius: 24px; box-shadow: var(--shadow); text-align: center; width: min(420px, 100%); }
.lock-card form { display: flex; gap: 8px; margin-top: 16px; }
.lock-card input { flex: 1; min-width: 0; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); }
.err { color: var(--red-ink); min-height: 1.4em; }
.big-brick { margin: 0 auto 16px; width: 120px; height: 56px; background: var(--yellow); border-radius: 8px; position: relative;
  box-shadow: inset 0 -8px 0 rgba(0,0,0,.15); animation: bob 2.4s ease-in-out infinite; }
.big-brick i { position: absolute; top: -12px; width: 20px; height: 13px; background: var(--yellow); border-radius: 5px 5px 0 0; }
.big-brick i:nth-child(1) { left: 8px } .big-brick i:nth-child(2) { left: 36px } .big-brick i:nth-child(3) { left: 64px } .big-brick i:nth-child(4) { left: 92px }
@keyframes bob { 50% { transform: translateY(-6px) rotate(2deg); } }

/* ---------- home ---------- */
.hero { position: relative; max-width: 900px; margin: 0 auto; padding: 48px 0 24px; text-align: center; }
.hero h1 { font-size: clamp(2rem, 5.5vw, 3.6rem); line-height: 1.05; }
.pop { color: var(--red); display: inline-block; animation: wiggle 3s ease-in-out infinite; }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-5deg) scale(1.05); } 92% { transform: rotate(4deg) scale(1.05); } }
.sub { color: var(--muted); max-width: 600px; margin: 12px auto 0; }
.floaters { position: absolute; inset: 0; pointer-events: none; z-index: -1; overflow: hidden; }
.floaters span { position: absolute; border-radius: 4px; opacity: .55; animation: float 9s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-18px) rotate(12deg); } }
.dream-box { margin: 28px auto 0; background: var(--card); border-radius: 22px; padding: 14px; box-shadow: var(--shadow);
  border: 3px solid var(--ink); text-align: left; }
.dream-box textarea { width: 100%; border: 0; resize: none; background: transparent; font-size: 1.25rem; font-weight: 700; padding: 6px 8px; outline: none; }
.dream-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-top: 6px; }
.styles { display: flex; flex-wrap: wrap; gap: 6px; }
.style { border: 2px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-weight: 800; font-size: .9rem; }
.style.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 16px auto 0; max-width: 760px; }
.chip { border: 0; border-radius: 999px; padding: 6px 14px; cursor: pointer; font-weight: 800; font-size: .9rem; color: #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,.2); transition: transform .15s; }
.chip:hover { transform: translateY(-3px) rotate(-2deg); }
.alt-starts { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 22px; }
.alt-card { display: flex; gap: 12px; align-items: center; text-align: left; background: var(--card); border: 2px dashed var(--line);
  border-radius: 16px; padding: 12px 18px; cursor: pointer; transition: transform .15s, border-color .15s; min-width: 260px; }
.alt-card:hover { transform: translateY(-3px); border-color: var(--blue); }
.alt-card small { display: block; color: var(--muted); font-weight: 600; }
.alt-icon { font-size: 1.8rem; }
.gallery-wrap { max-width: 1200px; margin: 24px auto 60px; }
.gallery-wrap h2 { font-size: 1.6rem; margin-bottom: 12px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.g-card { background: var(--card); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); cursor: pointer; border: 0; padding: 0; text-align: left;
  transition: transform .18s; }
.g-card:hover { transform: translateY(-4px) rotate(-.6deg); }
.g-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--bg2); }
.g-card .g-ph { width: 100%; aspect-ratio: 1; display: grid; place-items: center; font-size: 3rem; background: var(--bg2); }
.g-card div { padding: 10px 12px; }
.g-card b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-card small { color: var(--muted); }
.empty { color: var(--muted); text-align: center; }

/* ---------- pick ---------- */
#pick { max-width: 1100px; margin: 0 auto; padding-top: 20px; padding-bottom: 40px; }
.pick-head { display: flex; gap: 12px; align-items: flex-start; }
.pick-head h1 { font-size: 2rem; }
.pick-head .sub { margin: 4px 0 0; }
.redream { display: flex; gap: 8px; margin: 16px 0; }
.redream input { flex: 1; min-width: 0; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); font-weight: 700; }
.concepts { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.concept { position: relative; border: 0; padding: 0; border-radius: 18px; overflow: hidden; cursor: pointer; background: #fff;
  box-shadow: var(--shadow); transition: transform .18s; }
.concept:hover { transform: translateY(-5px) scale(1.02); }
.concept img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.concept span { position: absolute; left: 10px; bottom: 10px; background: var(--red); color: #fff; padding: 6px 12px; border-radius: 10px;
  font-weight: 900; opacity: 0; transform: translateY(6px); transition: .18s; }
.concept:hover span, .concept:focus-visible span { opacity: 1; transform: none; }

/* ---------- studio ---------- */
#studio { display: grid; grid-template-columns: 1fr 360px; height: calc(100dvh - 62px); padding: 0; }
.viewport { position: relative; background: var(--vp); overflow: hidden; touch-action: none; }
#canvas { width: 100%; height: 100%; display: block; }
.view-switch { position: absolute; top: 12px; left: 12px; display: flex; background: var(--card); border-radius: 12px; padding: 4px; box-shadow: var(--shadow); }
.view-switch button { border: 0; background: none; padding: 6px 12px; border-radius: 9px; cursor: pointer; font-weight: 800; font-size: .9rem; }
.view-switch button.on { background: var(--ink); color: var(--bg); }
.picture-view { position: absolute; inset: 60px 20px 20px; width: calc(100% - 40px); height: calc(100% - 80px); object-fit: contain; }
.vp-stats { position: absolute; left: 12px; bottom: 12px; background: var(--card); padding: 6px 12px; border-radius: 10px; font-size: .85rem; box-shadow: var(--shadow); }
.vp-stats:empty { display: none; }
.tool-hint { position: absolute; top: 64px; left: 12px; font-size: .85rem; color: var(--muted); }
.vp-buttons { position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; gap: 8px; }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; border: 0; background: var(--card); box-shadow: var(--shadow); cursor: pointer; font-size: 1.15rem; }
.icon-btn.on { background: var(--yellow); color: #1b1f3b; }
.panel { background: var(--card); border-left: 2px solid var(--line); overflow-y: auto; padding: 0 16px 24px; }
.tabs { position: sticky; top: 0; background: var(--card); display: flex; gap: 2px; padding: 12px 0 8px; z-index: 2; flex-wrap: wrap; }
.tab { flex: 1; border: 0; background: var(--bg); padding: 8px 4px; border-radius: 10px; cursor: pointer; font-weight: 800; font-size: .85rem; white-space: nowrap; }
.tab.on { background: var(--blue); color: #fff; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button { flex: 1; border: 2px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 4px; cursor: pointer; font-weight: 900; font-size: .85rem; }
.seg button.on { background: var(--yellow); border-color: #c79f00; color: #1b1f3b; }
.slider-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-weight: 800; }
.slider-row input { flex: 1; accent-color: var(--red); }
.slider-row output { min-width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; }
.slider-row.compact { flex: 1; margin: 0; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--red); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.note { color: var(--muted); font-size: .85rem; }
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 6px 0 12px; }
.tool { border: 2px solid var(--line); background: var(--bg); border-radius: 12px; padding: 8px 4px; cursor: pointer; font-weight: 800; font-size: .85rem;
  display: flex; flex-direction: column; align-items: center; gap: 2px; transition: transform .12s; }
.tool span { font-size: 1.3rem; }
.tool:hover { transform: translateY(-2px); }
.tool.on { background: var(--yellow); border-color: #c79f00; color: #1b1f3b; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); gap: 6px; }
.swatch { aspect-ratio: 1; border-radius: 8px; border: 2px solid rgba(0,0,0,.18); cursor: pointer; position: relative; transition: transform .1s; }
.swatch:hover { transform: scale(1.12); }
.swatch.on { outline: 3px solid var(--ink); outline-offset: 2px; }
.swatch.used::after { content: ""; position: absolute; right: 2px; bottom: 2px; width: 6px; height: 6px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1.5px #000; }
.cur-color { font-family: "Nunito"; font-weight: 800; font-size: .9rem; color: var(--muted); }
.step-head { display: flex; align-items: center; gap: 12px; margin: 10px 0; }
.step-head .btn { font-size: 1.4rem; padding: 8px 18px; }
.step-num { flex: 1; text-align: center; font-family: "Lilita One"; font-size: 2.4rem; line-height: 1; }
.step-num small { display: block; font-family: "Nunito"; font-size: .85rem; color: var(--muted); }
#stepRange { width: 100%; accent-color: var(--blue); }
.parts-list { display: flex; flex-direction: column; gap: 6px; }
.part { display: flex; align-items: center; gap: 10px; background: var(--bg); border-radius: 12px; padding: 6px 10px; }
.part .qty { font-family: "Lilita One"; font-size: 1.2rem; min-width: 2.6em; }
.part .pinfo { flex: 1; min-width: 0; }
.part .pinfo small { display: block; color: var(--muted); font-size: .8rem; }
.mini-brick { display: grid; gap: 2px; padding: 3px; border-radius: 4px; box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); flex: none; }
.mini-brick i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,.25); box-shadow: inset 0 -1px 0 rgba(0,0,0,.25); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.stat { background: var(--bg); border-radius: 12px; padding: 10px; }
.stat b { display: block; font-family: "Lilita One"; font-size: 1.5rem; font-weight: 400; }
.stat small { color: var(--muted); }
.weak { background: color-mix(in srgb, var(--yellow) 25%, var(--card)); border: 2px solid var(--yellow); border-radius: 12px; padding: 10px 12px; margin-top: 12px; }
.weak p { margin: 4px 0 8px; font-size: .9rem; }
.export-card { background: var(--bg); border-radius: 14px; padding: 12px 14px; margin-top: 12px; }
.export-card p { margin: 4px 0 10px; font-size: .9rem; color: var(--muted); }
#studio.hand .shape-only { display: none; }
#studio:not(.hand) .hand-only { display: none; }

/* ---------- overlay ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(18, 21, 43, .55); backdrop-filter: blur(4px); }
.work-card { background: var(--card); border-radius: 24px; padding: 28px; width: min(440px, calc(100% - 32px)); text-align: center; box-shadow: var(--shadow); }
.work-card h2 { font-size: 1.7rem; margin-top: 12px; }
.work-card p { color: var(--muted); min-height: 1.5em; }
.bar { height: 14px; border-radius: 999px; background: var(--bg2); overflow: hidden; }
.bar div { height: 100%; width: 0; background: repeating-linear-gradient(45deg, var(--red) 0 14px, #ff3d47 14px 28px); border-radius: 999px; transition: width .6s; animation: stripes 1s linear infinite; background-size: 40px 40px; }
@keyframes stripes { to { background-position: 40px 0; } }
.work-card small { color: var(--muted); display: block; margin-top: 8px; }
.stacker { height: 90px; position: relative; width: 90px; margin: 0 auto; }
.stacker i { position: absolute; left: 15px; width: 60px; height: 18px; border-radius: 4px; box-shadow: inset 0 -4px 0 rgba(0,0,0,.2); animation: drop 2.4s infinite; opacity: 0; }
.stacker i:nth-child(1) { background: var(--red); bottom: 0; animation-delay: 0s; }
.stacker i:nth-child(2) { background: var(--yellow); bottom: 19px; animation-delay: .3s; }
.stacker i:nth-child(3) { background: var(--blue); bottom: 38px; animation-delay: .6s; }
.stacker i:nth-child(4) { background: var(--green); bottom: 57px; animation-delay: .9s; }
@keyframes drop { 0% { opacity: 0; transform: translateY(-40px); } 15%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 40px); background: var(--ink); color: var(--bg); padding: 10px 18px;
  border-radius: 12px; font-weight: 800; opacity: 0; transition: .25s; z-index: 60; pointer-events: none; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  #studio { grid-template-columns: 1fr; grid-template-rows: 55dvh auto; height: auto; }
  .panel { border-left: 0; border-top: 2px solid var(--line); overflow: visible; }
  .topbar-mid input { font-size: 1rem; }
  .logo > span:last-child { display: none; }
  .hero { padding-top: 28px; }
  .dream-row .btn.big { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
