:root {
  --bg: #fff8ec;
  --ink: #2b2250;
  --muted: #7a6f9b;
  --card: #ffffff;
  --pri: #7c3aed;
  --yellow: #ffd23f;
  --pink: #ff6fb5;
  --teal: #19c3b1;
  --orange: #ff8a3d;
  --blue: #4c9bff;
  --shadow: 0 6px 0 rgb(43 34 80 / .12);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Baloo 2", "Comic Sans MS", "Chalkboard SE", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

.screen { display: none; }
body.screen-home #home, body.screen-art #art { display: block; }
body.screen-trace #trace { display: block; }
body.screen-trace { overflow: hidden; background: #000; }

/* ---------- home ---------- */
#home, #art {
  min-height: 100%;
  padding: calc(14px + var(--safe-t)) 16px calc(90px + var(--safe-b));
  max-width: 1100px; margin: 0 auto;
  background-image: radial-gradient(circle at 10% 0%, #ffe9b3 0 120px, transparent 121px),
                    radial-gradient(circle at 100% 20%, #ffd6ec 0 90px, transparent 91px);
  background-repeat: no-repeat;
}
.home-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logo { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo img { width: 48px; height: 48px; flex: none; }
h1 { margin: 0; font-size: clamp(26px, 6vw, 40px); font-weight: 800; line-height: 1; color: var(--pri); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hello { font-size: clamp(18px, 4.5vw, 24px); font-weight: 700; margin: 14px 0 10px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 10px 18px;
  background: var(--yellow); color: var(--ink); border-radius: 999px; font-weight: 800; font-size: 17px;
  box-shadow: var(--shadow); text-decoration: none; white-space: nowrap;
  transition: transform .1s;
}
.pill:active, .tool:active, .round:active, .card:active { transform: translateY(3px) scale(.97); }
.pill.danger { background: #ffd0d8; }
.pill.yes { background: var(--teal); color: #fff; }

.cats { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 14px; scrollbar-width: none; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.cats::-webkit-scrollbar { display: none; }
.cat {
  flex: none; padding: 8px 16px; border-radius: 999px; background: var(--card); font-weight: 800; font-size: 18px;
  box-shadow: var(--shadow); border: 3px solid transparent;
}
.cat.on { border-color: var(--pri); background: var(--pri); color: #fff; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.card {
  position: relative; background: var(--card); border-radius: 24px; padding: 10px 10px 8px; box-shadow: var(--shadow);
  text-align: center; transition: transform .1s; animation: pop .35s both;
  color: inherit; text-decoration: none; display: block; width: 100%;
}
.card:nth-child(5n+1) { --c: var(--yellow); }
.card:nth-child(5n+2) { --c: var(--pink); }
.card:nth-child(5n+3) { --c: var(--teal); }
.card:nth-child(5n+4) { --c: var(--orange); }
.card:nth-child(5n+5) { --c: var(--blue); }
.card .pic {
  aspect-ratio: 1; border-radius: 18px; background: #fff; display: grid; place-items: center; overflow: hidden;
  border: 4px solid var(--c, var(--yellow));
}
.card .pic img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }
.card .t { display: block; font-weight: 800; font-size: 18px; margin-top: 6px; line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .stars { font-size: 13px; letter-spacing: 1px; }
@keyframes pop { from { opacity: 0; transform: scale(.85); } }

.empty { text-align: center; font-size: 20px; font-weight: 700; color: var(--muted); margin-top: 40px; }
.parents-link {
  position: fixed; right: 12px; bottom: calc(12px + var(--safe-b)); font-size: 14px; font-weight: 700; color: var(--muted);
  background: rgb(255 255 255 / .85); padding: 6px 12px; border-radius: 999px; box-shadow: 0 2px 6px rgb(0 0 0 / .1);
}

.art-cards .card .pic img { object-fit: cover; padding: 0; }
.art-cards .card .t { font-size: 15px; }
#art .home-top h1 { flex: 1; text-align: center; }
#art .home-top span { width: 52px; }
#art .cards { margin-top: 16px; }

/* ---------- trace ---------- */
#trace { position: fixed; inset: 0; background: #000; touch-action: none; }
#trace.screen-mode { background: #fff; }
#cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#trace.screen-mode #cam { display: none; }
#stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
#overlay {
  position: absolute; left: 50%; top: 50%; max-width: none;
  transform-origin: center center; pointer-events: none; opacity: .5;
  will-change: transform;
}
/* Shadow style: multiply-blend into the camera image so it looks printed on the paper */
#overlay.shadow { mix-blend-mode: multiply; }
#trace.screen-mode #overlay.shadow { mix-blend-mode: normal; }

.round {
  width: 52px; height: 52px; border-radius: 50%; background: rgb(255 255 255 / .92); font-size: 24px;
  display: grid; place-items: center; box-shadow: 0 3px 0 rgb(0 0 0 / .2); flex: none; transition: transform .1s;
}
.round.on { background: var(--yellow); }

.tr-top {
  position: absolute; left: 0; right: 0; top: 0; padding: calc(10px + var(--safe-t)) 12px 10px;
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(rgb(0 0 0 / .35), transparent);
}
.mode-switch { flex: 1; display: flex; justify-content: center; }
.mode-switch > * { flex: none; }
.mode-switch button {
  padding: 8px 14px; background: rgb(255 255 255 / .85); font-weight: 800; font-size: 16px;
}
.mode-switch button:first-child { border-radius: 999px 0 0 999px; }
.mode-switch button:last-child { border-radius: 0 999px 999px 0; }
.mode-switch button.on { background: var(--pri); color: #fff; }

.tr-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 12px calc(12px + var(--safe-b));
  background: linear-gradient(transparent, rgb(0 0 0 / .45) 30%);
}
#trace.screen-mode .tr-top { background: linear-gradient(rgb(124 58 237 / .25), transparent); }
#trace.screen-mode .tr-bottom { background: linear-gradient(transparent, rgb(124 58 237 / .25) 30%); }

.opacity-row { display: flex; align-items: center; gap: 10px; max-width: 520px; margin: 0 auto 10px; font-size: 24px; }
.opacity-row input { flex: 1; }
input[type=range] { -webkit-appearance: none; appearance: none; height: 16px; border-radius: 99px; background: linear-gradient(90deg, rgb(255 255 255 / .4), #fff); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 38px; height: 38px; border-radius: 50%; background: var(--yellow); border: 4px solid #fff; box-shadow: 0 2px 6px rgb(0 0 0 / .35); }
input[type=range]::-moz-range-thumb { width: 32px; height: 32px; border-radius: 50%; background: var(--yellow); border: 4px solid #fff; box-shadow: 0 2px 6px rgb(0 0 0 / .35); }

.tools { display: flex; justify-content: center; gap: 8px; max-width: 560px; margin: 0 auto; }
.tool {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 0; padding: 8px 2px 6px;
  background: rgb(255 255 255 / .94); border-radius: 18px; box-shadow: 0 4px 0 rgb(0 0 0 / .2); transition: transform .1s;
}
.tool i { font-style: normal; font-size: 26px; line-height: 1.1; }
.tool b { font-size: 14px; line-height: 1.1; white-space: nowrap; }
.tool.on { background: var(--yellow); }
.tool.snap { background: var(--teal); color: #fff; }

.lock-badge {
  position: absolute; top: calc(74px + var(--safe-t)); left: 50%; transform: translateX(-50%);
  background: rgb(0 0 0 / .55); color: #fff; padding: 4px 14px; border-radius: 99px; font-weight: 800;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
#trace.locked .lock-badge { opacity: 1; }

.show-ui {
  position: absolute; right: 12px; bottom: calc(12px + var(--safe-b)); width: 46px; height: 46px; border-radius: 50%;
  background: rgb(255 255 255 / .5); font-size: 22px; display: none;
}
#trace.ui-hidden .chrome, #trace.ui-hidden .lock-badge { display: none; }
#trace.ui-hidden .show-ui { display: grid; place-items: center; }

.hint {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); max-width: 86%;
  background: rgb(0 0 0 / .6); color: #fff; padding: 12px 18px; border-radius: 18px; font-weight: 700; font-size: 18px;
  text-align: center; pointer-events: none; opacity: 0; transition: opacity .3s;
}
.hint.show { opacity: 1; }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgb(30 20 60 / .6); display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.viewer-box { display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 100%; max-height: 100%; }
.viewer-box img { max-width: 100%; max-height: calc(100vh - 140px); border-radius: 18px; border: 6px solid #fff; background: #fff; }
.viewer-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.dialog-box { background: #fff; border-radius: 24px; padding: 22px; width: 100%; max-width: 360px; text-align: center; box-shadow: var(--shadow); animation: pop .25s; }
.dialog-box p { font-size: 22px; font-weight: 800; margin: 0 0 14px; }
.dialog-box input { width: 100%; font: inherit; font-size: 30px; text-align: center; padding: 6px; border-radius: 14px; border: 3px solid #e5ddff; margin-bottom: 14px; color: var(--ink); }
.dialog-actions { display: flex; gap: 10px; justify-content: center; }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }
.toast {
  position: fixed; left: 50%; bottom: calc(150px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 20px; border-radius: 99px; font-weight: 800; font-size: 18px;
  opacity: 0; transition: .25s; z-index: 70; pointer-events: none; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 700px) {
  .cards { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
}
