:root {
  --bg: #f4f3ef;
  --ink: #141414;
  --mute: #8a877f;
  --line: #e3e0d8;
  --red: #e5484d;
  --blue: #2f6fed;
  --hand: Caveat, "Comic Sans MS", cursive;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { user-select: none; }

#scene { position: fixed; inset: 0; }
#scene canvas { display: block; touch-action: none; }

.top {
  position: fixed;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 26px;
  font-size: 14px;
  z-index: 8;
  pointer-events: none;
}
.top > * { pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--red);
  animation: beat 1.6s ease-in-out infinite;
}
@keyframes beat {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, .35); }
  50% { box-shadow: 0 0 0 6px rgba(229, 72, 77, 0); }
}

#cat-name {
  outline: none;
  cursor: text;
  user-select: text;
  border-bottom: 1px dashed transparent;
}
#cat-name:hover, #cat-name:focus { border-bottom-color: var(--mute); }

.stats { display: flex; gap: 18px; color: var(--mute); }
.stats b {
  display: inline-block;
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.stats b.bump { animation: bump .45s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes bump { 40% { transform: translateY(-5px) scale(1.35); color: var(--red); } }

.intro {
  position: fixed;
  left: 26px;
  top: 76px;
  max-width: 360px;
  z-index: 2;
  pointer-events: none;
}
.intro h1 {
  margin: 0 0 8px;
  font-size: 34px;
  font-weight: 500;
  letter-spacing: -.02em;
}
.intro p { margin: 0 0 6px; color: #5b5953; font-size: 15px; line-height: 1.5; }
.intro p.small { font-size: 13px; color: var(--mute); }

#fx { position: fixed; inset: 0; pointer-events: none; z-index: 6; }

/* Hand-drawn annotations */
.note {
  position: absolute;
  color: var(--c);
  font-family: var(--hand);
  font-size: 28px;
  font-weight: 700;
  pointer-events: none;
  animation: note-life 1.9s cubic-bezier(.2, .9, .3, 1.3) forwards;
}
.note svg { position: absolute; left: 0; top: -40px; overflow: visible; }
.note svg path {
  fill: none;
  stroke: var(--c);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-dasharray: 80;
  stroke-dashoffset: 80;
  animation: draw .35s .05s ease-out forwards;
}
.note span {
  position: absolute;
  left: 58px;
  top: -64px;
  white-space: nowrap;
  transform: rotate(var(--rot));
}
.note.left svg { left: -60px; transform: scaleX(-1); }
.note.left span { left: auto; right: 58px; }
@keyframes note-life {
  0% { opacity: 0; transform: scale(.7); }
  12% { opacity: 1; transform: scale(1); }
  80% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-10px); }
}
@keyframes draw { to { stroke-dashoffset: 0; } }

.heart {
  position: absolute;
  width: 24px;
  height: 24px;
  margin: -12px;
  animation: float-up 1.3s ease-out forwards;
}
@keyframes float-up {
  0% { opacity: 0; transform: scale(.3); }
  15% { opacity: 1; transform: translate(calc(var(--dx) * .2), -12px) scale(1.15) rotate(var(--r)); }
  100% { opacity: 0; transform: translate(var(--dx), -120px) scale(.8) rotate(var(--r)); }
}

.zzz {
  position: absolute;
  color: #77736a;
  font-family: var(--hand);
  font-weight: 700;
  font-size: var(--s);
  animation: z-up 2.6s ease-out forwards;
}
@keyframes z-up {
  0% { opacity: 0; transform: translate(0, 0) rotate(-12deg); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(46px, -100px) rotate(12deg); }
}

/* Drawing pad */
.pad {
  position: fixed;
  right: 26px;
  bottom: 96px;
  width: 340px;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(20, 18, 10, .14), 0 2px 8px rgba(20, 18, 10, .05);
  z-index: 12;
  opacity: 0;
  transform: translateY(16px) scale(.97);
  transform-origin: bottom right;
  transition: opacity .22s, transform .32s cubic-bezier(.2, 1.4, .4, 1);
}
.pad.open { opacity: 1; transform: none; }
.pad.shake { animation: shake .4s; }
@keyframes shake {
  20%, 60% { translate: -6px 0; }
  40%, 80% { translate: 6px 0; }
}

.pad-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.tabs { display: flex; gap: 4px; padding: 3px; background: #f2f0ea; border-radius: 999px; }
.tabs button, .pad-foot button, .x {
  all: unset;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 999px;
  color: #3a3833;
  transition: background .2s, color .2s, transform .15s;
}
.tabs button.active { background: var(--ink); color: #fff; }
.x { font-size: 20px; line-height: 1; padding: 4px 10px; color: var(--mute); }
.x:hover { color: var(--ink); }

.paper {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  background-color: #faf9f6;
  background-image: radial-gradient(#dcd8cf 1px, transparent 1px);
  background-size: 16px 16px;
  border: 1px solid var(--line);
  overflow: hidden;
}
.paper canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.paper-hint {
  position: absolute;
  inset: auto 0 44% 0;
  text-align: center;
  font-family: var(--hand);
  font-size: 26px;
  color: #b6b1a6;
  pointer-events: none;
  transition: opacity .2s;
}
.paper-hint.gone { opacity: 0; }

.swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 12px 0; }
.swatch {
  all: unset;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
  cursor: pointer;
  transition: transform .15s;
}
.swatch:hover { transform: scale(1.15); }
.swatch.active { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ink); }
.sizes { display: flex; gap: 2px; margin-left: auto; }
.size {
  all: unset;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  cursor: pointer;
}
.size::after { content: ""; width: var(--s); height: var(--s); border-radius: 50%; background: #3a3833; }
.size.active { background: #f2f0ea; }

.pad-foot { display: flex; gap: 6px; }
.pad-foot button { background: #f2f0ea; }
.pad-foot button:hover { background: #e9e6de; }
.pad-foot .primary { margin-left: auto; background: var(--ink); color: #fff; }
.pad-foot .primary:hover { background: #333; }
.pad-foot button:active, .tabs button:active { transform: scale(.94); }

/* Toolbar */
.toolbar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 12px 32px rgba(20, 18, 10, .08), 0 2px 6px rgba(20, 18, 10, .04);
  z-index: 10;
}
.toolbar button {
  all: unset;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  color: #3a3833;
  cursor: pointer;
  transition: background .2s, color .2s, transform .15s;
}
.toolbar button:hover { background: #f2f0ea; }
.toolbar button:active { transform: scale(.93); }
.toolbar svg { width: 18px; height: 18px; }
.toolbar .sep { width: 1px; margin: 6px 2px; background: var(--line); }
#sound, #daynight { padding: 10px 12px; }
#daynight .moon { display: none; }
#daynight.is-night .sun { display: none; }
#daynight.is-night .moon { display: inline; }

/* Night: dim the overlay UI to match the room (the drawing pad stays paper-white). */
body.night { --bg: #2a2f47; }
body.night .top, body.night .intro { --ink: #f1efe8; --mute: #a3a7c2; color: var(--ink); }
body.night .intro p { color: #c9cbe0; }
body.night .toolbar { background: #353a56; border-color: #474c6b; box-shadow: 0 12px 32px rgba(0, 0, 0, .3); }
body.night .toolbar button { color: #e9e7f2; }
body.night .toolbar button:hover { background: #42476a; }
body.night .toolbar .sep { background: #474c6b; }
body, .top, .intro p, .toolbar { transition: background .8s, color .8s, border-color .8s; }
#sound .off { display: none; }
#sound.muted .on { display: none; }
#sound.muted .off { display: inline; }

@media (max-width: 760px) {
  .intro { top: 56px; }
  .intro h1 { font-size: 26px; }
  .stats { gap: 10px; font-size: 12px; }
  .pad { left: 12px; right: 12px; width: auto; bottom: 86px; }
  .toolbar button span { display: none; }
}
