:root {
  --ink: #1e3a8a;
  --paper: #faf6ed;
  --trail: #f97316;
  --dim: #94a3b8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  /* stop iPad from scrolling or zooming while a finger is drawing */
  overscroll-behavior: none;
  touch-action: manipulation;
}

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

header {
  flex: 0 0 auto;
  position: relative;
  z-index: 2;                 /* stays tappable under the win overlay */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
}

#diff { display: flex; gap: 6px; flex: 1 1 auto; min-width: 0; }

header button {
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  flex: 1 1 0;                /* five levels have to fit a phone header */
  min-width: 0;
  min-height: 52px;           /* comfortable finger target */
  /* stars shrink so five of them still fit on one line */
  font-size: clamp(9px, 2.6vw, 14px);
  letter-spacing: -0.5px;
  border: 2px solid transparent;
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  line-height: 1.1;
  cursor: pointer;
}

header button small {
  font-size: clamp(9px, 2.2vw, 11px);
  color: var(--dim);
  letter-spacing: 0;
  white-space: nowrap;
}

header button[aria-pressed="true"] {
  border-color: var(--trail);
  background: #fff7ed;
}

header button[aria-pressed="true"] small { color: var(--trail); }

#again { font-size: 22px; flex: 0 0 auto; min-width: 52px; padding: 6px 10px; }

main {
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  padding: 4px 14px 18px;
  min-height: 0;              /* let the svg shrink inside the grid */
}

main svg {
  display: block;
  /* Fill the stage and let preserveAspectRatio letterbox the square
     viewBox. Sizing by the intrinsic viewBox px instead leaves an 8x8
     maze at 196px, far too small to trace with a finger. */
  width: 100%;
  height: 100%;
  touch-action: none;         /* required: we handle the drag ourselves */
}

#win {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  z-index: 1;
  /* Light veil only: the finished trail is the thing the child wants to
     look at, so it must stay legible through the overlay. */
  background: rgba(250, 246, 237, 0.35);
}

#win[hidden] { display: none; }

#win p { margin: 0; font-size: clamp(64px, 18vw, 140px); }

#next {
  font: inherit;
  font-size: 20px;
  padding: 14px 28px;
  border: none;
  border-radius: 999px;
  background: var(--trail);
  color: #fff;
  cursor: pointer;
}

#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }

#confetti i {
  position: absolute;
  top: -12vh;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  animation: fall linear forwards;
}

@keyframes fall {
  to { transform: translateY(115vh) rotate(720deg); }
}

@media (prefers-reduced-motion: reduce) {
  #confetti { display: none; }
}
