/* Cuti-Cuti — mobile-first, touch-friendly styles */
:root {
  --cream: #fff4e0;
  --ink: #3a2a3d;
  --muted: #8a7a9a;
  --brand: #7b5cff;
  --brand-soft: #efe9ff;
  --pink: #ff6fa5;
  --sun: #ffd23f;
  --mint: #3ddcb0;
  --card: #f8f4ff;
  --shadow: 0 4px 0 rgba(58, 42, 61, 0.14);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --font: "Nunito", "Baloo 2", ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--cream); color: var(--ink);
  font-family: var(--font); font-weight: 700;
  overscroll-behavior: none; touch-action: manipulation;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 4px solid var(--brand); outline-offset: 2px; }
.ic { width: 26px; height: 26px; display: block; }

/* ---------- layout ---------- */
#app {
  height: 100vh; height: 100dvh;
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto;
  padding-top: var(--sat);
  background:
    radial-gradient(circle at 12% 8%, #ffe8f1 0 18%, transparent 19%),
    radial-gradient(circle at 92% 30%, #e6f7ff 0 14%, transparent 15%),
    var(--cream);
}

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px 6px;
}
.tb-group { display: flex; gap: 8px; align-items: center; }
.ibtn {
  width: 46px; height: 46px; border-radius: 16px; border: 0; padding: 0;
  display: grid; place-items: center; background: #fff; color: var(--ink);
  box-shadow: var(--shadow); transition: transform 0.12s;
}
.ibtn:active { transform: translateY(2px) scale(0.95); box-shadow: 0 1px 0 rgba(58, 42, 61, 0.14); }
.ibtn:disabled { opacity: 0.35; box-shadow: none; }
.ibtn.primary { background: var(--brand); color: #fff; }
.ibtn.muted { color: #b9aec6; }
.logo {
  margin: 0; font-size: 25px; font-weight: 900; letter-spacing: -0.5px; display: flex; text-shadow: 0 3px 0 rgba(58, 42, 61, 0.14);
}
.logo span:nth-child(4n+1) { color: #ff6fa5; }
.logo span:nth-child(4n+2) { color: #ffb703; }
.logo span:nth-child(4n+3) { color: #3ddcb0; }
.logo span:nth-child(4n) { color: #7b5cff; }
.logo .dash { color: var(--ink); margin: 0 1px; }
@media (max-width: 460px) {
  #topbar { padding-left: 8px; padding-right: 8px; gap: 4px; }
  .logo { font-size: 19px; }
  .ibtn { width: 44px; height: 44px; border-radius: 14px; }
  .tb-group { gap: 6px; }
}
@media (max-width: 374px) { .logo { display: none; } }

/* ---------- stage ---------- */
#stagewrap {
  position: relative; margin: 2px 10px 10px; border-radius: 28px; overflow: hidden;
  border: 4px solid #fff; box-shadow: 0 6px 0 rgba(58, 42, 61, 0.12), 0 12px 30px rgba(123, 92, 255, 0.15);
  background: #cfe6ff; min-height: 0;
}
#bg, #stage, #fx { position: absolute; inset: 0; width: 100%; height: 100%; }
#bg svg { width: 100%; height: 100%; display: block; }
#stage { overflow: visible; touch-action: manipulation; }
#stage * { -webkit-user-drag: none; }
#fx { pointer-events: none; overflow: hidden; }
.fab {
  position: absolute; right: 10px; bottom: 10px; width: 52px; height: 52px; border-radius: 50%; border: 0;
  background: #fff; color: var(--brand); display: grid; place-items: center; box-shadow: var(--shadow);
}
.fab:active { transform: scale(0.92); }
.fab[hidden] { display: none; }
#toast {
  position: absolute; left: 50%; top: 12px; transform: translate(-50%, -80px); background: var(--ink); color: #fff;
  padding: 9px 16px; border-radius: 999px; font-size: 15px; transition: transform 0.28s cubic-bezier(0.3, 1.5, 0.5, 1); pointer-events: none; white-space: nowrap;
}
#toast.show { transform: translate(-50%, 0); }

/* character animations (only on the main stage, not the thumbnails) */
#bounce { transform-origin: 200px 640px; animation: breathe 3.6s ease-in-out infinite; }
#bounce.boing { animation: boing 0.5s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes breathe { 0%, 100% { transform: translateY(0) scaleY(1); } 50% { transform: translateY(-3px) scaleY(1.008); } }
@keyframes boing { 0% { transform: scale(1, 1); } 25% { transform: scale(1.06, 0.93); } 55% { transform: scale(0.97, 1.05); } 100% { transform: scale(1, 1); } }
#stage .blink { transform-box: fill-box; transform-origin: center; animation: blink 4.2s infinite; }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(0.08); } }
#stage .wave-R { animation: waveR 0.9s ease-in-out infinite alternate; }
#stage .wave-L { animation: waveL 0.9s ease-in-out infinite alternate-reverse; }
@keyframes waveR { from { transform: rotate(-9deg); } to { transform: rotate(7deg); } }
@keyframes waveL { from { transform: rotate(9deg); } to { transform: rotate(-7deg); } }
#stage .spin { animation: spin 0.45s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#stage .flame { animation: flame 0.25s ease-in-out infinite alternate; }
@keyframes flame { from { transform: scaleY(0.85); } to { transform: scaleY(1.15); } }
#stage .bob { animation: bob 2.4s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-6px); } }

.spark { position: absolute; width: 22px; height: 22px; pointer-events: none; animation: spark 0.85s ease-out forwards; }
@keyframes spark {
  0% { transform: translate(0, 0) scale(0.2) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.1) rotate(220deg); opacity: 0; }
}

/* ---------- bottom panel ---------- */
#panel {
  transition: height 0.35s ease;
  display: flex; flex-direction: column; min-height: 0;
  height: min(47dvh, 440px); height: min(47vh, 440px);
  background: #fff; border-radius: 28px 28px 0 0; box-shadow: 0 -8px 26px rgba(80, 50, 120, 0.13);
  padding-bottom: var(--sab);
}
@supports (height: 1dvh) { #panel { height: min(47dvh, 440px); } }
/* the "All" view gives the stage more room so the whole body is easier to see */
#app[data-view="full"] #panel { height: min(36vh, 330px); }
@supports (height: 1dvh) { #app[data-view="full"] #panel { height: min(36dvh, 330px); } }

#catwrap { position: relative; flex: none; }
#cats {
  display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; padding: 10px 14px 4px;
  scrollbar-width: none; scroll-snap-type: x proximity; overscroll-behavior-x: contain;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 26px), transparent);
  mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 26px), transparent);
}
#cats::-webkit-scrollbar { display: none; }
.cat {
  flex: none; width: 68px; padding: 0; border: 0; background: none; scroll-snap-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; font-weight: 800; color: var(--muted);
}
.cat .ico {
  width: 56px; height: 56px; border-radius: 20px; background: var(--card); border: 3px solid transparent; overflow: hidden;
  display: grid; place-items: center; transition: transform 0.15s, background 0.15s;
}
.cat .ico svg { width: 100%; height: 100%; display: block; }
.cat[aria-selected="true"] { color: var(--brand); }
.cat[aria-selected="true"] .ico { background: var(--brand-soft); border-color: var(--brand); transform: translateY(-2px) scale(1.06); }
.cat:active .ico { transform: scale(0.93); }

