/* Paper Pop: shared look for every game page. Spec: design/mobile-design.md §7, design/paper-pop.html.
   Each page sets its field color with <body style="--field: var(--grape)"> (or UI.field()). */

/* Unbounded (SIL Open Font License), self-hosted for offline use. Variable font: weights 500-900. */
@font-face {
  font-family: "Unbounded"; font-style: normal; font-weight: 500 900; font-display: swap;
  src: url("fonts/unbounded-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Unbounded"; font-style: normal; font-weight: 500 900; font-display: swap;
  src: url("fonts/unbounded-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Unbounded"; font-style: normal; font-weight: 500 900; font-display: swap;
  src: url("fonts/unbounded-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --cobalt: #2f4bff; --tomato: #ff5b3a; --grass: #19a463; --grape: #7b4dff;
  --lagoon: #0fa3c4; --sunflower: #ffbe1a; --bubblegum: #ff6fae; --cocoa: #b0673a; --plum: #a23e8c; --carrot: #ee7a1e;
  --ink: #1c1f4a; --paper: #fff; --sun: #ffd23a; --mint: #7be0a1; --pink: #ff9bd2;
  --drop: rgba(28, 31, 74, .28);
  --field: var(--cobalt);
  --on-field: #fff;           /* type and icons drawn straight on the field */
  --font: "Unbounded", system-ui, sans-serif;
  --slap: cubic-bezier(.2, 1.5, .45, 1);
  /* HUD: one 80 pt row in portrait; floating corners in short landscape (see below) */
  --safe-t: max(12px, env(safe-area-inset-top));
  --safe-b: max(12px, env(safe-area-inset-bottom));
  --safe-l: max(16px, env(safe-area-inset-left));
  --safe-r: max(16px, env(safe-area-inset-right));
  --hud-h: 80px;
  --side: 0px;
}
@media (orientation: landscape) and (max-height: 480px) {
  :root { --hud-h: 0px; --side: 88px; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--field); color: var(--on-field);
  font-family: var(--font); font-weight: 800;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
  transition: background-color .4s ease;
}
button { font-family: inherit; }
.ic { width: 52%; height: 52%; display: block; pointer-events: none; }

/* ---------- HUD ---------- */
.hud {
  position: relative; z-index: 30; flex: none;
  height: calc(var(--safe-t) + var(--hud-h));
  padding: var(--safe-t) var(--safe-r) 0 var(--safe-l);
  display: flex; align-items: center; gap: 16px;
}
@media (orientation: landscape) and (max-height: 480px) {
  .hud { position: absolute; left: 0; right: 0; top: 0; height: auto; padding-top: 12px; pointer-events: none; }
  .hud > * { pointer-events: auto; }
  .hud .stars { position: absolute; left: 50%; translate: -50% 0; top: 22px; }
}
.hud-home {
  position: relative; flex: none; width: 64px; height: 64px; border-radius: 22px; border: 0; padding: 0;
  background: var(--paper); color: var(--field); box-shadow: 0 6px 0 var(--drop);
  display: grid; place-items: center; cursor: pointer; text-decoration: none;
  transition: translate .1s ease-out, box-shadow .1s ease-out;
}
body.ink .hud-home { color: var(--ink); }
.hud-home:active { translate: 0 4px; box-shadow: 0 2px 0 var(--drop); }
/* hold-to-exit ring, driven by --p (0..1) from ui.js */
.hud-home::after {
  content: ""; position: absolute; inset: -8px; border-radius: 28px; pointer-events: none;
  background: conic-gradient(var(--sun) calc(var(--p, 0) * 360deg), transparent 0);
  -webkit-mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  padding: 6px; opacity: 0; transition: opacity .15s;
}
.hud-home.holding::after { opacity: 1; }
.hud-home.nudge { animation: nudge .45s ease; }
.hud-home.nudge::after { opacity: .5; --p: .3; }
@keyframes nudge { 25% { rotate: -8deg; } 50% { rotate: 7deg; } 75% { rotate: -4deg; } }

.stars { display: flex; gap: 6px; align-items: center; }
.stars .ic { width: 28px; height: 28px; color: rgba(255,255,255,.35); transition: color .3s; }
body.ink .stars .ic { color: rgba(28,31,74,.18); }
.stars .ic.on { color: var(--sun); }
.stars .ic.new { animation: starpop .5s var(--slap); }
@keyframes starpop { from { scale: .3; rotate: -40deg; } }

/* ---------- sticker ---------- */
.stk {
  position: relative; border: 8px solid var(--paper); border-radius: 28px; overflow: hidden;
  background: var(--c, #fce8da); box-shadow: 0 10px 0 var(--drop);
  rotate: var(--tilt, 0deg); padding: 0;
  transition: rotate .3s var(--slap), translate .1s ease-out, box-shadow .1s ease-out, scale .3s var(--slap), opacity .3s, filter .3s;
}
.stk.sm { border-width: 6px; border-radius: 22px; box-shadow: 0 7px 0 var(--drop); }
.stk > img { width: 100%; height: 100%; display: block; pointer-events: none; -webkit-user-drag: none; }
.stk.crop > img { object-fit: cover; object-position: 50% 10%; }
.stk.fit > img { object-fit: contain; object-position: 50% 100%; padding: 8px 6px 4px; }
button.stk, a.stk { cursor: pointer; }
.stk.press:active { rotate: 0deg; translate: 0 6px; box-shadow: 0 3px 0 var(--drop); }
.stk.slap { animation: slap .38s var(--slap) both; }
@keyframes slap { from { scale: 1.25; opacity: 0; rotate: calc(var(--tilt, 0deg) * -2); } }
.stk.peel { rotate: 0deg; scale: 1.12; z-index: 5; animation: wiggle .5s ease-in-out .1s; }
@keyframes wiggle { 25% { rotate: -6deg; } 50% { rotate: 5deg; } 75% { rotate: -3deg; } }
.stk.droop { rotate: calc(var(--tilt, 0deg) + 10deg); translate: 0 8px; filter: saturate(.4); opacity: .45; pointer-events: none; }

/* icon chip on a sticker's corner */
.chip {
  position: absolute; width: 48px; height: 48px; border-radius: 50%;
  border: 4px solid var(--paper); background: var(--sun); color: var(--ink);
  display: grid; place-items: center; box-shadow: 0 5px 0 var(--drop); pointer-events: none;
}

/* ---------- buttons ---------- */
.act {
  width: var(--s, 108px); height: var(--s, 108px); border-radius: 34%; border: 0; padding: 0;
  background: var(--sun); color: var(--ink); box-shadow: 0 9px 0 var(--drop);
  display: grid; place-items: center; cursor: pointer; flex: none;
  transition: translate .1s ease-out, box-shadow .1s ease-out;
}
.act.paper { background: var(--paper); }
.act.mint { background: var(--mint); }
.act.pink { background: var(--pink); }
.act:active { translate: 0 6px; box-shadow: 0 3px 0 var(--drop); }
.act.playing { animation: breathe .5s ease-in-out infinite alternate; }
@keyframes breathe { to { scale: 1.06; } }

/* ---------- name tape / speech tape ---------- */
.tape {
  position: absolute; z-index: 25; pointer-events: none; white-space: nowrap;
  background: var(--paper); color: var(--ink); font-weight: 800; font-size: 30px; line-height: 1.15;
  padding: .28em .8em .34em; rotate: var(--rot, -3deg);
  clip-path: polygon(0 6%, 3% 0, 6% 8%, 9% 0, 91% 0, 94% 8%, 97% 0, 100% 6%, 100% 94%, 97% 100%, 94% 92%, 91% 100%, 9% 100%, 6% 92%, 3% 100%, 0 94%);
  filter: drop-shadow(0 5px 0 var(--drop));
}
.tape.say { font-weight: 700; font-size: 22px; --rot: 4deg; }
.tape.hide { opacity: 0; }
.tape.show { animation: tape 2s ease both; }
.tape.stay { animation: tapein .3s var(--slap) both; }
@keyframes tape {
  0% { scale: 1.6; opacity: 0; }
  14% { scale: 1; opacity: 1; }
  82% { opacity: 1; }
  100% { opacity: 0; translate: var(--tx, 0) -12px; }
}
@keyframes tapein { from { scale: 1.6; opacity: 0; } }
/* small phones: the longest tapes ("Cock-a-doodle-doo!", "Белый мишка") must fit the safe width */
@media (max-width: 360px) {
  .tape { font-size: 26px; }
  .tape.say { font-size: 19px; }
}
@media (min-width: 700px) and (min-height: 700px) {
  .tape { font-size: 44px; }
  .tape.say { font-size: 32px; }
}

/* ---------- paper confetti ---------- */
.conf {
  position: fixed; z-index: 20; width: 16px; height: 16px; pointer-events: none;
  animation: conf var(--d, 1.2s) cubic-bezier(.25, .6, .5, 1) forwards;
}
@keyframes conf {
  0% { translate: 0 0; rotate: 0deg; opacity: 1; }
  25% { translate: calc(var(--dx) * .5) var(--up); }
  100% { translate: var(--dx) var(--dy); rotate: var(--r); opacity: 0; }
}

/* ---------- tap-to-start overlay (web only: iOS needs a tap per page before audio) ---------- */
.start {
  position: fixed; inset: 0; z-index: 40; background: var(--field);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); text-align: center;
}
.start[hidden] { display: none; }
.start .hud-home { position: absolute; left: var(--safe-l); top: var(--safe-t); }
.start h1 {
  margin: 0; font-weight: 900; font-size: clamp(30px, 10vw, 72px); line-height: .94; letter-spacing: -.02em;
  color: var(--on-field); text-shadow: 0 4px 0 var(--drop); max-width: 12ch;
}
/* Rule: ▶ never shrinks. The art is sized so 2 or 3 stickers fit the width, and the title wraps/shrinks before ▶ does. */
.start .peek { display: flex; gap: 18px; align-items: flex-end; height: min(30vh, 46vw); flex: none; }
.start .peek:has(> :nth-child(3)) { height: min(30vh, 34vw); }
.start .peek .stk { height: 100%; aspect-ratio: 3 / 4; }
.start .peek .stk:nth-child(2) { height: 88%; }
.start h1 { min-width: 0; flex: 0 1 auto; overflow-wrap: anywhere; }
.play {
  flex: none;
  width: 132px; height: 132px; border-radius: 34%; border: 0; padding: 0; cursor: pointer;
  background: var(--sun); color: var(--ink); box-shadow: 0 10px 0 var(--drop);
  display: grid; place-items: center; animation: breathe 1.2s ease-in-out infinite alternate;
}
.play:active { translate: 0 6px; box-shadow: 0 3px 0 var(--drop); }
@media (orientation: landscape) and (max-height: 480px) {
  .start { flex-direction: row; gap: 32px; }
  .start .peek { height: min(60vh, 28vw); }
  .start .peek:has(> :nth-child(3)) { height: min(60vh, 18vw); }
  .start h1 { font-size: clamp(26px, 5vw, 44px); }
  .play { width: 108px; height: 108px; }
}

/* iris: the next screen's field color grows out of the tapped tile */
.iris {
  position: fixed; z-index: 60; border-radius: 50%; pointer-events: none;
  width: 20px; height: 20px; translate: -50% -50%; scale: 0;
  transition: scale .42s cubic-bezier(.6, 0, .4, 1);
}

/* ---------- parent gate + settings (Home only) ---------- */
.parent-layer {
  position: fixed; inset: 0; z-index: 80; background: var(--cobalt); color: var(--ink);
  display: flex; align-items: center; justify-content: center; padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}
.parent-layer .close { position: absolute; left: var(--safe-l); top: var(--safe-t); }
.gate-card {
  width: min(360px, 100%); background: var(--paper); border-radius: 32px; box-shadow: 0 10px 0 var(--drop);
  padding: 28px 20px 24px; text-align: center;
}
.gate-card h2 { margin: 0 0 6px; font-size: 24px; }
.gate-card p { margin: 0; font: 500 16px/1.4 system-ui, -apple-system, sans-serif; }
.gate-card .words { font-size: 22px; font-weight: 700; margin: 4px 0 16px; }
.gate-dots { display: flex; justify-content: center; gap: 14px; margin-bottom: 18px; }
.gate-dots i { width: 16px; height: 16px; border-radius: 50%; border: 3px solid #c9cdf0; }
.gate-dots i.on { background: var(--cobalt); border-color: var(--cobalt); }
.keys { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; justify-content: center; }
.keys button {
  width: 72px; height: 72px; border-radius: 22px; border: 0; background: #eef0ff; color: var(--ink);
  font: 800 28px var(--font); box-shadow: 0 4px 0 rgba(28,31,74,.14); cursor: pointer;
}
.keys button:active { translate: 0 3px; box-shadow: 0 1px 0 rgba(28,31,74,.14); }
.settings {
  position: fixed; inset: 0; z-index: 80; background: #f5f6ff; color: var(--ink); overflow: auto;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  font: 500 16px/1.45 system-ui, -apple-system, sans-serif; user-select: text;
}
.settings .bar { display: flex; justify-content: space-between; align-items: center; max-width: 560px; margin: 8px auto 16px; }
.settings h2 { font: 800 28px var(--font); margin: 0; }
.settings .done { border: 0; background: none; color: var(--cobalt); font: 700 17px system-ui, sans-serif; padding: 10px; cursor: pointer; }
.settings section { max-width: 560px; margin: 0 auto 26px; }
.settings h3 { font-size: 15px; font-weight: 700; margin: 0 0 8px; }
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; min-height: 48px; border: 0; border-radius: 14px; background: #e4e7fb; color: var(--ink);
  font: 600 15px system-ui, -apple-system, sans-serif; cursor: pointer;
}
.seg button.on { background: var(--cobalt); color: #fff; }
.settings .help { color: #5a5d86; font-size: 14px; }

/* gear: parent entry, deliberately low-key; needs a 2 s hold */
.gear {
  position: absolute; width: 44px; height: 44px; border: 0; padding: 0; background: none; color: var(--on-field);
  opacity: .5; display: grid; place-items: center; cursor: pointer; border-radius: 50%;
}
.gear .ic { width: 26px; height: 26px; }
.gear::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; padding: 4px; opacity: 0;
  background: conic-gradient(#fff calc(var(--p, 0) * 360deg), transparent 0);
  -webkit-mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}
.gear.holding { opacity: 1; }
.gear.holding::after { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .play, .act.playing { animation: none; }
  .stk.peel { animation: none; }
  .stk.slap { animation-duration: .2s; animation-timing-function: ease-out; }
  .iris { transition-duration: 0s; }
  .conf { animation-duration: 1.2s; animation-name: conf-still; }
  @keyframes conf-still {
    from { translate: calc(var(--dx) * .6) calc(var(--up) * -.2); rotate: var(--r); opacity: 1; }
    to { translate: calc(var(--dx) * .6) calc(var(--up) * -.2); rotate: var(--r); opacity: 0; }
  }
}
