/* Nancy's Story Studio
   A sticker-book look: cream background, white paper, thick plum outlines
   and chunky buttons that press down when tapped. */

:root {
  --ink: #2b2140;      /* outlines and text */
  --cream: #ffe9a8;    /* page background */
  --paper: #ffffff;
  --go: #5ee08a;       /* the main "yes, onwards" button */
  --sun: #ffd84a;      /* highlights and selected tools */
  --pink: #ff9ec4;

  /* Size of a round tool button. Scales with the screen so the toolbar
     always fits, and never drops below a comfortable finger size. */
  --b: clamp(44px, 8.4vh, 66px);
  --gap: clamp(7px, 1.2vh, 10px);

  font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
  color: var(--ink);
}

/* The page never scrolls, zooms or bounces. Only the gallery list scrolls. */
html,
body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--cream);
  background-image: radial-gradient(rgba(43, 33, 64, 0.09) 2px, transparent 2.5px);
  background-size: 28px 28px;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

/* ---------- Screens: one is shown at a time ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: none;
  box-sizing: border-box;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen.is-active {
  display: flex;
}

/* ---------- Buttons ---------- */

.btn {
  font-size: clamp(20px, 3.2vmin, 30px);
  font-weight: 800;
  line-height: 1.1;
  padding: 0.6em 1.1em;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 0 6px 0 var(--ink);
  white-space: nowrap;
}

.btn:active,
.btn-round:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--ink);
}

.btn-go {
  background: var(--go);
}

.btn-small {
  font-size: clamp(18px, 2.6vmin, 24px);
}

.btn-plain {
  border-color: transparent;
  background: none;
  box-shadow: none;
  font-size: clamp(17px, 2.4vmin, 22px);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.btn-round {
  flex: none;
  width: 60px;
  height: 60px;
  padding: 11px;
  border: 4px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 5px 0 var(--ink);
}

.btn-round svg,
.tool svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- 1. Draw ---------- */

#screen-draw {
  flex-direction: row-reverse; /* landscape: paper on the right, tools on the left */
}

.paper {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  margin: 12px 14px 18px 4px;
  border: 4px solid var(--ink);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: 0 6px 0 var(--ink);
  overflow: hidden;
}

#pad {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* no scrolling or zooming while drawing */
  cursor: crosshair;
}

.paper-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  font-size: clamp(24px, 5vmin, 44px);
  font-weight: 800;
  color: rgba(43, 33, 64, 0.22);
  pointer-events: none;
  transition: opacity 0.3s;
}

.paper-hint.is-gone {
  opacity: 0;
}

.tools {
  flex: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: calc(var(--gap) * 2);
  padding: 12px 12px 18px 14px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(4, var(--b));
  gap: var(--gap);
}

.swatch,
.tool {
  width: var(--b);
  height: var(--b);
  padding: 0;
  border: 3.5px solid var(--ink);
  border-radius: 50%;
  box-shadow: 0 4px 0 var(--ink);
}

.swatch {
  background: var(--c);
  transition: transform 0.12s;
}

.swatch.is-rainbow {
  background: conic-gradient(#f2332e, #ff8a1f, #ffd21f, #7ed321, #1cc8b8, #2459d8, #8a3fd1, #e0218a, #f2332e);
}

/* The chosen colour pops forward with a white ring inside it. */
.swatch.is-on {
  transform: scale(1.14);
  box-shadow: inset 0 0 0 5px var(--paper), 0 4px 0 var(--ink);
}

.tool {
  display: grid;
  place-items: center;
  background: var(--paper);
}

.tool svg {
  width: 62%;
  height: 62%;
}

.tool:active,
.swatch:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

.tool.is-on {
  background: var(--sun);
}

/* Brush size buttons show a dot of that size, in the chosen colour. */
.size i {
  width: var(--dot);
  height: var(--dot);
  border-radius: 50%;
  background: var(--brush, var(--ink));
}

#btn-done {
  font-size: clamp(24px, 4vmin, 34px);
}

