:root {
  --bg: #f6f5ef; --ink: oklch(0.21 0.006 285.885); --ink-title: #735056;
  --surface: #fff; --surface-soft: rgba(255,255,255,.9);
  --tile-bg: #fbf1eb; --tile-ink: #8a5a5a;
  --progress-ok: #22c55e; --progress-sep: #a1a1aa; --progress-total: #71717a;
  --link: #6d3fd1; --focus: #f59e0b; --hint-ring: rgba(59,130,246,.7);
  --overlay: rgba(2,6,23,.75); --win-btn: #4caf50; --region-edge: rgba(0,0,0,.35);
  --region-1: #e6a8c1; --region-2: #c1658a; --region-3: #9179d1; --region-4: #fea0ec; --region-5: #ffa96c;
  --region-6: #e3ba46; --region-7: #6182b5; --region-8: #69bce6; --region-9: #46b3b0; --region-10: #acd994;
  --font-body: "Open Sans", Arial, sans-serif; --font-heading: "Quicksand", "Open Sans", Arial, sans-serif;
  --radius-card: 16px; --radius-tile: 12px; --radius-cell: 8px; --gap: 6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05); --shadow-btn: 0 4px 6px -1px rgba(0,0,0,.1);
  --win-title: #ff9a3c; --win-edge: #6b4423; --btn-size: 60px; --glyph-ratio: 83%;
  --n: 5; --pad: 6px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 16px; overflow-x: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.app { max-width: 992px; margin: 0 auto; padding: 8px var(--pad) 24px; display: flex; flex-direction: column; align-items: center; gap: 12px; }

.top { width: 100%; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.progress { opacity: 0.0; justify-self: start; display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border-radius: 9999px; padding: 4px 12px 4px 8px; box-shadow: var(--shadow-sm); font-size: 18px; font-weight: 500; }
.progress-icon { width: 24px; height: 24px; }
.progress-current { color: var(--progress-ok); }
.progress-sep { color: var(--progress-sep); }
.progress-total { color: var(--progress-total); }
.title-block { text-align: center; display: flex; flex-direction: column; align-items: center; }
.level-title { margin: 0; font-family: var(--font-body); font-size: 24px; font-weight: 600; color: var(--ink-title); }
.levelbar { justify-self: end; }
select { font: inherit; font-size: 14px; font-weight: 500; min-height: 32px; padding: 4px 10px; border-radius: 9999px; border: 0; background: var(--surface); color: var(--ink-title); box-shadow: var(--shadow-sm); cursor: pointer; max-width: 80px; }
select:focus-visible, .round-btn:focus-visible, .cell:focus-visible, #btn-next:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.cell:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; z-index: 2; }
.info { font-size: .75rem; color: var(--progress-total); }

.rules { width: 100%; max-width: 690px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 8px; background: var(--surface-soft); border-radius: var(--radius-card); box-shadow: var(--shadow-sm); }
.rule { background: var(--tile-bg); color: var(--tile-ink); border-radius: var(--radius-tile); padding: 8px 12px; min-height: 64px; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 14px; font-weight: 500; }

.round-btn { width: var(--btn-size); height: var(--btn-size); padding: 0; border: 0; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-btn); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; transition: transform .2s cubic-bezier(.4,0,.2,1), box-shadow .2s; }
.round-btn:hover:not(:disabled) { transform: scale(1.05); box-shadow: 0 10px 15px -3px rgba(0,0,0,.1); }
.round-btn:active:not(:disabled) { transform: scale(.95); }
.round-btn:disabled { opacity: .5; cursor: default; }
#btn-next { font: inherit; font-weight: 600; font-size: 18px; width: 100%; max-width: 320px; margin-top: 24px; padding: 12px 24px; min-height: 48px; border-radius: 9999px; border: 3px solid var(--win-edge); background: var(--win-btn); color: #fff; cursor: pointer; transition: opacity .15s, transform .15s; }
#btn-next:hover { opacity: .9; } #btn-next:active { transform: scale(.95); }

.board { --bpad: 8px; --bw: 90vw; --cell: min(56px, calc((var(--bw) - 2 * var(--bpad) - (var(--n) - 1) * var(--gap)) / var(--n))); display: grid; grid-template-columns: repeat(var(--n), var(--cell)); grid-auto-rows: var(--cell); gap: var(--gap); padding: var(--bpad); max-width: 100%; background: var(--surface); border-radius: var(--radius-card); box-shadow: var(--shadow-btn); touch-action: manipulation; user-select: none; -webkit-user-select: none; }
@media (min-width: 601px) { .board { --bpad: 16px; --bw: min(90vw, 560px); } }
@media (min-width: 1024px) { .board { --bw: max(35vw, 440px); } }
.cell { position: relative; cursor: pointer; display: flex; align-items: center; justify-content: center; border: 2px solid transparent; padding: 0; min-height: 0; border-radius: var(--radius-cell); font-size: calc(var(--cell) * .62); line-height: 1; color: #2b2222; background: var(--c); font-weight: 400; transition: transform .2s, box-shadow .2s; }
.cell:hover { transform: scale(1.02); }
.cell:active { transform: scale(.95); }
.cell.bt { border-top-color: var(--region-edge); } .cell.bl { border-left-color: var(--region-edge); }
.cell.br { border-right-color: var(--region-edge); } .cell.bb { border-bottom-color: var(--region-edge); }
.cell .gfx { width: 83%; height: 83%; display: block; pointer-events: none; }
.cell .cat-gfx .eyes { transform-box: fill-box; transform-origin: center; animation: blink 4s infinite; }
.cell.conflict .dizzy-gfx { animation: dizzy-tilt 1.7s ease-in-out infinite; transform-origin: 50% 80%; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }
@keyframes dizzy-tilt { 0%, 100% { transform: rotate(-7deg); } 50% { transform: rotate(7deg); } }
@media (prefers-reduced-motion: reduce) { .cell .cat-gfx .eyes, .cell.conflict .dizzy-gfx { animation: none; } }
.cell.hint { box-shadow: 0 0 0 4px var(--hint-ring); z-index: 1; }

.message { min-height: 2.6em; font-size: 14px; margin: 0; text-align: center; max-width: 36em; }
.controls { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }

.win { position: fixed; inset: 0; background: var(--overlay); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; overflow: hidden; }
.win[hidden] { display: none; }
.win-content { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; text-align: center; width: 100%; max-width: 320px; }
.win-cat svg { width: 140px; height: auto; animation: cheer .8s ease-in-out infinite alternate; }
.win-title { margin: 8px 0 0; font-family: var(--font-heading); font-weight: 800; font-size: 40px; line-height: 1.1; color: var(--win-title); -webkit-text-stroke: 8px #fff; paint-order: stroke fill; text-shadow: 0 4px 0 var(--win-edge); }
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-piece { position: absolute; top: -20px; display: block; transform: rotate(var(--rot)); animation: fall 3s linear infinite; }
@keyframes fall { to { transform: translateY(110vh) rotate(calc(var(--rot) + 540deg)); } }
@keyframes cheer { from { transform: translateY(0); } to { transform: translateY(-8px); } }
@media (prefers-reduced-motion: reduce) { .confetti-piece, .win-cat svg { animation: none; } .confetti-piece { top: 20%; } }

@media (max-width: 600px) {
  .level-title { font-size: 20px; }
  .rule { font-size: 12px; padding: 8px; }
  #btn-next { max-width: 240px; }
  .win-title { font-size: 32px; }
}
