/* Glitter — playful, bright, big touch targets. */
:root {
  --bg1: #ffe3f4;
  --bg2: #e3f0ff;
  --bg3: #f1e6ff;
  --ink: #3b2a55;
  --ink-soft: #7a6896;
  --card: #ffffff;
  --accent: #ff4fa3;
  --accent2: #7b5cff;
  --gold: #ffc531;
  --ok: #2ecc71;
  --no: #ff5d5d;
  --shadow: 0 6px 18px rgba(110, 60, 170, 0.18);
  --shadow-sm: 0 3px 8px rgba(110, 60, 170, 0.16);
  --radius: 22px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Quicksand", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: manipulation; /* no double-tap zoom, no 300ms delay */
}
/* iOS Safari won't let you type into fields under a user-select:none ancestor */
input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
button, canvas { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
/* scroll areas: allow panning but not page pinch-zoom */
.cards, .chips, .palette, .importer-mount, #screen-importer .gi-root, #screen-importer .gi-right { touch-action: pan-x pan-y; }
body {
  background:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,.9) 0 2px, transparent 3px),
    radial-gradient(circle at 78% 8%, rgba(255,255,255,.9) 0 2px, transparent 3px),
    radial-gradient(circle at 92% 70%, rgba(255,255,255,.8) 0 2px, transparent 3px),
    radial-gradient(circle at 30% 88%, rgba(255,255,255,.8) 0 2px, transparent 3px),
    linear-gradient(135deg, var(--bg1), var(--bg3) 50%, var(--bg2));
  background-attachment: fixed;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
button:focus { outline: none; }
button:focus-visible { outline: 4px solid var(--accent2); outline-offset: 2px; }
.hidden { display: none !important; }
.no-emoji .emoji { display: none !important; }
.ic { display: block; width: 1em; height: 1em; flex: none; overflow: visible; }
.done-stars .ic { display: inline-block; vertical-align: -0.15em; }