#opts { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 2px 14px 16px; }
.subs { display: flex; gap: 8px; margin: 8px 0 4px; }
.chip {
  flex: 1; min-width: 0; height: 68px; border-radius: 18px; border: 3px solid transparent; background: var(--card); color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-weight: 900; font-size: 12px; padding: 2px 4px;
}
.chip svg { width: 40px; height: 40px; border-radius: 12px; flex: none; }
.chip[aria-selected="true"] { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }

.sec { margin: 6px 0 14px; }
.sec[hidden] { display: none; }
.sec h3 { margin: 8px 0 8px; font-size: 13px; font-weight: 900; color: var(--muted); letter-spacing: 0.3px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px; }
.opt {
  position: relative; aspect-ratio: 1; padding: 0; border-radius: 20px; background: var(--card); border: 3px solid transparent; overflow: hidden;
  transition: transform 0.12s;
}
.opt .th, .opt .th svg { display: block; width: 100%; height: 100%; }
.opt:active { transform: scale(0.92); }
.opt.sel { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px rgba(123, 92, 255, 0.22); }
.opt .chk {
  position: absolute; right: 4px; top: 4px; width: 22px; height: 22px; border-radius: 50%; background: var(--brand); color: #fff;
  display: none; place-items: center;
}
.opt .chk .ic { width: 15px; height: 15px; }
.opt.sel .chk { display: grid; animation: pop 0.3s cubic-bezier(0.3, 1.8, 0.5, 1); }
.opt > .ic { position: absolute; inset: 0; margin: auto; width: 40px; height: 40px; color: #c9b8d8; }
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }

