@font-face {
  font-family: "Gochi Hand";
  src: url("fonts/GochiHand-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

:root {
  --ink: #1C1B19;
  --white: #FFFDF8;
  --orange: #EE7D2B;
  --purple: #B6A2E8;
  --yellow: #F4C740;
  --paper: #FBF6EA;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --btn: 46px;              /* set from JS: min(innerWidth, 430) / 8.5 */
  --hit: max(var(--btn), 44px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: fixed;
  inset: 0;
  height: 100dvh;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

canvas, #catcher {
  position: fixed;
  left: 0;
  width: 100%;
  display: block;
  touch-action: none;
}

#paper, #catcher { top: 0; height: 100dvh; }
#paper { pointer-events: none; }

/* The drawing canvas and the stage share one coordinate space: from the safe-area top to
   the screen bottom (the stage insets are measured in it). */
#ink, #stage { top: var(--sat); height: calc(100dvh - var(--sat)); }
#ink { pointer-events: none; }
body.drawing #ink { pointer-events: auto; }
body.on-stage #ink { visibility: hidden; }
#stage { pointer-events: none; }

#safe-probe {
  position: fixed;
  visibility: hidden;
  pointer-events: none;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---- toolbar ---- */

#toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(var(--sat) + 6px) 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;     /* idle: only the stickers take touches */
  z-index: 10;
}
/* While DRAWING, swallow touches across the bar so a stroke started under a bubble isn't
   hidden by it. */
body.drawing #toolbar { pointer-events: auto; }

.row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.row[hidden] { display: none; }
#suit-row { max-width: 398px; }

.sticker {
  appearance: none;
  border: 0;
  margin: 0;
  padding: 0;
  background: none;
  width: var(--hit);
  height: var(--hit);
  display: grid;
  place-items: center;
  position: relative;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  --off: calc(var(--btn) * 0.1);
}
.sticker:focus { outline: none; }
.sticker:focus-visible .sticker-face { outline: 2px solid var(--orange); outline-offset: 3px; }

.sticker > .sticker-back,
.sticker > .sticker-face {
  grid-area: 1 / 1;
  width: var(--btn);
  height: var(--btn);
  border-radius: 50%;
}

/* Sticker surface: colour fill + 2px ink border + a HARD solid ink copy nudged
   down-left. Never a blur or shadow. Pressing shrinks the backdrop to 0.25× its offset and
   slides the face 0.75× into it, so the sticker sinks flat onto the page. */
.sticker-back {
  background: var(--ink);
  transform: translate(calc(var(--off) * -1), var(--off));
}
.sticker-face {
  position: relative;
  z-index: 1;               /* above the (transformed) backdrop */
  background: var(--fill, var(--white));
  box-shadow: inset 0 0 0 2px var(--ink);
  display: grid;
  place-items: center;
  transition: transform 180ms cubic-bezier(0.34, 1.45, 0.64, 1);
}
.sticker-face svg {
  /* icon = 0.37 × button, as a symbol's point size: its drawn glyph fills ≈ 0.72 of a
     24-unit box, so the box is scaled up to match. */
  width: calc(var(--btn) * 0.37 * 1.36);
  height: calc(var(--btn) * 0.37 * 1.36);
  overflow: visible;
}
.sticker.pressed > .sticker-face { transform: translate(calc(var(--off) * -0.75), calc(var(--off) * 0.75)); }

/* ---- ribbon ---- */

#ribbon {
  position: relative;
  display: grid;
  pointer-events: auto;
  transform: rotate(-1.5deg);
  cursor: default;
  --off: 3px;
}
body.drawing #ribbon { visibility: hidden; }
#ribbon > .sticker-back,
#ribbon > .sticker-face { grid-area: 1 / 1; border-radius: 8px; }
#ribbon > .sticker-face {
  position: relative;
  z-index: 1;
  background: var(--yellow);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
  line-height: 1.2;
  white-space: nowrap;
  transition: none;
}

/* ---- long-press menu ---- */

#menu-scrim { position: fixed; inset: 0; z-index: 20; }
#menu {
  position: fixed;
  z-index: 21;
  display: grid;
  --off: 4px;
  min-width: 180px;
}
#menu[hidden], #menu-scrim[hidden] { display: none; }
#menu > .sticker-back,
#menu > .sticker-face { grid-area: 1 / 1; border-radius: 14px; }
#menu > .sticker-face { position: relative; z-index: 1; background: var(--white); box-shadow: inset 0 0 0 2px var(--ink); place-items: stretch; padding: 4px; }
#menu button {
  appearance: none;
  border: 0;
  background: none;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 11px 12px;
  min-height: 44px;
  border-radius: 10px;
  cursor: pointer;
}
#menu button:active, #menu button:focus-visible { background: rgba(28, 27, 25, 0.07); outline: none; }
.menu-icon svg { width: 18px; height: 18px; display: block; }

/* ---- colour picker: one row of round swatches on a sticker card ---- */

#picker-scrim { position: fixed; inset: 0; z-index: 20; }
#picker-scrim[hidden] { display: none; }
#picker {
  position: fixed;
  left: 50%;
  z-index: 21;
  display: grid;
  --off: 4px;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(-8px) scale(0.96);
  transform-origin: top center;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}
#picker.open { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0) scale(1); }
#picker > .sticker-back,
#swatch-grid { grid-area: 1 / 1; border-radius: 999px; }
#swatch-grid {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 10px;
  padding: 9px 12px;
  background: var(--white);
  box-shadow: inset 0 0 0 2px var(--ink);
}
.sw {
  appearance: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  padding: 0;
  margin: 0;
  display: block;
  cursor: pointer;
  box-shadow: inset 0 0 0 2px var(--ink);
  transition: transform 0.08s;
}
.sw:active { transform: scale(0.86); }
.sw.sel { box-shadow: inset 0 0 0 2px var(--ink), inset 0 0 0 5px var(--white); }

/* ---- toast ---- */

#toast {
  position: fixed;
  left: 50%;
  z-index: 25;
  transform: translateX(-50%) translateY(-6px) rotate(-1deg);
  background: var(--white);
  border-radius: 10px;
  box-shadow: inset 0 0 0 2px var(--ink), -3px 3px 0 0 var(--ink);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0) rotate(-1deg); }

/* ---- the little "i" (bottom-left) ---- */

#info {
  position: fixed;
  left: 14px;
  bottom: max(14px, env(safe-area-inset-bottom, 0px));
  z-index: 15;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--ink);
  opacity: 0.55;
  cursor: pointer;
}
#info svg { width: 100%; height: 100%; display: block; }
#info-card {
  position: fixed;
  left: 12px;
  bottom: calc(max(14px, env(safe-area-inset-bottom, 0px)) + 40px);
  z-index: 16;
  max-width: min(80vw, 300px);
  background: var(--white);
  border-radius: 14px;
  box-shadow: inset 0 0 0 2px var(--ink), -4px 4px 0 0 var(--ink);
  padding: 13px 15px;
  font-size: 13px;
  line-height: 1.5;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#info-card.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
#info-card b { font-weight: 800; }
body.erasing #ink { cursor: cell; }