/* Portrait: paper on top, tools in a bar along the bottom. */
@media (orientation: portrait) {
  :root {
    --b: clamp(44px, 8.6vw, 70px);
    --gap: clamp(7px, 1.2vw, 10px);
  }

  #screen-draw {
    flex-direction: column;
  }

  .paper {
    margin: 12px 14px 6px;
  }

  .tools {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: stretch;
    gap: calc(var(--gap) * 1.6) 14px;
    padding: 12px 14px 20px;
  }

  .tool-grid {
    grid-template-columns: repeat(8, var(--b));
    grid-column: 1;
  }

  #btn-done {
    grid-column: 2;
    grid-row: 1 / span 2;
    padding: 0.4em;
    border-radius: 28px;
    white-space: normal;
  }
}

/* ---------- 2. Describe ---------- */

/* Everything sits in the top half so the keyboard never covers it. */
#screen-ask,
#screen-signin {
  flex-direction: column;
  align-items: center;
}

.ask,
.grownups {
  box-sizing: border-box;
  width: min(940px, calc(100% - 28px));
  margin-top: clamp(10px, 2.5vh, 28px);
  padding: 18px 26px 26px;
  border: 4px solid var(--ink);
  border-radius: 34px;
  background: var(--paper);
  box-shadow: 0 8px 0 var(--ink);
}

.ask-top {
  display: flex;
  align-items: center;
  gap: 16px;
}

.dots {
  display: flex;
  gap: 12px;
  margin: 0 76px 0 auto; /* balances the back button so the dots sit centred */
  padding: 0;
  list-style: none;
  flex: 1;
  justify-content: center;
}

.dots li {
  width: 16px;
  height: 16px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  transition: transform 0.2s;
}

.dots li.is-done {
  background: var(--go);
}

.dots li.is-now {
  background: var(--sun);
  transform: scale(1.3);
}

.ask-body {
  display: flex;
  align-items: flex-start;
  gap: 26px;
  margin-top: 14px;
}

/* The child's drawing, shown as a little friend beside the question. */
.friend {
  flex: none;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  width: clamp(110px, 20vmin, 190px);
  aspect-ratio: 1;
  padding: 10px;
  border-radius: 26px;
  background: #fff6da;
}

.friend img {
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
}

.ask-form {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ask-question {
  font-size: clamp(26px, 4.6vmin, 44px);
  font-weight: 800;
  line-height: 1.15;
}

.ask-input {
  box-sizing: border-box;
  width: 100%;
  padding: 0.5em 0.7em;
  border: 4px solid var(--ink);
  border-radius: 22px;
  background: #fffdf5;
  color: var(--ink);
  font: inherit;
  font-size: clamp(24px, 4vmin, 36px);
  font-weight: 700;
  -webkit-user-select: text;
  user-select: text;
}

.ask-input::placeholder {
  color: rgba(43, 33, 64, 0.35);
}

.ask-input:focus {
  outline: 5px solid var(--sun);
  outline-offset: 2px;
}

.ask-hint {
  margin: 0;
  font-size: clamp(16px, 2.3vmin, 20px);
  line-height: 1.35;
  color: rgba(43, 33, 64, 0.7);
}

.ask-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 16px;
  margin-top: 4px;
}

/* ---------- 3. Wait ---------- */

#screen-wait {
  align-items: center;
  justify-content: center;
}

.wait {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(14px, 3vh, 28px);
  width: min(760px, calc(100% - 40px));
  text-align: center;
}

.friend-big {
  width: min(44vmin, 340px);
  background: none;
}

.bouncing img {
  animation: bounce 0.9s cubic-bezier(0.3, 0, 0.7, 1) infinite alternate;
  transform-origin: 50% 100%;
}

@keyframes bounce {
  from {
    transform: translateY(8%) scale(1.05, 0.95);
  }
  to {
    transform: translateY(-12%) scale(0.97, 1.03);
  }
}

.wait-message {
  margin: 0;
  min-height: 2.4em;
  font-size: clamp(24px, 4.4vmin, 40px);
  font-weight: 800;
  line-height: 1.2;
}

