:root {
  --bg1: #c7a6ee;
  --bg2: #8a63c9;
  --bg3: #5c3d94;
  --pink1: #ffb3d9;
  --pink2: #f45ea6;
  --pink3: #d23a86;
  --yellow1: #ffe66a;
  --yellow2: #ffc928;
  --yellow3: #e5a200;
  --lcd: #c9d3a6;
  --ink: #2b3122;
  --purple: #7a2a9e;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg2);
  color: #fff;
  font-family: 'Fredoka', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

body { overflow: hidden; }

/* ------------------------------------------------------------ sfondo */
.sky {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 80% at 50% 10%, rgba(255, 255, 255, .28), transparent 60%),
    radial-gradient(60% 50% at 15% 85%, rgba(255, 140, 210, .35), transparent 70%),
    radial-gradient(70% 60% at 90% 70%, rgba(110, 70, 200, .45), transparent 70%),
    linear-gradient(160deg, var(--bg1), var(--bg2) 55%, var(--bg3));
}
.sky::before, .sky::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 82% 12%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 70% 82%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 30% 70%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 92% 45%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 6% 52%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 50% 4%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 22% 92%, #fff 50%, transparent 51%);
  animation: twinkle 3.2s ease-in-out infinite;
}
.sky::after {
  transform: translate(37px, 53px) scale(1.15);
  animation-delay: -1.6s;
  opacity: .7;
}
@keyframes twinkle { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* ------------------------------------------------------------ layout */
.stage {
  position: relative;
  min-height: 100%;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.2vh;
  padding: max(14px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
}

.device {
  --w: min(92vw, calc((100svh - 118px) / 1.2), 470px);
  width: var(--w);
  aspect-ratio: 100 / 118;
  position: relative;
  container-type: inline-size;
  margin-top: calc(var(--w) * .07);
  filter: drop-shadow(0 2.4cqw 3cqw rgba(50, 15, 80, .45));
}

/* anello e catenella */
.loop {
  position: absolute;
  left: 50%;
  top: -6.4cqw;
  width: 13cqw;
  height: 11cqw;
  transform: translateX(-50%);
  border-radius: 50% 50% 40% 40%;
  border: 3.2cqw solid var(--pink2);
  background: transparent;
  box-shadow: inset 0 .6cqw 0 rgba(255, 255, 255, .5);
}
.chain {
  position: absolute;
  left: 51%;
  top: -7cqw;
  width: 30cqw;
  height: 30cqw;
  pointer-events: none;
}

/* ------------------------------------------------------------ guscio */
.shell {
  position: absolute;
  inset: 0;
  border-radius: 50% 50% 47% 47% / 56% 56% 44% 44%;
  background:
    radial-gradient(70% 55% at 30% 18%, rgba(255, 255, 255, .55), transparent 55%),
    radial-gradient(90% 80% at 70% 90%, rgba(150, 20, 90, .35), transparent 60%),
    linear-gradient(160deg, #ffa2d2 0%, var(--pink2) 45%, var(--pink3) 100%);
  box-shadow:
    inset 0 1.2cqw 1.2cqw rgba(255, 255, 255, .55),
    inset 0 -2cqw 3cqw rgba(120, 10, 70, .45),
    inset 1.5cqw 0 2cqw rgba(255, 190, 230, .35);
}
.shell::before { /* bordo di giunzione delle due metà */
  content: '';
  position: absolute;
  left: 2%;
  right: 2%;
  top: 55%;
  height: 0;
  border-top: .35cqw solid rgba(160, 20, 90, .35);
  border-radius: 50%;
  pointer-events: none;
}
.gloss {
  position: absolute;
  left: 9%;
  top: 5%;
  width: 46%;
  height: 22%;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0));
  transform: rotate(-18deg);
  pointer-events: none;
}
.deco {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.logo {
  position: absolute;
  left: 9%;
  top: 6.5%;
  width: 82%;
  overflow: visible;
  filter: drop-shadow(0 .5cqw 0 rgba(90, 10, 60, .35));
}
.logo-text {
  font-family: 'Fredoka', ui-rounded, system-ui, sans-serif;
  font-weight: 700;
  font-size: 33px;
  letter-spacing: .5px;
  fill: var(--yellow1);
  stroke: var(--purple);
  stroke-width: 7px;
  paint-order: stroke fill;
  stroke-linejoin: round;
}

/* cornice gialla a stella */
.bezel {
  position: absolute;
  left: 9%;
  right: 9%;
  top: 25.5%;
  height: 51%;
  background: linear-gradient(160deg, var(--yellow1), var(--yellow2) 55%, var(--yellow3));
  clip-path: polygon(
    0% 9%, 9% 2%, 19% 7%, 31% 0%, 43% 6%, 50% 1%, 57% 6%, 69% 0%, 81% 7%, 91% 2%, 100% 9%,
    97% 24%, 100% 38%, 97% 52%, 100% 66%, 97% 80%, 100% 91%,
    91% 98%, 81% 93%, 69% 100%, 57% 94%, 50% 99%, 43% 94%, 31% 100%, 19% 93%, 9% 98%, 0% 91%,
    3% 80%, 0% 66%, 3% 52%, 0% 38%, 3% 24%
  );
  display: grid;
  place-items: center;
}
.bezel::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(80% 60% at 30% 20%, rgba(255, 255, 255, .55), transparent 60%);
  pointer-events: none;
}

.lcd {
  position: relative;
  width: 89%;
  height: 87%;
  border-radius: 4.5cqw;
  background: var(--lcd);
  box-shadow:
    inset 0 .7cqw 1.4cqw rgba(40, 50, 20, .55),
    inset 0 -.3cqw .6cqw rgba(255, 255, 255, .4),
    0 0 0 .9cqw #d39b00,
    0 0 0 1.4cqw rgba(255, 255, 255, .6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.lcd::after { /* riflesso del vetro */
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(125deg, rgba(255, 255, 255, .28) 0%, rgba(255, 255, 255, 0) 32%, rgba(255, 255, 255, 0) 70%, rgba(255, 255, 255, .08) 100%);
  pointer-events: none;
  border-radius: inherit;
}

.icons {
  flex: 0 0 auto;
  height: 11.5%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  padding: 0 4%;
}
.icons.top { border-bottom: .3cqw solid rgba(43, 49, 34, .35); }
.icons.bottom { border-top: .3cqw solid rgba(43, 49, 34, .35); }

.ico {
  appearance: none;
  border: 0;
  margin: 0 auto;
  padding: 0;
  width: 7.2cqw;
  height: 7.2cqw;
  border-radius: 1.4cqw;
  background: transparent;
  color: var(--ink);
  opacity: .82;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}
.ico svg { width: 82%; height: 82%; shape-rendering: crispEdges; display: block; }
.ico svg rect { fill: currentColor; }
.ico.sel {
  background: var(--ink);
  color: var(--lcd);
  opacity: 1;
  transform: scale(1.1);
}
.ico.attn { opacity: .22; cursor: default; }
.ico.attn.on { opacity: 1; animation: blink .7s steps(1) infinite; cursor: pointer; }
.ico.busy { opacity: .35; }
@keyframes blink { 50% { opacity: .2; } }

.screen {
  position: relative;
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  min-height: 0;
}
#lcd {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}
.pixelgrid {
  position: absolute;
  pointer-events: none;
  mix-blend-mode: multiply;
  opacity: .16;
}

/* ------------------------------------------------------------ pulsanti */
.buttons {
  position: absolute;
  left: 50%;
  top: 80.5%;
  width: 54%;
  height: 14cqw;
  transform: translateX(-50%);
}
.btn {
  --s: 11.2cqw;
  position: absolute;
  top: 0;
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  border: 0;
  padding: 0;
  cursor: pointer;
  background:
    radial-gradient(60% 55% at 35% 30%, #fff8c2 0%, rgba(255, 248, 194, 0) 60%),
    radial-gradient(circle at 50% 60%, var(--yellow2), var(--yellow3));
  box-shadow:
    0 1.1cqw 0 #c98a00,
    0 1.8cqw 1.6cqw rgba(110, 10, 60, .45),
    inset 0 -.6cqw .8cqw rgba(170, 90, 0, .45);
  transition: transform .06s ease, box-shadow .06s ease;
  outline: none;
}
.btn:nth-child(1) { left: 0; }
.btn.mid { left: 50%; transform: translateX(-50%); top: 3.2cqw; }
.btn:nth-child(3) { right: 0; }
.btn span {
  position: absolute;
  left: 50%;
  top: calc(100% + 2.6cqw);
  transform: translateX(-50%);
  font-size: 2.9cqw;
  font-weight: 700;
  color: rgba(255, 235, 248, .9);
  text-shadow: 0 .2cqw 0 rgba(140, 20, 80, .5);
  pointer-events: none;
}
.btn.down, .btn:active {
  box-shadow:
    0 .2cqw 0 #c98a00,
    0 .6cqw .8cqw rgba(110, 10, 60, .4),
    inset 0 .6cqw .8cqw rgba(170, 90, 0, .4);
}
.btn:not(.mid).down, .btn:not(.mid):active { transform: translateY(.9cqw); }
.btn.mid.down, .btn.mid:active { transform: translate(-50%, .9cqw); }
.btn:focus-visible { box-shadow: 0 0 0 .8cqw #fff, 0 1.1cqw 0 #c98a00; }

/* ------------------------------------------------------------ barra sotto */
.dock {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 92vw;
}
.legend {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, .9);
  background: rgba(60, 25, 110, .35);
  padding: 7px 12px;
  border-radius: 999px;
  white-space: nowrap;
  backdrop-filter: blur(6px);
}
.legend b { color: var(--yellow1); }
.chip {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .7);
  background: rgba(255, 255, 255, .18);
  color: #fff;
  font: 700 16px/1 'Fredoka', system-ui, sans-serif;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.chip.off { opacity: .45; text-decoration: line-through; }

/* ------------------------------------------------------------ tutorial */
.sheet {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(50, 20, 90, .55);
  backdrop-filter: blur(4px);
  z-index: 10;
  animation: fade .25s ease;
}
.sheet[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.card {
  width: min(100%, 400px);
  max-height: 100%;
  overflow: auto;
  background: linear-gradient(180deg, #fff 0%, #fff3fa 100%);
  color: #4a2660;
  border-radius: 28px;
  padding: 24px 22px 20px;
  box-shadow: 0 0 0 5px var(--yellow2), 0 0 0 9px var(--pink2), 0 24px 50px rgba(40, 0, 60, .45);
  animation: pop .35s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.card h1 { margin: 0 0 6px; font-size: 24px; line-height: 1.15; }
.card h1 span { color: var(--pink3); }
.card .lead { margin: 0 0 14px; font-size: 15px; color: #6b4a80; }
.card ul { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 9px; }
.card li { display: flex; align-items: center; gap: 10px; font-size: 15px; line-height: 1.3; }
.card .k {
  flex: 0 0 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-style: normal;
  font-weight: 700;
  color: #6a4300;
  background: radial-gradient(circle at 35% 30%, #fff6b8, var(--yellow2) 60%, var(--yellow3));
  box-shadow: 0 2px 0 #c98a00;
}
.card .k.t { color: #fff; background: radial-gradient(circle at 35% 30%, #ffc4e2, var(--pink2) 65%); box-shadow: 0 2px 0 var(--pink3); }
.card .small { font-size: 13px; color: #8a6c9c; margin: 0 0 16px; }
.go {
  display: block;
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #ff86c2, var(--pink3));
  color: #fff;
  font: 700 18px 'Fredoka', system-ui, sans-serif;
  box-shadow: 0 4px 0 #9c1f5e;
  cursor: pointer;
}
.go:active { transform: translateY(3px); box-shadow: 0 1px 0 #9c1f5e; }

/* tremolio dello schermo */
.screen.shake { animation: shake 90ms steps(2) infinite; }
.bezel:has(.screen.shake) { animation: shake 120ms steps(2) infinite; }
@keyframes shake {
  0% { transform: translate(0, 0) rotate(0); }
  25% { transform: translate(-1.2px, .8px) rotate(-.4deg); }
  50% { transform: translate(1.2px, -.6px) rotate(.3deg); }
  75% { transform: translate(-.6px, -1px) rotate(.2deg); }
  100% { transform: translate(.8px, 1px) rotate(-.3deg); }
}

@media (prefers-reduced-motion: reduce) {
  .sky::before, .sky::after, .ico.attn.on { animation: none; }
}