#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* ---------- round buttons ---------- */
.btn-round {
  flex: none;
  width: 52px; height: 52px; min-width: 48px;
  border: none; border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  font-size: 26px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform .12s ease, background .2s;
  padding: 0;
}
.btn-round:active { transform: scale(.9); }
.btn-round.on { background: var(--gold); box-shadow: 0 0 0 4px #fff, var(--shadow-sm); }
.btn-round.off { background: #e9e3f2; }

/* ================================================================ GALLERY */
.gallery { display: flex; flex-direction: column; height: 100%; }
.gallery-head {
  flex: none;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px 6px;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
.logo {
  margin: 0; flex: none;
  font-size: 32px; font-weight: 900; letter-spacing: .5px;
  display: flex; align-items: center; gap: 4px;
}
.logo-text {
  background: linear-gradient(90deg, #ff4fa3, #ff9b3d, #ffd23f, #4cd964, #3fa9ff, #a35cff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 2px 0 rgba(255,255,255,.9));
}
.logo-gem { font-size: 34px; }
.logo-spark { font-size: 24px; animation: twinkle 1.8s ease-in-out infinite; display: inline-block; }
@keyframes twinkle { 0%,100% { transform: scale(1) rotate(0); opacity: 1; } 50% { transform: scale(.7) rotate(20deg); opacity: .6; } }

.fs-btn { flex: none; margin-left: auto; }
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 6px 4px 8px;
  scrollbar-width: none; flex: 1; min-width: 0;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-height: 48px; padding: 0 16px 0 10px;
  border: none; border-radius: 999px;
  background: rgba(255,255,255,.85);
  box-shadow: var(--shadow-sm);
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 17px; font-weight: 800;
  transition: transform .12s, background .2s;
}
.chip-emoji { font-size: 24px; line-height: 1; }
.chip-emoji:empty { display: none; }
.chip.sel .ic { filter: drop-shadow(0 0 2px rgba(255,255,255,.8)); }
.chip:active { transform: scale(.94); }
.chip.sel { background: var(--accent2); color: #fff; box-shadow: 0 0 0 3px #fff, var(--shadow); }

.cards {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  padding: 8px 16px 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  align-content: start;
}
.card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .15s ease;
  animation: card-in .35s ease both;
}
@keyframes card-in { from { transform: translateY(12px) scale(.96); opacity: 0; } }
.card:active { transform: scale(.96); }
.card-play, .make-card {
  display: flex; flex-direction: column; align-items: stretch;
  width: 100%; height: 100%;
  border: none; background: none; padding: 10px; border-radius: inherit;
  text-align: center;
}
.make-card { background: linear-gradient(145deg, #fff3b0, #ffd1ec 55%, #d6c8ff); border-radius: var(--radius); }
.thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  background: #ebe5ee;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.thumb canvas {
  max-width: 94%; max-height: 94%;
  border-radius: 12px;
  filter: drop-shadow(0 2px 3px rgba(80, 40, 120, .2));
}
.make-thumb { background: rgba(255,255,255,.55); flex-direction: column; gap: 2px; }
.make-cam { font-size: 64px; }
.make-plus { font-size: 30px; animation: twinkle 1.6s infinite; }
.card-label {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 8px; min-height: 28px;
  font-size: 16px; font-weight: 800; line-height: 1.15;
}
.card-emoji { font-size: 22px; flex: none; }
.card-title {
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  word-break: break-word;
}
.card-diff { font-size: 10px; letter-spacing: 3px; color: var(--accent); margin-top: 2px; height: 12px; }
.card.finished { box-shadow: 0 0 0 4px var(--gold), var(--shadow); }

.ring {
  position: absolute; right: 6px; top: 6px;
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(255,255,255,.92);
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 900; color: var(--accent2);
}
.ring svg { position: absolute; inset: 1px; width: 44px; height: 44px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: #ece4f7; stroke-width: 5; }
.ring-fg { fill: none; stroke: var(--accent2); stroke-width: 5; stroke-linecap: round; }
.ring span { position: relative; }
.ring-done { background: var(--gold); color: #fff; font-size: 26px; text-shadow: 0 1px 2px rgba(0,0,0,.2); }

.card-del {
  position: absolute; left: 6px; top: 6px;
  width: 48px; height: 48px; border-radius: 50%;
  border: none; background: rgba(255,255,255,.92);
  box-shadow: var(--shadow-sm);
  font-size: 26px;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.card-del:active { transform: scale(.9); }

.empty-msg {
  grid-column: 1 / -1;
  text-align: center; padding: 40px 16px;
  font-size: 22px; font-weight: 800; color: var(--ink-soft);
}
.empty-emoji { font-size: 64px; display: flex; justify-content: center; gap: 8px; }
.empty-msg .small { font-size: 18px; font-weight: 700; }

/* ================================================================ PLAY */
.play { display: flex; flex-direction: column; height: 100%; position: relative; }
.play-top {
  flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  background: rgba(255,255,255,.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 10px rgba(110,60,170,.08);
  z-index: 2;
}
.play-title {
  flex: 0 1 auto; min-width: 0;
  display: flex; align-items: center; gap: 6px;
  font-size: 20px; font-weight: 900;
}
.play-emoji { font-size: 28px; flex: none; }
.play-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.play-progress {
  flex: 1 1 80px; min-width: 70px; max-width: 280px;
  display: flex; align-items: center; gap: 8px;
  margin-left: auto;
}
.play-progress .bar {
  flex: 1; height: 16px; border-radius: 99px;
  background: #fff; box-shadow: inset 0 1px 3px rgba(80,40,120,.2);
  overflow: hidden;
}
.play-progress .bar i {
  display: block; height: 100%; width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, #ff6fd8, #ffb347, #ffe259, #6ee7a8, #6ec6ff, #b18cff);
  background-size: 280px 100%;
  transition: width .25s ease;
}
.play-progress .pct { font-size: 15px; font-weight: 900; min-width: 40px; text-align: right; }
.play-tools { display: flex; gap: 8px; flex: none; }

.board {
  flex: 1; position: relative; min-height: 0; overflow: hidden;
  background: #ebe5ee;
}
.grid-canvas, .fx-canvas {
  position: absolute; left: 0; top: 0; display: block;
  touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.grid-canvas { cursor: crosshair; }
.board.pan-mode .grid-canvas { cursor: grab; }
.fx-canvas { pointer-events: none; z-index: 1; }

.palette {
  flex: none;
  display: flex; gap: 10px; align-items: center;
  overflow-x: auto; overflow-y: hidden;
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
  background: rgba(255,255,255,.7);
  box-shadow: 0 -2px 10px rgba(110,60,170,.08);
  scrollbar-width: thin;
  z-index: 2;
}
.pal-btn {
  position: relative; flex: none;
  width: 66px; height: 66px; border-radius: 20px;
  border: 3px solid rgba(255,255,255,.95);
  background: radial-gradient(circle at 50% 40%, #fffdfb 0 45%, #efe9ea 100%);
  color: #fff;
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  transition: transform .15s ease, opacity .25s, box-shadow .2s;
  margin: 6px 2px;
}
.pal-gem { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -27px 0 0 -25px; pointer-events: none; }
.pal-num {
  position: relative; font-size: 24px; font-weight: 900; line-height: 1;
  color: #fff;
  text-shadow: 0 0 3px rgba(40,20,50,.9), 0 1px 2px rgba(40,20,50,.9), 0 0 1px #000;
  -webkit-text-stroke: .5px rgba(40,20,50,.6);
}
.pal-left {
  position: absolute; right: -8px; bottom: -6px;
  min-width: 26px; height: 22px; padding: 0 5px;
  border-radius: 11px;
  background: #fff; color: var(--ink);
  font-size: 12px; font-weight: 900; line-height: 22px;
  box-shadow: 0 1px 4px rgba(60,30,90,.25);
}
.pal-left:empty { display: none; }
.pal-btn.sel {
  transform: scale(1.12) translateY(-2px);
  border-color: var(--c);
  box-shadow: 0 0 0 3px var(--ink), 0 6px 14px rgba(60,30,90,.35);
}
.pal-btn.done { opacity: .4; transform: scale(.86); }
.pal-btn.done .pal-num { font-size: 28px; }
.pal-btn.hint { animation: hint-bounce .6s ease; }
@keyframes hint-bounce {
  0%,100% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-12px) scale(1.15); }
  60% { transform: translateY(0) scale(.95); }
}
.pal-btn.pop { animation: pop .5s ease; }
/* squash as a gem leaves the button (two names so each launch restarts the animation) */
.pal-btn.launch-a { animation: launch-a .12s ease-out; }
.pal-btn.launch-b { animation: launch-b .12s ease-out; }
@keyframes launch-a { from { scale: .9; } to { scale: 1; } }
@keyframes launch-b { from { scale: .9; } to { scale: 1; } }
.fly-canvas { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 3; }
@keyframes pop { 0% { transform: scale(1.3); } 100% { } }

/* done overlay */
.done-layer {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(59,42,85,.45), rgba(59,42,85,0) 70%);
  animation: fade-in .3s ease both;
}
@keyframes fade-in { from { opacity: 0; } }
.done-card {
  background: #fff; border-radius: 28px; box-shadow: 0 12px 40px rgba(60,30,90,.35);
  padding: 14px 22px 20px; text-align: center;
  animation: card-pop .45s cubic-bezier(.2,1.6,.4,1) both;
  max-width: 100%;
}
@keyframes card-pop { from { transform: translateY(40px) scale(.7); opacity: 0; } }
.done-stars { font-size: 34px; }
.done-title {
  margin: 0 0 12px; font-size: 40px; font-weight: 900;
  background: linear-gradient(90deg, #ff4fa3, #ff9b3d, #a35cff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.done-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.big-btn {
  min-width: 108px; min-height: 84px;
  border: none; border-radius: 22px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 15px; font-weight: 900;
  box-shadow: var(--shadow);
  padding: 8px 14px;
  transition: transform .12s;
}
.big-btn:active { transform: scale(.93); }
.big-btn .ic { font-size: 40px; }
.big-btn.gallery { background: #d9f0ff; }
.big-btn.again { background: #ffe7b8; }
.big-btn.save { background: #ffd6ef; }

/* ================================================================ IMPORTER */
.importer-mount { flex: 1; min-height: 0; overflow: auto; position: relative; -webkit-overflow-scrolling: touch; }
/* notches / home indicator (the importer's own CSS is injected later, hence the id prefix) */
#screen-importer .gi-root {
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}

/* ================================================================ MODAL */
.modal-layer {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(59,42,85,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fade-in .2s ease both;
}
.modal {
  background: #fff; border-radius: 28px; padding: 20px 24px;
  box-shadow: 0 12px 40px rgba(60,30,90,.4);
  text-align: center; max-width: 380px; width: 100%;
  animation: card-pop .35s cubic-bezier(.2,1.5,.4,1) both;
}
.modal-icon { font-size: 56px; line-height: 1.1; }
.modal-image { margin: 6px auto; }
.modal-image canvas { max-width: 120px; max-height: 120px; border-radius: 10px; }
.modal-text { font-size: 20px; font-weight: 800; margin: 8px 0 16px; }
.modal-buttons { display: flex; gap: 16px; justify-content: center; }
.modal-btn {
  width: 96px; height: 72px; border: none; border-radius: 22px;
  font-size: 36px; font-weight: 900; color: #fff;
  box-shadow: var(--shadow);
}
.modal-btn:active { transform: scale(.93); }
.modal-btn { display: flex; align-items: center; justify-content: center; }
.modal-btn .ic { font-size: 42px; stroke: #fff; stroke-width: 3; }
.modal-icon .ic { margin: 0 auto; }
.modal-btn.yes { background: var(--ok); }
.modal-btn.no { background: var(--no); }

/* ================================================================ RESPONSIVE */
@media (max-height: 640px) {
  .gallery-head { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 2px; }
  .logo { font-size: 26px; }
  .play-top { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 6px; }
  .btn-round { width: 48px; height: 48px; font-size: 24px; }
  .pal-btn { width: 58px; height: 58px; margin: 5px 2px; border-radius: 17px; }
  .pal-gem { width: 44px; height: 44px; margin: -24px 0 0 -22px; }
  .palette { padding-top: 6px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .done-title { font-size: 32px; margin-bottom: 8px; }
  .done-stars { font-size: 26px; }
  .big-btn { min-height: 74px; }
}
@media (max-width: 760px) {
  .play-title .play-name { display: none; }
  .play-progress { max-width: none; }
}
@media (max-width: 600px) {
  .gallery-head { flex-wrap: wrap; gap: 4px; }
  .logo { order: -2; } .fs-btn { order: -1; }
  .chips { flex-basis: 100%; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; padding: 6px 12px max(20px, env(safe-area-inset-bottom)); }
  .play-tools .zoom-in, .play-tools .zoom-out { display: none; }
  .play-top { gap: 6px; padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .play-tools { gap: 6px; }
  .btn-round { width: 48px; height: 48px; font-size: 22px; }
  .play-progress .pct { min-width: 34px; font-size: 13px; }
  .done-card { padding: 12px 14px 16px; }
  .big-btn { min-width: 92px; }
}
@media (max-width: 380px) {
  .play-emoji { display: none; }
  .play-progress .pct { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ================================================================ TWO PLAYERS (v2.2) */
.duo-btn { margin-left: auto; position: relative; }
.duo-btn + .fs-btn { margin-left: 0; }
.duo-btn .ic { font-size: 30px; }
.duo-badge {
  position: absolute; right: -4px; top: -4px;
  min-width: 22px; height: 22px; border-radius: 11px;
  background: var(--accent); color: #fff;
  font-size: 14px; font-weight: 900; line-height: 22px;
  box-shadow: 0 0 0 2px #fff;
}
.pick-back { flex: none; }
.pick-title {
  margin: 0; flex: none;
  display: flex; align-items: center; gap: 8px;
  font-size: 26px; font-weight: 900; color: var(--accent2);
  white-space: nowrap;
}
.pick-ic { font-size: 30px; }
.gallery.picking .card-play { cursor: pointer; }
.gallery.picking .card:hover { box-shadow: 0 0 0 4px var(--accent2), var(--shadow); }

/* mode card */
.duo-card { max-width: 560px; padding: 18px 20px 16px; }
.duo-head {
  margin: 0 0 12px; display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 30px; font-weight: 900; color: var(--accent2);
}
.duo-head .ic { font-size: 40px; }
.duo-modes { display: flex; gap: 14px; justify-content: center; }
.duo-mode {
  flex: 1 1 0; min-width: 0;
  border: none; border-radius: 24px;
  padding: 12px 10px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  box-shadow: var(--shadow);
  transition: transform .12s;
}
.duo-mode:active { transform: scale(.94); }
.duo-mode.together { background: linear-gradient(160deg, #e0f4ff, #d6c8ff); }
.duo-mode.copies { background: linear-gradient(160deg, #fff3b0, #ffd1ec); }
.duo-pic svg { display: block; width: 100%; max-width: 180px; height: auto; margin: 0 auto; }
.duo-pic { width: 100%; }
.duo-name { font-size: 24px; font-weight: 900; }
.duo-expl { font-size: 15px; font-weight: 700; color: var(--ink-soft); line-height: 1.2; }
.duo-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.duo-back { background: #ffe1e1; }
.duo-f2f {
  display: flex; align-items: center; gap: 10px;
  min-height: 56px; padding: 4px 14px 4px 6px;
  border: none; border-radius: 999px; background: #f1e9fb;
  font-size: 18px; font-weight: 900;
  box-shadow: var(--shadow-sm);
}
.duo-f2f-pic svg { display: block; width: 44px; height: 44px; }
.duo-switch {
  position: relative; width: 52px; height: 30px; border-radius: 15px; background: #d9d2e6;
  transition: background .2s; flex: none;
}
.duo-switch i {
  position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s;
}
.duo-f2f.on .duo-switch { background: var(--ok); }
.duo-f2f.on .duo-switch i { transform: translateX(22px); }
.duo-f2f.on { background: #dff7e9; }

/* split screen */
#screen-duo { background: #d9cfe6; }
.duo { position: absolute; inset: 0; display: flex; flex-direction: row; }
.duo-half { position: relative; flex: 1 1 0; min-width: 0; min-height: 0; overflow: hidden; }
.duo-half.rot180 { transform: rotate(180deg); }
.duo-mount { position: absolute; inset: 0; display: flex; flex-direction: column; }
.duo-divider {
  flex: none; width: 14px; position: relative; z-index: 3;
  background: linear-gradient(90deg, #cbbde0, #f6f0fc 50%, #cbbde0);
  touch-action: none;
}
.duo-divider::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 6px; height: 46px; margin: -23px 0 0 -3px;
  border-radius: 3px; background: rgba(123, 92, 255, .35);
}
@media (orientation: portrait) {
  .duo { flex-direction: column-reverse; } /* player 1 at the bottom, player 2 on top (facing them when rotated) */
  .duo-divider { width: auto; height: 14px; background: linear-gradient(180deg, #cbbde0, #f6f0fc 50%, #cbbde0); }
  .duo-divider::after { width: 46px; height: 6px; margin: -3px 0 0 -23px; }
}
.duo-picker { position: absolute; inset: 0; z-index: 10; background: linear-gradient(135deg, var(--bg1), var(--bg3) 50%, var(--bg2)); }
.duo-picker .gallery-head { gap: 8px; padding: 8px 10px 4px; }
.duo-picker .pick-title { font-size: 20px; }
.duo-picker .cards { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; padding: 6px 10px 16px; }
.duo-picker .card-label { font-size: 13px; }
.duo-picker .card-emoji { font-size: 16px; }
.duo-picker .chip { min-height: 40px; font-size: 15px; padding: 0 12px 0 8px; }

/* compact play chrome (one half of the split screen) */
.play.compact .play-top { gap: 6px; padding: 6px 8px; }
.play.compact .btn-round { width: 44px; height: 44px; min-width: 44px; font-size: 22px; }
.play.compact .play-progress { max-width: none; min-width: 50px; gap: 6px; }
.play.compact .play-progress .bar { height: 12px; }
.play.compact .play-progress .pct { font-size: 14px; min-width: 36px; }
.play.compact .play-tools { gap: 6px; }
.play.compact .palette { gap: 6px; padding: 4px 8px; }
.play.compact .pal-btn { width: 52px; height: 52px; border-radius: 15px; margin: 5px 1px; border-width: 2px; }
.play.compact .pal-gem { width: 40px; height: 40px; margin: -22px 0 0 -20px; }
.play.compact .pal-num { font-size: 20px; }
.play.compact .pal-left { font-size: 11px; height: 19px; line-height: 19px; min-width: 22px; right: -6px; bottom: -5px; }
.play.compact .done-layer { padding: 8px; }
.play.compact .done-card { padding: 8px 12px 12px; border-radius: 22px; }
.play.compact .done-stars { font-size: 22px; }
.play.compact .done-title { font-size: 28px; margin-bottom: 6px; }
.play.compact .done-buttons { gap: 8px; }
.play.compact .big-btn { min-width: 76px; min-height: 64px; font-size: 13px; border-radius: 18px; padding: 6px 8px; }
.play.compact .big-btn .ic { font-size: 30px; }
/* the split screen owns the safe areas: no notch padding inside the halves */
#screen-duo .play-top, #screen-duo .palette { padding-left: 8px; padding-right: 8px; }
#screen-duo .play-top { padding-top: 6px; }
#screen-duo .palette { padding-bottom: 4px; }
@media (max-width: 600px) {
  .duo-btn { order: -1; margin-left: auto; }
  .pick-back, .pick-title { order: -2; }
  .duo-modes { gap: 10px; }
  .duo-name { font-size: 20px; }
  .duo-expl { font-size: 13px; }
  .duo-f2f { font-size: 15px; }
}
@media (max-width: 600px) and (orientation: portrait) {
  .duo-btn + .fs-btn { margin-left: 0; }
}
.duo {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ================================================================ SETTINGS CARD */
.gear-btn { margin-left: auto; }
.gear-btn .ic { font-size: 32px; }
.duo-btn + .gear-btn, .gear-btn + .fs-btn { margin-left: 0; }
.set-card { position: relative; max-width: 560px; padding: 14px 20px 18px; }
.set-head { margin-bottom: 8px; }
.set-close { position: absolute; right: 12px; top: 10px; background: #ffe1e1; }
.set-sparkle { background: #f6f1fc; border-radius: 22px; padding: 10px 12px 6px; }
.set-label { display: flex; align-items: center; gap: 8px; font-size: 24px; font-weight: 900; margin-bottom: 8px; }
.set-label-ic { font-size: 28px; display: inline-flex; }
.set-stars { margin-left: auto; display: inline-flex; gap: 2px; }
.set-star { font-size: 26px; display: inline-flex; opacity: .22; filter: grayscale(1); transition: opacity .15s, transform .15s; }
.set-star.lit { opacity: 1; filter: none; transform: scale(1.08); }
.set-preview { position: relative; width: 100%; height: 84px; border-radius: 16px; overflow: hidden; box-shadow: inset 0 2px 6px rgba(80,50,110,.18); }
.set-preview canvas { position: absolute; left: 0; top: 0; display: block; }
.set-slider-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.set-end {
  flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 60px; min-height: 64px; padding: 0; border: none; background: none; color: var(--ink-soft);
}
.set-end .ic { font-size: 40px; }
.set-end-hi .ic { font-size: 46px; }
.set-end small { font-size: 14px; font-weight: 900; line-height: 1; }
.set-end-hi small { color: var(--accent); }
.set-range {
  --pct: 50%;
  flex: 1 1 auto; min-width: 0; height: 64px; margin: 0; background: transparent;
  -webkit-appearance: none; appearance: none; touch-action: none; cursor: pointer;
}
.set-range::-webkit-slider-runnable-track {
  height: 18px; border-radius: 9px;
  background: linear-gradient(90deg, #ffc531, #ff4fa3) 0 0 / var(--pct) 100% no-repeat, #e2d9ee;
  box-shadow: inset 0 2px 4px rgba(60,30,90,.2);
}
.set-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 46px; height: 46px; margin-top: -14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 22%, #ffe9a8 23% 55%, #ffc531 56%);
  border: 4px solid #fff; box-shadow: 0 3px 10px rgba(60,30,90,.4);
}
.set-range::-moz-range-track { height: 18px; border-radius: 9px; background: #e2d9ee; box-shadow: inset 0 2px 4px rgba(60,30,90,.2); }
.set-range::-moz-range-progress { height: 18px; border-radius: 9px; background: linear-gradient(90deg, #ffc531, #ff4fa3); }
.set-range::-moz-range-thumb {
  width: 38px; height: 38px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 22%, #ffe9a8 23% 55%, #ffc531 56%);
  border: 4px solid #fff; box-shadow: 0 3px 10px rgba(60,30,90,.4);
}
.set-range:focus-visible { outline: 4px solid var(--accent2); outline-offset: 2px; border-radius: 12px; }
.set-toggles { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 14px; }
.set-toggle { flex: 1 1 200px; justify-content: space-between; }
.set-tg-ic { display: flex; width: 44px; height: 44px; align-items: center; justify-content: center; font-size: 34px; }
.set-toggle .duo-f2f-text { flex: 1 1 auto; text-align: left; }
@media (max-height: 640px) {
  .set-card { padding: 10px 16px 12px; }
  .set-head { font-size: 26px; margin-bottom: 4px; }
  .set-head .ic { font-size: 34px; }
  .set-toggles { margin-top: 10px; }
}
@media (max-width: 600px) {
  .gear-btn { order: -1; }
  .duo-btn + .gear-btn { margin-left: 0; }
  .set-card { padding: 12px 12px 14px; }
  .set-label { font-size: 20px; }
  .set-star { font-size: 22px; }
  .set-end { width: 48px; }
  .set-toggle { flex-basis: 100%; }
}
@media (max-width: 420px) {
  .logo { font-size: 28px; }
  .logo-gem { font-size: 30px; }
  .gallery-head .btn-round { width: 46px; height: 46px; min-width: 46px; }
}

/* ================================================================ BOARDS (v3) */
.play-tools .add-fig .ic, .play-tools .gear .ic { font-size: 30px; }
.play-tools .add-fig .ic { width: 1.1em; height: 1.1em; }
.board.arranging .grid-canvas { cursor: grab; }
.arrange-ui {
  position: absolute; left: 0; top: 0; z-index: 3;
  display: flex; gap: 8px; padding: 6px;
  border-radius: 999px; background: rgba(255,255,255,.92);
  box-shadow: 0 4px 14px rgba(60,30,90,.3);
  will-change: transform;
}
.arrange-ui .btn-round { width: 48px; height: 48px; min-width: 48px; font-size: 26px; }
.arrange-ui .arr-del { background: #ffe1e1; }
.arrange-ui .arr-ok { background: #dff7e9; }
.arrange-ui .arr-ok .ic { stroke: #2e9d5b; stroke-width: 3; }
.fig-done {
  position: absolute; left: 50%; top: 12px; z-index: 4;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  padding: 8px 18px 8px 8px; border-radius: 999px;
  background: #fff; box-shadow: 0 0 0 4px var(--gold), 0 8px 22px rgba(60,30,90,.3);
  cursor: pointer;
}
.fig-done.show { animation: fig-done-in .45s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes fig-done-in { from { transform: translateX(-50%) translateY(-30px) scale(.6); opacity: 0; } }
.fig-done-thumb { width: 52px; height: 52px; border-radius: 12px; object-fit: contain; }
.fig-done-text { display: flex; align-items: center; gap: 6px; font-size: 26px; font-weight: 900; color: var(--accent2); }
.fig-done-text .ic { font-size: 28px; }
.board-card .card-emoji { letter-spacing: 2px; }
.board-card .board-count { font-weight: 900; color: var(--accent2); }
.board-card .thumb { background: linear-gradient(135deg, #fff, #f6effc); }
/* the "+" picker and the settings card live in the app-level overlay layer (#modal-root) */
.app-picker { position: fixed; inset: 0; z-index: 40; }
.set-layer.rot180 .set-card { transform: rotate(180deg); }
.play.compact .play-tools .gear .ic { font-size: 26px; }
@media (max-width: 600px) {
  .play:not(.compact) .play-tools .sound { display: none; }
}
@media (max-width: 820px) {
  .play:not(.compact) .play-tools .zoom-in, .play:not(.compact) .play-tools .zoom-out { display: none; }
}

/* ================================================================ ONLINE ROOMS (v3) */
.join-btn { margin-left: auto; }
.join-btn:not(.hidden) + .duo-btn { margin-left: 0; }
.join-btn .ic { font-size: 32px; }
.play-tools .online { position: relative; }
.play-tools .online .ic { font-size: 30px; }
.online-count {
  position: absolute; right: -4px; top: -4px; min-width: 22px; height: 22px; padding: 0 5px;
  border-radius: 11px; background: var(--accent); color: #fff; font-size: 13px; font-weight: 900; line-height: 22px;
  box-shadow: 0 0 0 2px #fff;
}
.room-pill {
  position: absolute; left: 10px; top: 10px; z-index: 3;
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 6px; border: none; border-radius: 999px;
  background: rgba(255,255,255,.94); box-shadow: 0 4px 14px rgba(60,30,90,.25);
}
.room-pill:active { transform: scale(.95); }
.room-pill.reconnecting { opacity: .55; animation: room-blink 1.2s ease-in-out infinite; }
@keyframes room-blink { 50% { opacity: .3; } }
.room-code { display: flex; justify-content: center; gap: 12px; }
.room-sym {
  display: inline-flex; align-items: center; justify-content: center;
  width: 84px; height: 84px; border-radius: 22px; background: #fff;
  box-shadow: 0 0 0 3px #efe6fb, var(--shadow-sm);
}
.room-sym .ic { width: 70%; height: 70%; }
.room-sym.empty { background: #f6f0fc; box-shadow: inset 0 0 0 3px #e0d4f2; color: #b9a8d6; font-size: 30px; }
.room-code.big .room-sym { width: 104px; height: 104px; border-radius: 26px; }
.room-code.mid .room-sym { width: 64px; height: 64px; border-radius: 18px; }
.room-code.mini { gap: 3px; }
.room-code.mini .room-sym, .room-code.small .room-sym { width: 34px; height: 34px; border-radius: 10px; box-shadow: 0 0 0 2px #efe6fb; }
.room-code.small { margin: 4px 0; }
.peer-list, .online-peers { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.peer-badge {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 3px var(--pc, var(--accent2));
}
.peer-badge .ic { width: 72%; height: 72%; }
.online-peers { margin: 4px 0 6px; min-height: 52px; align-items: center; gap: 12px; }
.online-peers .peer-badge { width: 52px; height: 52px; box-shadow: 0 0 0 4px var(--pc, var(--accent2)); }
.peer-badge.me i { position: absolute; right: -8px; top: -8px; font-size: 20px; line-height: 0; }
.peer-badge.me i .ic { width: 1em; height: 1em; }
.online-card { max-width: 600px; position: relative; padding: 18px 20px 18px; }
.online-head .ic { font-size: 40px; }
.online-hint { margin: 10px 0 4px; font-size: 20px; font-weight: 800; color: var(--ink-soft); }
.online-hint.warn { color: var(--no); font-size: 18px; }
.online-foot { display: flex; justify-content: center; margin-top: 10px; }
.online-modes { flex-wrap: wrap; }
.online-mode { background: linear-gradient(160deg, #e0f4ff, #d6c8ff); }
.online-mode.join, .online-mode.m2 { background: linear-gradient(160deg, #fff3b0, #ffd1ec); }
.online-mode.m3 { background: linear-gradient(160deg, #dff7e9, #c8f0ff); }
.online-mode.m4 { background: linear-gradient(160deg, #ffe1e1, #f1e6ff); }
.online-mode.disabled { opacity: .4; filter: grayscale(.6); }
.join-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.join-modes .duo-pic { height: 92px; display: flex; align-items: center; justify-content: center; }
.join-modes .duo-pic svg { max-height: 92px; }
.join-modes .duo-name { font-size: 20px; }
.mode-thumb { position: relative; display: inline-block; }
.mode-thumb canvas { display: block; max-width: 92px; max-height: 88px; border-radius: 10px; background: #fff; box-shadow: var(--shadow-sm); }
.mode-pct {
  position: absolute; right: -10px; bottom: -6px; padding: 2px 7px; border-radius: 10px;
  background: var(--ok); color: #fff; font-size: 14px; font-weight: 900;
}
.sym-top { display: flex; align-items: center; justify-content: center; gap: 14px; }
.sym-top .room-code { gap: 10px; }
.sym-top .room-sym { width: 76px; height: 76px; }
.sym-back { background: #ffe1e1; }
.sym-back:disabled { opacity: .35; }
.sym-pad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px; }
.sym-pad.busy { opacity: .6; }
.sym-btn {
  aspect-ratio: 1; min-height: 60px; border: none; border-radius: 20px; background: #fff;
  box-shadow: 0 0 0 3px #efe6fb, var(--shadow-sm);
  display: flex; align-items: center; justify-content: center; transition: transform .1s;
}
.sym-btn .ic { width: 70%; height: 70%; }
.sym-btn:active { transform: scale(.9); }
.sym-btn.used { opacity: .25; }
.room-wait { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; }
.room-wait-syms { display: flex; gap: 12px; }
.room-wait-syms .ic { width: 72px; height: 72px; }
.room-wait-gem { font-size: 64px; line-height: 0; display: flex; justify-content: center; animation: room-spin 1.4s linear infinite; }
@keyframes room-spin { to { transform: rotate(360deg); } }
.online-card.shake { animation: room-shake .45s ease; }
@keyframes room-shake { 20%, 60% { transform: translateX(-12px); } 40%, 80% { transform: translateX(12px); } }
@media (max-width: 600px), (max-height: 640px) {
  .room-code.big .room-sym { width: 80px; height: 80px; }
  .sym-top .room-sym { width: 58px; height: 58px; }
  .sym-pad { gap: 7px; margin-top: 10px; }
  .sym-btn { min-height: 48px; border-radius: 14px; }
  .join-modes .duo-pic { height: 70px; }
  .join-modes .duo-pic svg { max-height: 70px; }
  .join-modes .duo-expl { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .room-wait-gem, .room-pill.reconnecting, .online-card.shake { animation: none; }
}
.sym-pad { max-width: min(420px, 52vh); margin-left: auto; margin-right: auto; }
.online-card { max-height: 100%; overflow-y: auto; }

/* ---- 1 Player / 2 Players pair ---- */
.solo-btn { position: relative; margin-left: auto; }
.solo-btn .ic { font-size: 30px; }
.solo-btn + .join-btn, .solo-btn + .duo-btn, .join-btn + .duo-btn, .duo-btn { margin-left: 0; }
.solo-btn.sel, .duo-btn.sel { background: #efe4ff; box-shadow: inset 0 0 0 3px #a35cff, 0 4px 10px rgba(80,40,120,.15); }
#screen-duo .play-top .solo-btn { margin-left: 0; }
#screen-duo .play-top .solo-btn .duo-badge { transform: scale(.85); }
@media (max-width: 600px) {
  .solo-btn { order: -1; margin-left: auto; }
  .join-btn, .duo-btn { order: -1; margin-left: 0; }
}
