/* A goofy sticker-book: flat colours, thick ink outlines, hard offset shadows, nothing quite straight. */
:root {
  color-scheme: light;
  --ink: #241B2F;
  --paper: #FFF1D6;
  --card: #FFFBF2;
  --muted: #7A6158;
  --pink: #FF5E8A;
  --yellow: #FFD21E;
  --c: #FF5B3A;                                         /* current character's colour, set by app.js */
  --soft: color-mix(in srgb, var(--c) 24%, #FFF8EA);
  --ray: color-mix(in srgb, var(--c) 34%, #FFF8EA);
  --line: 3px solid var(--ink);
  --shadow: 4px 4px 0 var(--ink);
  --wob: 18px 26px 16px 28px / 26px 16px 28px 18px;     /* hand-cut corners */
  /* Fredoka for Latin; it has no CJK glyphs, so Chinese falls through to ZCOOL KuaiLe. */
  --fun: "Fredoka", "ZCOOL KuaiLe", "Hannotate SC", "HanziPen SC", "Wawati SC", "PingFang SC", system-ui, sans-serif;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; color: var(--ink); overflow: hidden;
  background-color: var(--paper);
  background-image: radial-gradient(color-mix(in srgb, var(--ink) 9%, transparent) 2px, transparent 2.5px);
  background-size: 22px 22px;
}
button { font: inherit; color: inherit; }

/* Doodles */
.doodles { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
.d { transform-box: fill-box; transform-origin: center; animation: bob 3s ease-in-out infinite alternate; }
.d2 { animation: spin 14s linear infinite; }
.d3, .d6 { animation-delay: -1.2s; }
.d4, .d8 { animation-delay: -2.1s; }
.d5 { animation: bob 1.1s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(-6px) rotate(-6deg); } to { transform: translateY(6px) rotate(6deg); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Loading: the page is built by app.js, so until it is complete only a "getting ready" sticker shows and
   the finished page then fades in at once — nothing jumps around while modules and the font arrive.
   The reveal animation is a safety net in case the script never runs. */
.loader { display: none; }
.loading .loader {
  display: block; position: fixed; left: 50%; top: 50%; z-index: 2; margin: 0; translate: -50% -50%;
  font: 400 20px/1 var(--fun); background: var(--card); border: var(--line); border-radius: var(--wob);
  box-shadow: var(--shadow); padding: 10px 18px 9px; animation: bob 0.6s ease-in-out infinite alternate;
}
.app { transition: opacity .25s; }
.loading .app { visibility: hidden; opacity: 0; animation: reveal 0s 4s forwards; }
@keyframes reveal { to { visibility: visible; opacity: 1; } }

/* Layout: stage on the left, everything you touch on the right. */
.app {
  position: relative; z-index: 1; height: 100svh; max-width: 1360px; margin: 0 auto;
  display: grid; gap: 14px 28px; padding: 22px 28px;
  grid-template-columns: minmax(0, 1fr) clamp(340px, 34vw, 430px);
  grid-template-rows: 1fr auto auto auto auto auto 1fr;
  grid-template-areas: "stage ." "stage head" "stage intro" "stage pick" "stage mood" "stage tools" "stage .";
  row-gap: 18px;
}
.head { grid-area: head; }
.stage-wrap { grid-area: stage; }
.intro { grid-area: intro; }
.pick { grid-area: pick; }
.mood { grid-area: mood; }
.tools { grid-area: tools; }

/* Header: a wobbling title where every glyph does its own thing. */
.date { margin: 0; font-size: 12px; letter-spacing: .14em; color: var(--muted); }
.title { margin: 2px 0 0; font: 400 34px/1.15 var(--fun); white-space: nowrap; }
.title span span {
  display: inline-block; animation: hop 1.6s ease-in-out infinite; animation-delay: calc(var(--i) * -0.13s);
  -webkit-text-stroke: 1px var(--ink); color: var(--k); text-shadow: 2px 2px 0 var(--ink);
}
@keyframes hop { 0%, 100% { transform: translateY(0) rotate(var(--r)); } 50% { transform: translateY(-5px) rotate(calc(var(--r) * -1)); } }

/* Stage: a comic panel in the character's colour, with sun rays turning behind it. */
.stage-wrap { container-type: size; display: grid; place-items: center; min-height: 0; min-width: 0; }
.stage {
  position: relative; width: min(100cqw, 100cqh); aspect-ratio: 1; overflow: hidden;
  background: var(--soft); border: 4px solid var(--ink); border-radius: 42px 58px 36px 64px / 60px 38px 62px 40px;
  box-shadow: 8px 8px 0 var(--ink); rotate: -1deg; transition: background-color .3s;
}
.stage.slap { animation: slap .45s cubic-bezier(.3, 1.8, .5, 1); }
.stage.boing { animation: boing .35s cubic-bezier(.3, 2, .5, 1); }
@keyframes slap { 0% { transform: rotate(-4deg) scale(.94); } 60% { transform: rotate(2deg) scale(1.02); } 100% { transform: none; } }
@keyframes boing { 0% { transform: scale(1.04, .95); } 50% { transform: scale(.98, 1.03); } 100% { transform: none; } }
.rays {
  position: absolute; inset: -40%;
  background: repeating-conic-gradient(var(--ray) 0 10deg, transparent 10deg 20deg);
  animation: spin 40s linear infinite; transition: background .3s;
}
.stage canvas {
  position: relative; display: block; width: 100%; height: 100%; cursor: pointer; outline: none;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.stage canvas:focus-visible { box-shadow: inset 0 0 0 5px var(--yellow); }
.nameplate {
  position: absolute; left: 5%; top: 5%; display: grid; justify-items: start; gap: 2px; rotate: -6deg; pointer-events: none;
}
.nameplate b {
  font: 400 clamp(22px, 5cqmin, 40px)/1 var(--fun); background: var(--card); border: var(--line);
  padding: 6px 14px 5px; border-radius: var(--wob); box-shadow: var(--shadow);
}
.nameplate span {
  font: 700 11px/1 ui-rounded, system-ui, sans-serif; letter-spacing: .2em; text-transform: uppercase;
  background: var(--ink); color: var(--card); padding: 4px 8px; border-radius: 6px; margin-left: 14px; rotate: 4deg;
}

/* Speech balloon with a tail. */
.bubble {
  position: absolute; right: 7%; top: 9%; max-width: 46%; padding: 10px 16px; font: 400 clamp(16px, 3.4cqmin, 24px)/1.25 var(--fun);
  background: #fff; border: var(--line); border-radius: 22px 30px 26px 20px; box-shadow: var(--shadow);
  opacity: 0; transform: scale(.3) rotate(-14deg); transform-origin: 20% 100%; pointer-events: none;
  transition: opacity .15s, transform .35s cubic-bezier(.3, 1.9, .5, 1);
}
.bubble::after {
  content: ""; position: absolute; left: 18%; bottom: -14px; width: 20px; height: 20px; background: #fff;
  border: var(--line); border-top: 0; border-left: 0; transform: rotate(40deg) skew(12deg, 12deg);
}
.bubble.show { opacity: 1; transform: rotate(4deg); }

/* The poke button is a comic "POW" burst. */
.poke {
  position: absolute; right: 4%; bottom: 4%; width: clamp(92px, 19cqmin, 136px); aspect-ratio: 1; padding: 0;
  border: 0; background: none; cursor: pointer; animation: throb 1.2s ease-in-out infinite;
}
.poke::before, .poke::after {
  content: ""; position: absolute; inset: 0; background: var(--ink);
  clip-path: polygon(50% 0, 61% 20%, 84% 8%, 80% 32%, 100% 40%, 82% 56%, 96% 78%, 71% 76%, 64% 100%, 50% 82%, 34% 100%, 28% 76%, 4% 80%, 18% 57%, 0 38%, 21% 31%, 15% 7%, 39% 20%);
}
.poke::before { translate: 4px 5px; }
.poke::after { inset: 5px; background: var(--yellow); }
.poke span { position: relative; z-index: 1; display: block; font: 400 clamp(15px, 3.2cqmin, 21px)/1 var(--fun); rotate: -10deg; }
.poke:hover { animation-duration: .4s; }
.poke:active { scale: .88; }
@keyframes throb { 0%, 100% { transform: rotate(-6deg) scale(1); } 50% { transform: rotate(5deg) scale(1.07); } }

.intro {
  margin: 0; justify-self: start; font-size: 13.5px; background: var(--card); border: 2px dashed var(--ink);
  padding: 7px 12px; border-radius: 12px; rotate: .6deg;
}

/* Sticker sections */
.pick, .mood { position: relative; background: var(--card); border: var(--line); border-radius: var(--wob); box-shadow: var(--shadow); padding: 20px 14px 14px; }
.mood { rotate: -.6deg; }
.tag {
  position: absolute; left: 14px; top: -14px; margin: 0; font: 400 16px/1 var(--fun); background: var(--pink); color: #fff;
  border: var(--line); padding: 5px 12px 4px; border-radius: 10px; rotate: -4deg; box-shadow: 2px 2px 0 var(--ink);
}
.mood .tag { background: var(--yellow); color: var(--ink); rotate: 3deg; }

.roster { display: grid; gap: 10px; }
.squad { display: grid; gap: 6px; }
.squad-name { margin: 0; font: 400 13px/1 var(--fun); color: var(--muted); }
.squad-row { display: flex; flex-wrap: wrap; gap: 6px; }
.avatar {
  --c: #ccc; display: grid; justify-items: center; gap: 1px; width: 58px; padding: 4px 0 5px; font-size: 11.5px; line-height: 1.2;
  background: #fff; border: 2.5px solid var(--ink); border-radius: 14px 18px 12px 18px; cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink); rotate: var(--r, 0deg); transition: transform .15s cubic-bezier(.3, 2, .5, 1), background-color .2s;
}
.avatar canvas { width: 46px; height: 46px; }
@media (min-width: 1200px) and (min-height: 860px) { .avatar { width: 62px; } .avatar canvas { width: 50px; height: 50px; } .title { font-size: 38px; } }
.avatar:hover { transform: translateY(-3px) rotate(4deg); }
.avatar:active { transform: scale(.9); }
.avatar[aria-pressed=true] { background: color-mix(in srgb, var(--c) 45%, #fff); font-weight: 700; transform: scale(1.08); box-shadow: 3px 3px 0 var(--ink); animation: wiggle 1s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { rotate: -4deg; } 50% { rotate: 4deg; } }

.states { display: flex; flex-wrap: wrap; gap: 8px 7px; }
.chip {
  font-size: 13.5px; background: #fff; border: 2.5px solid var(--ink); border-radius: 999px 820px 900px 760px;
  padding: 4px 12px; cursor: pointer; box-shadow: 2px 2px 0 var(--ink); rotate: var(--r, 0deg);
  transition: transform .15s cubic-bezier(.3, 2, .5, 1);
}
.chip:hover { transform: translateY(-2px) rotate(-5deg); }
.chip:active { transform: scale(.9); }
.chip[aria-pressed=true] { background: var(--c); color: #fff; font-weight: 700; -webkit-text-stroke: .4px var(--ink); text-shadow: 1px 1px 0 var(--ink); transform: scale(1.1); }

.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 4px; }
.btn {
  font: 400 15px/1 var(--fun); background: #fff; border: var(--line); padding: 8px 14px; border-radius: 14px 10px 16px 9px;
  box-shadow: 3px 3px 0 var(--ink); cursor: pointer; transition: transform .1s, box-shadow .1s;
}
.btn:hover { transform: rotate(-3deg); }
.btn:active, .btn[aria-pressed=true] { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.btn[aria-pressed=true] { background: var(--yellow); }
.sep { flex: 1; }
.stamp {
  font-size: 12px; color: var(--muted); background: none; border: 2px dashed currentColor; border-radius: 8px;
  padding: 3px 7px; cursor: pointer; text-decoration: none; rotate: -2deg;
}
.stamp:nth-of-type(even) { rotate: 2deg; }
.stamp:hover { color: var(--ink); background: var(--card); }

button:focus-visible, a:focus-visible { outline: 3px solid var(--pink); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Short desktop windows: tighten the right column so it still fits without scrolling. */
@media (min-width: 860px) and (max-height: 760px) {
  .app { gap: 10px 24px; padding-block: 14px; }
  .title { font-size: 28px; }
  .avatar { width: 52px; } .avatar canvas { width: 40px; height: 40px; }
  .chip { padding: 3px 10px; font-size: 13px; }
}

/* Narrow screens: stage on top, pickers become sideways-swipe strips so the page itself never scrolls. */
@media (max-width: 859px) {
  .app {
    gap: 10px; padding: max(10px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
    grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto auto auto auto;
    grid-template-areas: "head" "stage" "intro" "pick" "mood" "tools";
  }
  .head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
  .title { font-size: 23px; }
  .date { order: 2; font-size: 11px; letter-spacing: .06em; }
  .stage { border-width: 3px; box-shadow: 5px 5px 0 var(--ink); }
  .intro { justify-self: stretch; font-size: 12.5px; padding: 4px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .pick, .mood { padding: 14px 0 8px; border-radius: 16px 22px 14px 24px; }
  .tag { font-size: 13px; top: -11px; left: 10px; padding: 3px 9px 2px; }
  .roster, .states {
    display: flex; flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x proximity; overscroll-behavior-x: contain;
    padding: 4px 12px 6px; gap: 10px; scrollbar-width: none;
  }
  .roster::-webkit-scrollbar, .states::-webkit-scrollbar { display: none; }
  .squad { display: flex; align-items: center; gap: 6px; flex: none; }
  .squad-name { writing-mode: vertical-rl; font-size: 11px; letter-spacing: .1em; padding: 4px 2px; border-left: 2px dashed var(--muted); }
  .squad-row { flex-wrap: nowrap; }
  .avatar { flex: none; scroll-snap-align: start; width: 52px; }
  .avatar canvas { width: 40px; height: 40px; }
  .chip { flex: none; scroll-snap-align: start; padding: 3px 11px; }

  /* One row on a phone: the language button would otherwise wrap onto a line of its own. */
  .tools { gap: 5px; flex-wrap: nowrap; }
  .sep { min-width: 0; }
  .btn { font-size: 13px; padding: 6px 8px; }
  .stamp { font-size: 11px; padding: 2px 4px; white-space: nowrap; }
}
/* Tiny/landscape phones: allow the page to scroll rather than crushing the stage. */
@media (max-width: 859px) and (max-height: 560px) {
  body { overflow: auto; }
  .app { height: auto; grid-template-rows: auto min(80vw, 420px) auto auto auto auto; }
}
@media (min-width: 860px) and (max-height: 600px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 600px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .loading .app { animation: reveal 0s 4s forwards !important; }   /* keep the safety net */
}