.progress {
  width: min(520px, 100%);
  height: 26px;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  overflow: hidden;
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff7eb6, #ffd21f, #7ed321, #3db7f5, #8a3fd1);
  background-size: 520px 100%;
  transition: width 1s linear;
}

/* ---------- 4. Watch ---------- */

.stage {
  position: absolute;
  inset: 0;
  background: var(--paper);
}

.stage iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.play-left,
.play-right {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
}

.play-left {
  left: calc(12px + env(safe-area-inset-left));
}

.play-right {
  right: calc(12px + env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 12px;
}

.play-trouble {
  position: absolute;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 14px 16px 22px;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 0 6px 0 var(--ink);
  font-size: clamp(18px, 2.6vmin, 24px);
  font-weight: 700;
  white-space: nowrap;
}

/* ---------- 5. Keep (gallery) ---------- */

#screen-gallery {
  flex-direction: column;
}

.gallery-top {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px 14px;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 5.4vmin, 50px);
  font-weight: 800;
  line-height: 1.1;
}

.gallery-scroll {
  flex: 1;
  min-height: 0;
  padding: 8px 22px 30px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 24px 20px;
}

.card {
  position: relative;
}

.card-open {
  display: block;
  width: 100%;
  padding: 10px 10px 14px;
  border: 4px solid var(--ink);
  border-radius: 26px;
  background: var(--paper);
  box-shadow: 0 6px 0 var(--ink);
  text-align: left;
}

.card-open:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--ink);
}

.card-paper {
  display: grid;
  place-items: center;
  box-sizing: border-box;
  aspect-ratio: 4 / 3;
  padding: 10px;
  border-radius: 16px;
  background: #fff6da;
}

.card-paper img {
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
}

.card-title {
  display: block;
  margin: 10px 4px 2px;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.2;
}

.card-date {
  display: block;
  margin: 0 4px;
  font-size: 16px;
  color: rgba(43, 33, 64, 0.65);
}

.card-bin {
  position: absolute;
  top: -10px;
  right: -8px;
  width: 46px;
  height: 46px;
  padding: 8px;
  border: 3.5px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 3px 0 var(--ink);
}

.card-bin svg {
  display: block;
  width: 100%;
  height: 100%;
}

.gallery-empty {
  margin: 12vh auto 0;
  max-width: 18em;
  font-size: clamp(22px, 3.6vmin, 32px);
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
}

/* ---------- Grown-ups (sign-in) ---------- */

.grownups {
  width: min(640px, calc(100% - 28px));
  padding-top: 24px;
}

.grownups form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 14px;
}

.code-input {
  text-align: center;
  letter-spacing: 0.35em;
  font-variant-numeric: tabular-nums;
}

.grownups p {
  margin: 0;
  font-size: clamp(17px, 2.4vmin, 21px);
  line-height: 1.4;
}

.grownups-status {
  min-height: 1.4em;
  font-weight: 700;
}

/* ---------- "Are you sure?" box and pop-up messages ---------- */

.dialog {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(43, 33, 64, 0.55);
}

.dialog-box {
  box-sizing: border-box;
  width: min(560px, 100%);
  padding: 26px 26px 28px;
  border: 4px solid var(--ink);
  border-radius: 34px;
  background: var(--paper);
  box-shadow: 0 8px 0 var(--ink);
  text-align: center;
}

.dialog-box p {
  margin: 0 0 22px;
  font-size: clamp(24px, 4vmin, 34px);
  font-weight: 800;
  line-height: 1.2;
}

.dialog-box .ask-buttons {
  justify-content: center;
}

.toast {
  position: absolute;
  left: 50%;
  top: calc(18px + env(safe-area-inset-top));
  z-index: 20;
  transform: translateX(-50%);
  max-width: calc(100% - 40px);
  padding: 14px 24px;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: var(--sun);
  box-shadow: 0 6px 0 var(--ink);
  font-size: clamp(19px, 2.8vmin, 26px);
  font-weight: 800;
  text-align: center;
  animation: drop-in 0.25s ease-out;
}

@keyframes drop-in {
  from {
    transform: translate(-50%, -40px);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bouncing img {
    animation-duration: 2.4s;
  }
}
