/* ============================================================
   Cutie UI kit — cozy paper-and-ink game UI.
   Reusable on any page: include ui.css + js/ui.js.
   Everything is themed through the custom properties below.
   See /kit.html for a live sampler of every component.
   ============================================================ */

@font-face {
  font-family: 'Fredoka';
  src: url('../fonts/fredoka.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --cq-ink: #5b3a31;
  --cq-ink-soft: #8a6455;
  --cq-paper: #fff3e0;
  --cq-paper-2: #fde4c6;
  --cq-peach: #f5c6a3;
  --cq-peach-deep: #e2a17c;
  --cq-rose: #ef8274;
  --cq-pink: #ff9fb5;
  --cq-gold: #fbd070;
  --cq-gold-deep: #eda94b;
  --cq-mint: #8ee5c8;
  --cq-mint-deep: #4fc3a0;
  --cq-lilac: #c5b2f0;
  --cq-track: #b98058;
  --cq-sky-1: #7f88ad;
  --cq-sky-2: #c9b7c6;
  --cq-radius: 18px;
  --cq-line: 3px;
  --cq-font: 'Fredoka', ui-rounded, 'Nunito', 'Trebuchet MS', system-ui, sans-serif;
  --cq-bounce: cubic-bezier(.34, 1.56, .64, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.cq {
  margin: 0;
  font-family: var(--cq-font);
  font-weight: 500;
  font-size: 16px;
  line-height: 1.35;
  color: var(--cq-ink);
  background:
    radial-gradient(ellipse 150px 46px at 18% 12%, #ffffff40 0 60%, transparent 62%),
    radial-gradient(ellipse 110px 34px at 30% 14.5%, #ffffff40 0 60%, transparent 62%),
    radial-gradient(ellipse 170px 50px at 86% 30%, #ffffff33 0 60%, transparent 62%),
    radial-gradient(ellipse 120px 38px at 10% 62%, #ffffff26 0 60%, transparent 62%),
    linear-gradient(180deg, var(--cq-sky-1), var(--cq-sky-2) 70%, #e9c9bd);
  background-attachment: fixed;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior-y: none;
}
body.cq.auth-screen {
  /* The PWA chrome uses --cq-sky-1. Match it at both viewport edges while
     keeping a little depth behind the login card. */
  background:
    radial-gradient(ellipse 150px 46px at 18% 12%, #ffffff40 0 60%, transparent 62%),
    radial-gradient(ellipse 170px 50px at 86% 30%, #ffffff33 0 60%, transparent 62%),
    linear-gradient(180deg, var(--cq-sky-1), #a59db8 56%, var(--cq-sky-1));
  background-attachment: fixed;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-user-select: none; user-select: none; }
:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* ---------- panel: peach frame, paper inside ---------- */
cq-panel {
  display: block;
  position: relative;
  background: var(--cq-paper);
  border: var(--cq-line) solid var(--cq-ink);
  border-radius: var(--cq-radius);
  box-shadow: inset 0 0 0 6px var(--cq-peach), inset 0 0 0 8px #5b3a3130, 0 6px 0 #5b3a3155;
  padding: 22px 18px 18px;
}
cq-panel[tone="mint"] { box-shadow: inset 0 0 0 6px var(--cq-mint), inset 0 0 0 8px #5b3a3130, 0 6px 0 #5b3a3155; }
cq-panel[tone="lilac"] { box-shadow: inset 0 0 0 6px var(--cq-lilac), inset 0 0 0 8px #5b3a3130, 0 6px 0 #5b3a3155; }

/* ---------- ribbon: notched banner title, sits on a panel's top-left ---------- */
cq-ribbon {
  display: inline-block;
  position: relative;
  isolation: isolate;
  padding: 6px 30px 6px 16px;
  font-weight: 700;
  font-size: 1.15rem;
  filter: drop-shadow(2px 0 0 var(--cq-ink)) drop-shadow(-2px 0 0 var(--cq-ink)) drop-shadow(0 2px 0 var(--cq-ink)) drop-shadow(0 -2px 0 var(--cq-ink));
}
cq-ribbon::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--cq-rose);
  clip-path: polygon(0 0, 100% 0, calc(100% - 12px) 50%, 100% 100%, 0 100%);
}
cq-ribbon[tone="gold"]::before { background: var(--cq-gold); }
cq-ribbon[tone="mint"]::before { background: var(--cq-mint); }
cq-ribbon[tone="lilac"]::before { background: var(--cq-lilac); }
cq-panel > cq-ribbon:first-child { margin: -36px 0 10px -26px; display: table; transform: rotate(-1.5deg); }

/* ---------- card: a paper note with a folded corner ---------- */
cq-card {
  display: block;
  position: relative;
  background: var(--cq-paper-2);
  border: var(--cq-line) solid var(--cq-ink);
  border-radius: 14px 14px 14px 14px;
  padding: 12px;
  box-shadow: 0 4px 0 #5b3a3140;
}
cq-card::after {
  content: '';
  position: absolute;
  right: -3px; bottom: -3px;
  width: 18px; height: 18px;
  background: linear-gradient(135deg, var(--cq-peach-deep) 0 50%, transparent 50%);
  border-top: var(--cq-line) solid var(--cq-ink);
  border-left: var(--cq-line) solid var(--cq-ink);
  border-radius: 8px 0 12px 0;
  background-color: var(--cq-paper);
}

/* ---------- buttons ---------- */
.cq-btn {
  --b: var(--cq-gold);
  --b2: var(--cq-gold-deep);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 18px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--cq-ink);
  background: linear-gradient(180deg, #ffffff80 0 12%, transparent 13%), linear-gradient(180deg, var(--b), var(--b2));
  border: var(--cq-line) solid var(--cq-ink);
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--cq-ink);
  transition: transform .12s var(--cq-bounce), box-shadow .12s;
  text-decoration: none;
  white-space: nowrap;
}
.cq-btn:active { transform: translateY(3px) scale(.97); box-shadow: 0 1px 0 var(--cq-ink); }
.cq-btn.mint { --b: #a5f0d6; --b2: var(--cq-mint-deep); }
.cq-btn.rose { --b: #ffb1a3; --b2: var(--cq-rose); }
.cq-btn.pink { --b: #ffc3d1; --b2: var(--cq-pink); }
.cq-btn.lilac { --b: #ddd0fa; --b2: #a88fe6; }
.cq-btn.paper { --b: var(--cq-paper); --b2: var(--cq-paper-2); }
.cq-btn.sm { min-height: 36px; padding: 2px 13px; font-size: .95rem; box-shadow: 0 3px 0 var(--cq-ink); }
.cq-btn.lg { min-height: 54px; padding: 8px 28px; font-size: 1.25rem; }
.cq-btn.block { display: flex; width: 100%; }
.cq-btn.round { width: 44px; padding: 0; }
.cq-btn.sm.round { width: 36px; }
.cq-btn:disabled, .cq-btn[aria-disabled="true"] { filter: grayscale(.7); opacity: .6; pointer-events: none; }
.cq-btn svg { width: 1.25em; height: 1.25em; flex: none; }

/* ---------- chips & stamps ---------- */
cq-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 9px;
  font-size: .8rem; font-weight: 600;
  background: #f4c9a4;
  border-radius: 999px;
  white-space: nowrap;
}
cq-chip[tone="mint"] { background: #b9efdc; }
cq-chip[tone="pink"] { background: #ffc8d4; }
cq-chip[tone="gold"] { background: #ffe19a; }
cq-chip svg { width: 1.1em; height: 1.1em; }

cq-stamp {
  display: inline-grid; place-items: center;
  padding: 4px 10px;
  font-weight: 700; font-size: .95rem;
  color: #3f9f7c;
  border: 3px dashed #55b792;
  outline: 3px solid #55b792; outline-offset: 2px;
  border-radius: 999px;
  background: #c9f2e0cc;
  transform: rotate(-10deg);
  animation: cq-stamp .45s var(--cq-bounce) both;
}
cq-stamp[tone="gold"] { color: #b9791f; border-color: #e0a23c; outline-color: #e0a23c; background: #ffeab5cc; }
@keyframes cq-stamp { from { transform: rotate(-10deg) scale(2.2); opacity: 0; } }

/* ---------- currency pill ---------- */
cq-pill {
  display: inline-flex; align-items: center;
  height: 30px; min-width: 76px;
  padding: 0 12px 0 0;
  background: var(--cq-paper);
  border: 2.5px solid var(--cq-ink);
  border-radius: 999px;
  font-weight: 700;
  box-shadow: 0 3px 0 #5b3a3140;
}
cq-pill .cq-pill-ic { width: 36px; height: 36px; margin: 0 6px 0 -8px; flex: none; }
cq-pill .cq-pill-ic svg { width: 100%; height: 100%; display: block; }
cq-pill.bump { animation: cq-bump .5s var(--cq-bounce); }
@keyframes cq-bump { 30% { transform: scale(1.22) rotate(-3deg); } }

/* ---------- progress bar with star milestones and a runner ---------- */
cq-bar { display: block; position: relative; padding: 12px 0 6px; --fill-a: #ffe08f; --fill-b: var(--cq-gold-deep); }
cq-bar[tone="pink"] { --fill-a: #ffc6d3; --fill-b: #f7809c; }
cq-bar[tone="mint"], cq-bar.full { --fill-a: #b4f3df; --fill-b: var(--cq-mint-deep); }
cq-bar[tone="lilac"] { --fill-a: #ddd0fa; --fill-b: #a88fe6; }
.cq-bar-track {
  position: relative; height: 24px;
  background: var(--cq-track);
  border: var(--cq-line) solid var(--cq-ink);
  border-radius: 999px;
  overflow: hidden;
}
.cq-bar-fill {
  position: absolute; inset: 0 auto 0 0;
  width: 0; min-width: 0;
  background: linear-gradient(180deg, #ffffff8c 0 22%, transparent 23%), linear-gradient(180deg, var(--fill-a), var(--fill-b));
  border-radius: 999px;
  transition: width .9s var(--cq-bounce);
}
.cq-bar-label {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 700; font-size: .85rem; color: #fff8ea;
  text-shadow: 0 1.5px 0 var(--cq-ink), 1.5px 0 0 var(--cq-ink), -1.5px 0 0 var(--cq-ink), 0 -1.5px 0 var(--cq-ink);
  letter-spacing: .02em;
}
.cq-bar-star {
  position: absolute; top: 0; width: 24px; height: 24px; margin-left: -12px; z-index: 1;
  transition: transform .4s var(--cq-bounce);
}
.cq-bar-star svg { width: 100%; height: 100%; display: block; }
.cq-bar-star.lit { transform: scale(1.15) rotate(-8deg); }
.cq-bar-star.pop { animation: cq-starpop .7s var(--cq-bounce); }
@keyframes cq-starpop { 40% { transform: scale(2) rotate(20deg); } }
.cq-bar-runner {
  position: absolute; top: 5px; left: 0; z-index: 2;
  width: 40px; height: 40px; margin-left: -20px;
  transition: left .9s var(--cq-bounce);
  pointer-events: none;
}
.cq-bar-runner > * {
  display: block; width: 100%; height: 100%;
  border-radius: 50%; overflow: hidden;
  border: 2.5px solid var(--cq-ink); background: var(--cq-paper);
  box-shadow: 0 2px 0 #5b3a3155;
}
cq-bar.moving .cq-bar-runner > * { animation: cq-hop .3s ease-in-out 3; }
@keyframes cq-hop { 50% { transform: translateY(-7px) rotate(6deg); } }
cq-bar:has(.cq-bar-runner) { padding: 12px 20px 6px; }

/* ---------- tabs: paper notes pinned along an edge ---------- */
cq-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 4px 2px 0; }
cq-tabs::-webkit-scrollbar { display: none; }
cq-tab {
  flex: 1 0 auto;
  display: grid; place-items: center;
  min-height: 42px; padding: 4px 12px;
  font-weight: 700;
  background: var(--cq-peach);
  border: var(--cq-line) solid var(--cq-ink);
  border-bottom-width: 0;
  border-radius: 12px 12px 0 0;
  cursor: pointer;
  transform: translateY(5px);
  transition: transform .15s var(--cq-bounce), background .15s;
  -webkit-user-select: none; user-select: none;
}
cq-tab[selected] { background: var(--cq-paper); transform: translateY(0); }
cq-tabs + cq-panel { border-top-left-radius: 6px; border-top-right-radius: 6px; }

/* ---------- forms ---------- */
.cq-field { display: block; margin: 0 0 12px; }
.cq-field > span { display: block; font-weight: 700; font-size: .9rem; margin: 0 0 4px 4px; }
.cq-input {
  width: 100%; min-height: 44px; padding: 6px 14px;
  background: #fffaf1;
  border: var(--cq-line) solid var(--cq-ink);
  border-radius: 14px;
  font-weight: 600; font-size: 1rem;
  box-shadow: inset 0 3px 0 #5b3a3118;
  -webkit-appearance: none; appearance: none;
}
.cq-input::placeholder { color: #c3a392; }
.cq-input:focus { outline: none; background: #fff; box-shadow: inset 0 3px 0 #5b3a3118, 0 0 0 3px var(--cq-gold); }
.cq-row { display: flex; gap: 8px; align-items: center; }
.cq-row > .grow { flex: 1; min-width: 0; }
/* segmented choice: <div class="cq-seg"><button aria-pressed="true">A</button>…</div> */
.cq-seg { display: flex; gap: 6px; }
.cq-seg > button {
  flex: 1; min-height: 42px; padding: 4px 8px;
  font-weight: 700;
  background: var(--cq-paper-2);
  border: var(--cq-line) solid var(--cq-ink);
  border-radius: 12px;
  box-shadow: 0 3px 0 var(--cq-ink);
  transition: transform .12s var(--cq-bounce);
}
.cq-seg > button[aria-pressed="true"] { background: var(--cq-gold); transform: translateY(2px); box-shadow: 0 1px 0 var(--cq-ink); }

/* ---------- modal ---------- */
.cq-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; grid-template-columns: minmax(0, 420px); justify-content: center; align-items: center;
  padding: 26px 14px calc(14px + env(safe-area-inset-bottom));
  background: #4a3a5a8c;
  overflow-y: auto;
  animation: cq-fade .2s both;
}
.cq-overlay > cq-panel { min-width: 0; animation: cq-pop .35s var(--cq-bounce) both; }
.cq-overlay.closing { animation: cq-fade .15s reverse both; }
.cq-close {
  position: absolute; top: -14px; right: -8px; z-index: 2;
  width: 40px; height: 40px; padding: 0;
  display: grid; place-items: center;
  background: linear-gradient(180deg, #d8ecf7, #a9cbe0);
  border: var(--cq-line) solid var(--cq-ink);
  border-radius: 50%;
  box-shadow: 0 3px 0 var(--cq-ink);
  font-weight: 700; font-size: 1.2rem; color: #fff;
  text-shadow: 0 1.5px 0 var(--cq-ink), 1.5px 0 0 var(--cq-ink), -1.5px 0 0 var(--cq-ink), 0 -1.5px 0 var(--cq-ink);
}
.cq-close:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--cq-ink); }

.cq-modal-body { min-width: 0; }
@keyframes cq-fade { from { opacity: 0; } }
@keyframes cq-pop { from { transform: scale(.7) translateY(30px); opacity: 0; } }

/* ---------- toast ---------- */
.cq-toasts {
  position: fixed; left: 0; right: 0; top: calc(10px + env(safe-area-inset-top)); z-index: 70;
  display: grid; justify-items: center; gap: 6px; pointer-events: none; padding: 0 12px;
}
.cq-toast {
  max-width: 420px;
  padding: 8px 16px;
  background: var(--cq-paper);
  border: var(--cq-line) solid var(--cq-ink);
  border-radius: 16px;
  box-shadow: 0 4px 0 #5b3a3155;
  font-weight: 600;
  animation: cq-toast-in .4s var(--cq-bounce) both;
}
.cq-toast.bad { background: #ffd9d2; }
.cq-toast.out { animation: cq-fade .3s reverse both; }
@keyframes cq-toast-in { from { transform: translateY(-40px) scale(.8); opacity: 0; } }

/* ---------- particles ---------- */
.cq-fx { position: fixed; inset: 0; z-index: 90; pointer-events: none; overflow: hidden; contain: strict; }
.cq-fx > i { position: absolute; left: 0; top: 0; font-style: normal; line-height: 1; will-change: transform, opacity; }

/* ---------- chibi ---------- */
cq-chibi { display: block; }
cq-chibi svg { display: block; width: 100%; height: 100%; }
cq-chibi[mode="stage"] { border: var(--cq-line) solid var(--cq-ink); border-radius: 16px; overflow: hidden; background: var(--cq-paper-2); }
cq-chibi[mode="head"] { border-radius: 50%; overflow: hidden; }
cq-chibi[bob] .chibi-body { animation: cq-bob 2.6s ease-in-out infinite; transform-origin: 100px 236px; }
cq-chibi[bob] .chibi-pet { animation: cq-hop 1.8s ease-in-out infinite; }
@keyframes cq-bob { 50% { transform: scaleY(.975) translateY(1px); } }
cq-chibi.cheer .chibi-body { animation: cq-cheer .5s var(--cq-bounce) 2; transform-origin: 100px 236px; }
@keyframes cq-cheer { 40% { transform: translateY(-16px) scaleY(1.04); } 70% { transform: scaleY(.94); } }

.cq-wiggle { animation: cq-wiggle .4s; }
@keyframes cq-wiggle { 25% { transform: translateX(-6px) rotate(-2deg); } 75% { transform: translateX(6px) rotate(2deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01s !important; animation-iteration-count: 1 !important; transition-duration: .01s !important; }
}

/* ---------- inline icons (from icon() in ui.js) ---------- */
.cq-ic { display: inline-block; width: 1.25em; height: 1.25em; vertical-align: -.24em; flex: none; }
