/* Tutto e' pensato per un dito piccolo: bottoni grandi, niente testo,
   niente scroll, niente zoom accidentale. */

:root {
  --btn: 60px;
  --radius: 18px;
  --ink: #4a3a52;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #f4eef8;
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

body {
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }

/* ---------- barra strumenti ---------- */

#toolbar {
  flex: 0 0 auto;
  background: linear-gradient(105deg, #ffdff0 0%, #f0e0ff 34%, #dff0ff 68%, #dffaf0 100%);
  border-bottom-left-radius: 26px;
  border-bottom-right-radius: 26px;
  box-shadow: 0 4px 14px rgba(120, 90, 140, 0.18);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.spacer { flex: 1 1 auto; }
.sep {
  width: 2px;
  height: 34px;
  background: rgba(120, 90, 140, 0.18);
  border-radius: 2px;
  margin: 0 2px;
}

.btn {
  width: var(--btn);
  height: var(--btn);
  min-width: var(--btn);
  border: none;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 2px 0 rgba(120, 90, 140, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  font-size: 30px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: transform 0.09s ease, box-shadow 0.09s ease, background 0.09s ease;
}

.btn:active { transform: translateY(2px) scale(0.96); }
.btn.ghost { background: rgba(255, 255, 255, 0.5); font-size: 26px; }
.btn:disabled { opacity: 0.35; }

.btn.on {
  background: #fff;
  transform: translateY(-3px) scale(1.06);
  box-shadow: 0 6px 0 rgba(120, 90, 140, 0.2), 0 0 0 3px #fff, 0 0 0 6px rgba(255, 180, 215, 0.85);
}

/* pastiglie colore */
.swatch {
  width: 46px;
  height: 46px;
  border: 3px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  padding: 0;
  box-shadow: 0 2px 5px rgba(120, 90, 140, 0.25);
  transition: transform 0.09s ease, box-shadow 0.09s ease;
}
.swatch:active { transform: scale(0.92); }
.swatch.on {
  transform: scale(1.16);
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px rgba(255, 180, 215, 0.9), 0 3px 8px rgba(120, 90, 140, 0.3);
}

/* dimensione tratto */
.size {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
  display: grid;
  place-items: center;
}
.size i {
  display: block;
  border-radius: 50%;
  background: var(--ink);
}
.size.on {
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 180, 215, 0.9);
}

/* adesivi */
#stickerbar {
  overflow-x: auto;
  flex-wrap: nowrap;
  touch-action: pan-x;
  padding-bottom: 2px;
}
.sticker {
  width: 54px;
  height: 54px;
  min-width: 54px;
  border: none;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.6);
  font-size: 32px;
  line-height: 1;
}
.sticker.on {
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 180, 215, 0.9);
  transform: scale(1.06);
}

/* ---------- foglio ---------- */

#stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  position: relative;
}

#page {
  height: 100%;
  max-width: 100%;
  aspect-ratio: 1820 / 1300;
  background: #ffd978;
  border-radius: 30px;
  padding: 14px;
  box-shadow: 0 10px 26px rgba(120, 90, 140, 0.22);
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 18px;
  background: #fffdf7;
  touch-action: none;
}

#loading {
  position: absolute;
  inset: auto;
  padding: 14px 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 6px 18px rgba(120, 90, 140, 0.25);
  font-size: 20px;
  font-weight: 600;
}

/* ---------- galleria ---------- */

#gallery {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(74, 58, 82, 0.55);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
}

.gallery-box {
  background: #fff;
  border-radius: 28px;
  padding: 22px;
  max-width: 900px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.gallery-box h1 {
  margin: 0 0 16px;
  font-size: 28px;
  text-align: center;
}
.gallery-box h2 {
  margin: 22px 0 10px;
  font-size: 21px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.gallery-box h2:first-of-type { margin-top: 6px; }
.gallery-box h2 span { font-size: 26px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
.card {
  border: none;
  background: #fff8e6;
  border-radius: 20px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: 0 3px 0 rgba(120, 90, 140, 0.15);
}
.card:active { transform: scale(0.97); }
.card img {
  width: 100%;
  aspect-ratio: 1820 / 1300;
  object-fit: contain;
  background: #fff;
  border-radius: 14px;
}
.card span { font-size: 17px; font-weight: 600; }

.btn.close {
  width: auto;
  height: 52px;
  padding: 0 26px;
  margin: 18px auto 0;
  font-size: 19px;
  font-weight: 700;
  background: #ffe1ef;
}
