* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:        #FFE6CF;
  --bg-2:      #FFF4EA;
  --card:      #FFFFFF;
  --cream:     #FFF6EC;
  --orange:    #FFA21F;
  --orange-2:  #FF8A00;
  --orange-soft: #FFEBD3;
  --ink:       #1E1B3A;
  --ink-soft:  #5E5873;
  --muted:     #ABA0A0;
  --line:      rgba(30,27,58,.07);
  --shadow:    0 10px 28px rgba(255,138,0,.13), 0 2px 6px rgba(30,27,58,.05);
  --shadow-lg: 0 18px 44px rgba(255,138,0,.18), 0 4px 10px rgba(30,27,58,.06);
  --gold:      #FFB300;
  --bad:       #FF4D5E;
  --board:     #25224A;
  --n: 9;
  --bw: min(calc(100vw - 32px), 520px, calc(100dvh - 276px));
  --cell: calc(var(--bw) / var(--n));
}
.big-board {
  --bw: min(calc(100vw - 24px), 680px, calc(100dvh - 268px));
  --cell: calc(var(--bw) / var(--n));
}
html, body { min-height: 100%; touch-action: manipulation; }
body {
  font-family: 'Poppins', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(600px 420px at 100% 0%, rgba(255,170,90,.35), transparent 70%),
    radial-gradient(520px 420px at 0% 100%, rgba(255,200,150,.45), transparent 70%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .dot { fill: currentColor; }
/* Hand-drawn pals sit inline like an emoji glyph */
img.art { width: 1em; height: 1em; display: inline-block; vertical-align: -0.12em; pointer-events: none; -webkit-user-drag: none; }

/* Soft floating bubbles in the background */
.dust { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.dust span {
  position: absolute; border-radius: 50%; opacity: .55;
  background: radial-gradient(circle at 35% 30%, #fff 0 18%, var(--b, #FFC27A) 60%);
  animation: float 9s ease-in-out infinite alternate;
}
@keyframes float { to { transform: translateY(-18px) rotate(10deg); } }

.wrap {
  position: relative; z-index: 2;
  max-width: 720px; margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.card { background: var(--card); border-radius: 22px; box-shadow: var(--shadow); }

/* Header */
.top { width: var(--bw); min-width: min(100%, 358px); display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0;
  background: var(--card); color: var(--ink); box-shadow: var(--shadow); text-decoration: none;
  transition: transform .15s, color .15s;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { color: var(--orange-2); transform: translateY(-1px); }
.icon-btn:active { transform: scale(.94); }
.title { flex: 1; min-width: 0; text-align: center; }
.logo { font-size: 21px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; color: var(--ink); }
.logo span { color: var(--orange); }
.tagline { font-size: 10px; font-weight: 500; color: var(--muted); }
.top-btns { display: flex; gap: 6px; }

/* Puzzle type: a slim pill row */
.modes { width: var(--bw); min-width: min(100%, 358px); display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.mode {
  display: flex; align-items: center; justify-content: center; gap: 6px; padding: 5px 6px; height: 38px;
  background: var(--card); border-radius: 999px; box-shadow: var(--shadow); min-width: 0;
  transition: transform .15s, background .2s;
}
.mode:active { transform: scale(.97); }
.mode-ic {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 15px; flex-shrink: 0;
  background: var(--t, var(--orange-soft));
}
.mode b { font-size: 13.5px; font-weight: 700; line-height: 1; white-space: nowrap; }
.mode.active {
  background: linear-gradient(160deg, var(--orange), var(--orange-2)); color: #fff;
  box-shadow: 0 8px 18px rgba(255,138,0,.32);
}
.mode.active .mode-ic { background: rgba(255,255,255,.95); }

/* Status */
.status { width: var(--bw); min-width: min(100%, 358px); display: grid; grid-template-columns: 1fr 1.3fr 1fr; padding: 5px 6px; border-radius: 16px; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.stat.mid { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.stat-label { font-size: 9px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 600; }
.stat-val { font-size: 15px; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; }

/* Rule cards */
.rule-cards { width: var(--bw); min-width: min(100%, 358px); display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.rule {
  display: flex; align-items: center; justify-content: center; gap: 4px; padding: 3px 6px; border-radius: 999px;
  background: var(--orange-soft); color: var(--ink-soft); white-space: nowrap;
  font-size: 10.5px; font-weight: 600; line-height: 1.2;
}
.rule-ic { font-size: 12px; flex-shrink: 0; }

/* Board: separate rounded tiles on a navy card, so every pastel pops */
.board-area { display: flex; flex-direction: column; align-items: center; }
.board-shell { padding: 0; border-radius: 26px; box-shadow: var(--shadow-lg), 0 0 0 5px rgba(255,255,255,.75); }
.board {
  --gap: max(2px, calc(var(--cell) * .07));
  width: var(--bw); height: var(--bw);
  display: grid; grid-template-columns: repeat(var(--n), 1fr); grid-template-rows: repeat(var(--n), 1fr);
  gap: var(--gap); padding: calc(var(--gap) * 1.8);
  border-radius: 26px; background: var(--board);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.cell {
  position: relative; display: grid; place-items: center; min-width: 0; min-height: 0;
  background: var(--c); cursor: pointer;
  border-radius: max(3px, calc(var(--cell) * .2));
  box-shadow: inset 0 -2px 0 rgba(30,27,58,.1);
  transition: filter .12s, transform .12s;
}
@media (hover: hover) { .cell:hover { filter: brightness(1.06); } }
.cell:active { transform: scale(.93); }

/* Who's hiding: colored tabs (with ears) perched on top of the board */
.tabs {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px;
  max-width: calc(var(--bw) - 28px);
  padding: 6px 10px 5px; margin-bottom: -4px; position: relative; z-index: 1;
  background: var(--board); border-radius: 18px 18px 0 0;
}
.tab {
  width: min(26px, calc((var(--bw) - 52px) / var(--n) - 4px)); aspect-ratio: 1;
  border-radius: 50% 50% 42% 42%; background: var(--c);
  display: grid; place-items: center; position: relative;
  font-size: min(16px, calc((var(--bw) - 52px) / var(--n) * .58));
  box-shadow: inset 0 -2px 0 rgba(30,27,58,.12);
}
.tab::before, .tab::after { /* little ears */
  content: ''; position: absolute; top: -3px; width: 34%; height: 38%;
  background: var(--c); border-radius: 3px 70% 0 70%; transform: rotate(-12deg);
}
.tab::before { left: 2px; }
.tab::after { right: 2px; transform: scaleX(-1) rotate(-12deg); }
.tab span { position: relative; z-index: 1; }
.tab .q { font-weight: 800; font-size: .95em; line-height: 1; color: rgba(30,27,58,.5); }
.tab.dark .q { color: rgba(255,255,255,.7); }
.tab.found span { animation: pop .3s cubic-bezier(.3,1.6,.5,1); }

/* Regular ✕: big and white, with a soft dark edge so it shows on the palest tiles too */
.cell .x {
  width: 62%; height: 62%; pointer-events: none; overflow: visible;
  stroke: #fff; stroke-width: 3.4; stroke-linecap: round;
  animation: pop .18s cubic-bezier(.3,1.6,.5,1);
}
.cell .x .x-edge { stroke: rgba(30,27,58,.36); stroke-width: 5.6; }
.cell .pal {
  font-size: calc(var(--cell) * .62); line-height: 1; pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(30,27,58,.3));
  animation: pop .28s cubic-bezier(.3,1.6,.5,1);
}
@keyframes pop { from { transform: scale(.2); } to { transform: scale(1); } }
/* Wrong guess: same big ✕, in red with a white edge */
.cell .miss {
  width: 66%; height: 66%; pointer-events: none; overflow: visible;
  stroke: var(--bad); stroke-width: 3.8; stroke-linecap: round;
  animation: pop .25s cubic-bezier(.3,1.6,.5,1);
}
.cell .miss .x-edge { stroke: #fff; stroke-width: 6.6; }
.cell.missed { filter: saturate(.55) brightness(.95); cursor: default; }
.cell.shake { animation: shake .4s ease-in-out; }
@keyframes shake { 20%, 60% { transform: translateX(-12%); } 40%, 80% { transform: translateX(12%); } }
/* hold-to-uncover: a bubble swells while the press counts down */
.cell.holding::before {
  content: ''; position: absolute; inset: 12%; border-radius: 50%; pointer-events: none;
  background: rgba(255,255,255,.55); box-shadow: 0 0 0 2px #fff;
  transform: scale(0); animation: hold .34s linear .08s forwards;
}
@keyframes hold { to { transform: scale(1); } }
.board.lost .cell { cursor: default; }
.board.lost .cell:not(.missed) { filter: saturate(.7); }
.cell.hinted::after {
  content: ''; position: absolute; inset: 2px; border-radius: inherit;
  border: 2px dashed rgba(255,255,255,.9); pointer-events: none;
}
.cell.flash { animation: flash .9s ease-in-out 2; }
@keyframes flash { 50% { filter: brightness(1.4) saturate(1.3); box-shadow: inset 0 0 0 4px #fff; } }
.board.won .cell .pal { animation: dance 1s ease-in-out infinite alternate; animation-delay: var(--d, 0s); }
@keyframes dance { from { transform: translateY(0) rotate(-6deg); } to { transform: translateY(-12%) rotate(6deg); } }
.board.won .cell { cursor: default; }

.stars { letter-spacing: .04em; }
.stars .on { color: var(--gold); }
.stars .off { color: #EDE3DA; }
.stars.drop { animation: starDrop .5s ease-in-out; }
@keyframes starDrop { 30% { transform: scale(1.25); color: var(--bad); } }
.win-stars { color: var(--gold); letter-spacing: .04em; }
.win-stars span { color: #EDE3DA; }

/* Controls */
.controls { width: var(--bw); min-width: min(100%, 358px); display: grid; grid-template-columns: repeat(3, 1fr) 1.25fr; gap: 4px; padding: 5px; margin-top: 4px; border-radius: 18px; }
.ctl {
  padding: 7px 4px; border-radius: 14px; color: var(--ink-soft);
  font-size: 12px; font-weight: 600;
  display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 4px;
  transition: transform .12s, background .15s, color .15s;
}
.ctl svg { width: 18px; height: 18px; }
.ctl:hover { background: var(--cream); color: var(--ink); }
.ctl:active { transform: scale(.95); }
.ctl:disabled { opacity: .35; cursor: default; background: none; }
.ctl.primary {
  background: linear-gradient(160deg, var(--orange), var(--orange-2)); color: #fff;
  box-shadow: 0 8px 18px rgba(255,138,0,.35);
}
.ctl.primary svg { stroke-width: 2.6; }

.tip { font-size: 12px; color: var(--muted); text-align: center; line-height: 1.5; }
.tip b { color: var(--ink-soft); }
.foot { font-size: 12px; color: var(--muted); margin-top: 8px; }
.foot a { color: var(--orange-2); text-decoration: none; font-weight: 600; }

/* Modal: a white bottom-sheet-ish card */
.modal-bg {
  position: fixed; inset: 0; z-index: 50; background: rgba(30,27,58,.35); backdrop-filter: blur(5px);
  display: grid; place-items: center; padding: 16px; animation: fade .2s;
}
.modal-bg[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 440px; max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--card); border-radius: 28px; padding: 24px 20px 20px; box-shadow: 0 24px 60px rgba(30,27,58,.25);
  animation: rise .25s cubic-bezier(.3,1.4,.5,1);
}
@keyframes rise { from { transform: translateY(20px) scale(.96); opacity: 0; } }
.modal h2 { font-size: 24px; font-weight: 800; letter-spacing: -.02em; text-align: center; margin-bottom: 8px; color: var(--ink); }
.modal p { color: var(--ink-soft); font-size: 14px; line-height: 1.55; margin-bottom: 10px; }
.modal p b { color: var(--ink) !important; }
.modal .rules { list-style: none; display: flex; flex-direction: column; gap: 8px; margin: 10px 0 14px; }
.modal .rules li { display: flex; gap: 10px; font-size: 14px; color: var(--ink-soft); line-height: 1.45; }
.modal .rules li b { color: var(--ink); }
.modal .rules .ic {
  font-size: 16px; flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; background: var(--orange-soft);
}
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.btn {
  flex: 1; padding: 13px; border-radius: 999px; font-weight: 700; font-size: 14px;
  background: var(--cream); color: var(--ink);
}
.btn.primary { background: linear-gradient(160deg, var(--orange), var(--orange-2)); color: #fff; box-shadow: 0 8px 18px rgba(255,138,0,.35); }

.mini-board { display: grid; width: 160px; height: 160px; margin: 6px auto 12px; gap: 4px; padding: 7px; border-radius: 18px; background: var(--board); }
.mini-board div { display: grid; place-items: center; font-size: 20px; border-radius: 8px; }

.win-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.win-stats div { background: var(--cream); border-radius: 16px; padding: 9px 6px; text-align: center; }
.win-stats b { display: block; font-size: 18px; font-weight: 700; }
.win-stats small { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 600; }
.win-pals { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.win-pal {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 6px; min-width: 70px;
  border-radius: 16px; background: var(--c); color: var(--ink); font-size: 11px; font-weight: 600; position: relative;
}
.win-pal.dark { color: #fff; }
.win-pal .e { font-size: 28px; }
.win-pal .new {
  position: absolute; top: -7px; right: -4px; background: var(--orange); color: #fff; white-space: nowrap;
  font-size: 8.5px; font-weight: 700; padding: 2px 6px; border-radius: 99px; letter-spacing: .04em;
}

.dex-progress { height: 8px; background: var(--cream); border-radius: 99px; overflow: hidden; margin: 6px 0 14px; }
.dex-progress div { height: 100%; background: linear-gradient(90deg, var(--orange), var(--orange-2)); border-radius: 99px; }
.dex { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.dex-card {
  background: var(--cream); border-radius: 16px; padding: 8px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
}
.dex-card .e { font-size: 28px; }
.dex-card .e .q { display: inline-grid; place-items: center; width: 1.15em; height: 1.15em; border-radius: 50%; background: #F1E6DA; color: #B9AA9C; font-size: .75em; font-weight: 800; }
.dex-card .nm { font-size: 10px; font-weight: 600; color: var(--ink); line-height: 1.2; }
.dex-card.locked .nm { color: var(--muted); }
.dex-card .ct { font-size: 9px; color: var(--muted); }
button.dex-card { font: inherit; cursor: pointer; transition: transform .12s, box-shadow .15s; }
button.dex-card:active { transform: scale(.96); }
button.dex-card[aria-expanded="true"] { box-shadow: 0 0 0 2px var(--orange); }
button.dex-card .ct { color: var(--orange-2); font-weight: 600; }
.dex-sort { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: var(--cream); border-radius: 999px; margin-bottom: 10px; }
.dex-sort button { padding: 7px 4px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--ink-soft); white-space: nowrap; }
.dex-sort button.active { background: linear-gradient(160deg, var(--orange), var(--orange-2)); color: #fff; box-shadow: 0 4px 10px rgba(255,138,0,.3); }
.dex-hint { text-align: center; font-size: 12px !important; color: var(--muted) !important; margin: -6px 0 10px !important; }
.dex-versions {
  grid-column: 1 / -1; background: var(--cream); border-radius: 16px; padding: 10px;
  animation: rise .2s cubic-bezier(.3,1.4,.5,1);
}
.dv-title { font-size: 13px; font-weight: 700; text-align: center; margin-bottom: 8px; }
.dv-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px 5px; }
.dv { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.dv-sw {
  width: 100%; aspect-ratio: 1.7; border-radius: 10px; display: grid; place-items: center; font-size: 20px;
  box-shadow: inset 0 -2px 0 rgba(30,27,58,.1);
}
.dv.missing .dv-sw { background: #F1E6DA; }
.dv-sw .q { font-size: 16px; font-weight: 800; color: #B9AA9C; }
.dv small { font-size: 9px; color: var(--ink-soft); font-weight: 600; text-align: center; line-height: 1.1; }
.dv.missing small { color: var(--muted); }
.dex-stats { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 14px; }
.dex-stats th, .dex-stats td { padding: 7px 4px; text-align: center; border-bottom: 1px solid var(--line); }
.dex-stats th { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 600; }
.section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 600; margin-top: 16px; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting div b { display: block; font-size: 14px; font-weight: 600; }
.setting div small { font-size: 12px; color: var(--muted); }
.switch { position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: #EFE6DD; transition: .2s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.15); transition: .2s; }
.switch input:checked + span { background: linear-gradient(160deg, var(--orange), var(--orange-2)); }
.switch input:checked + span::after { left: 23px; }
.switch input:focus-visible + span { outline: 2px solid var(--orange-2); outline-offset: 2px; }

/* Toast */
.toast {
  position: fixed; left: 50%; top: max(16px, env(safe-area-inset-top)); z-index: 60;
  transform: translate(-50%, -30px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff;
  padding: 11px 18px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(30,27,58,.3); transition: .25s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* Confetti */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti span { position: absolute; top: -40px; font-size: 26px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(calc(100dvh + 80px)) rotate(var(--r)); } }

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

/* "NEW" marks in the Pal-dex, kept until the next new puzzle */
.dex-card, .dv { position: relative; }
.dex-new {
  position: absolute; top: -6px; right: -4px; z-index: 1; white-space: nowrap;
  background: var(--orange); color: #fff; font-size: 8px; font-weight: 700; letter-spacing: .04em;
  padding: 2px 5px; border-radius: 99px; box-shadow: 0 2px 6px rgba(255,138,0,.35);
}
.dv .dex-new { top: -5px; right: -3px; font-size: 7.5px; padding: 1px 4px; }
.dex-news { text-align: center; font-size: 12.5px !important; font-weight: 600; color: var(--orange-2) !important; margin: -4px 0 10px !important; }
.icon-btn { position: relative; }
.icon-btn.has-new::after {
  content: ''; position: absolute; top: 5px; right: 5px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--orange); box-shadow: 0 0 0 2px #fff;
}