.swatches { display: flex; flex-wrap: wrap; gap: 9px; }
.sw {
  position: relative; width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff; padding: 0;
  box-shadow: 0 0 0 2px rgba(58, 42, 61, 0.22), 0 3px 0 rgba(58, 42, 61, 0.12); transition: transform 0.12s;
  display: grid; place-items: center; color: #fff;
}
.sw:active { transform: scale(0.9); }
.sw.sel { box-shadow: 0 0 0 3px #fff, 0 0 0 7px var(--brand); transform: scale(1.04); }
.sw .ic { width: 22px; height: 22px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.45)); }
.sw.custom { background: conic-gradient(#ff5a5f, #ffd93d, #5fd35f, #4aa8ff, #a26bff, #ff5a5f); }
.sw.auto { background: #fff; color: var(--brand); }
.sw.auto .ic { filter: none; }
.sw .tick { display: none; }
.sw.sel .tick { display: block; }

.picker { margin-top: 12px; padding: 10px 14px 6px; background: var(--card); border-radius: 20px; }
.bar { position: relative; height: 36px; margin: 8px 0 14px; border-radius: 18px; touch-action: none; box-shadow: inset 0 0 0 3px rgba(58, 42, 61, 0.15); }
.bar .knob {
  position: absolute; top: 50%; width: 38px; height: 38px; border-radius: 50%; border: 5px solid #fff; transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px var(--ink), 0 3px 6px rgba(0, 0, 0, 0.3); pointer-events: none;
}
.hue { background: linear-gradient(90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }

.slider { display: flex; align-items: center; gap: 10px; }
.slider svg { width: 26px; height: 26px; flex: none; }
input[type="range"] { -webkit-appearance: none; appearance: none; flex: 1; height: 44px; background: transparent; margin: 0; touch-action: pan-y; }
input[type="range"]::-webkit-slider-runnable-track { height: 14px; border-radius: 7px; background: linear-gradient(90deg, #d9ccff, var(--brand)); }
input[type="range"]::-moz-range-track { height: 14px; border-radius: 7px; background: linear-gradient(90deg, #d9ccff, var(--brand)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 40px; height: 40px; margin-top: -13px; border-radius: 50%; background: #fff; border: 6px solid var(--brand); box-shadow: 0 3px 0 rgba(58, 42, 61, 0.2); }
input[type="range"]::-moz-range-thumb { width: 28px; height: 28px; border-radius: 50%; background: #fff; border: 6px solid var(--brand); box-shadow: 0 3px 0 rgba(58, 42, 61, 0.2); }

.pats { display: flex; flex-wrap: wrap; gap: 9px; }
.pat { width: 54px; height: 54px; border-radius: 16px; border: 3px solid transparent; background: var(--card); padding: 0; overflow: hidden; position: relative; }
.pat svg { width: 100%; height: 100%; display: block; }
.pat.sel { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(123, 92, 255, 0.22); }
.pat:active { transform: scale(0.92); }
.pat > .ic { position: absolute; inset: 0; margin: auto; width: 30px; height: 30px; color: #b9a8c9; }

/* full-view actions + friends */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0 14px; }
.bigbtn {
  min-height: 60px; border: 0; border-radius: 20px; padding: 8px 12px; display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 15px; font-weight: 900; color: #fff; box-shadow: 0 5px 0 rgba(58, 42, 61, 0.2); transition: transform 0.1s;
}
.bigbtn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(58, 42, 61, 0.2); }
.bigbtn .ic { width: 28px; height: 28px; }
.bigbtn.b1 { background: var(--brand); }
.bigbtn.b2 { background: var(--pink); }
.bigbtn.b3 { background: #2fbf9b; }
.bigbtn.b4 { background: #ff9f43; }
.friends { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 10px; }
.friend { position: relative; aspect-ratio: 3 / 4; border-radius: 18px; background: var(--card); border: 3px solid transparent; padding: 0; overflow: hidden; }
.friend svg { width: 100%; height: 100%; display: block; }
.friend:active { transform: scale(0.94); }
.friend .del {
  position: absolute; right: 4px; top: 4px; width: 32px; height: 32px; border-radius: 50%; background: rgba(255, 255, 255, 0.92); color: #c0416a;
  display: grid; place-items: center; border: 0; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}
.friend .del.sure { background: #c0416a; color: #fff; }
.friend .del .ic { width: 16px; height: 16px; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 2px 14px; line-height: 1.35; }

/* ---------- mode switcher ---------- */
#modes { display: flex; gap: 8px; padding: 6px 12px 10px; flex: none; }
.mode {
  flex: 1; height: 62px; border-radius: 22px; border: 0; background: #f2ecff; color: var(--brand); font-weight: 900; font-size: 15px;
  display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 6px 0 4px; box-shadow: 0 4px 0 rgba(123, 92, 255, 0.22); transition: transform 0.1s;
}
.mode .mi { width: 48px; height: 48px; border-radius: 16px; background: #fff; overflow: hidden; flex: none; }
.mode .mi svg { width: 100%; height: 100%; display: block; }
.mode[aria-selected="true"] { background: var(--brand); color: #fff; box-shadow: 0 4px 0 rgba(58, 42, 61, 0.28); }
.mode:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(58, 42, 61, 0.2); }
@media (max-width: 380px) { .mode { font-size: 13px; } .mode .mi { width: 40px; height: 40px; } }

/* ---------- wide screens & phones on their side ---------- */
@media (min-aspect-ratio: 1/1) and (min-width: 640px) {
  #app { grid-template-columns: minmax(0, 1fr) minmax(360px, 460px); grid-template-rows: auto minmax(0, 1fr); }
  #topbar { grid-column: 1 / -1; padding: 6px 14px 4px; }
  #stagewrap { margin: 2px 6px 12px 14px; }
  #app #panel, #app[data-view="full"] #panel { height: auto; border-radius: 28px 0 0 0; }
  #app > #panel { grid-row: 2; grid-column: 2; }
  .cat { width: 74px; }
  #modes { padding-bottom: 12px; }
}
@media (max-height: 460px) and (min-aspect-ratio: 1/1) {
  #topbar { padding: 4px 10px 2px; }
  .ibtn { width: 40px; height: 40px; }
  .cat .ico { width: 46px; height: 46px; }
  .mode { height: 52px; }
  .mode .mi { width: 38px; height: 38px; }
  #stagewrap { margin-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  #bounce, #bounce.boing, #stage .blink, #stage .wave-R, #stage .wave-L, #stage .spin, #stage .flame, #stage .bob { animation: none !important; }
  .spark { display: none; }
}
