@font-face {
  font-family: Baloo;
  src: url("/assets/baloo-latin.woff2") format("woff2");
  font-weight: 400 800;
  font-display: swap;
}

:root {
  font-family: Baloo, "Trebuchet MS", sans-serif;
  color-scheme: dark;
  color: #fff4ed;
  background: #241234;
  --ink: #3e224f;
  --cream: #fff4ed;
  --amber: #ffdc8f;
  --comic: "Luckiest Guy", Baloo, sans-serif;
  --board-size: 7;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-height: 100svh;
  margin: 0;
  background:
    linear-gradient(180deg, #28103510, #26143820 62%, #29173766),
    #2a153c url("./art/feria-nocturna.webp") center / cover no-repeat;
}

button, a {
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 4px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: min(100%, 1110px);
  margin-inline: auto;
  padding: max(19px, env(safe-area-inset-top)) max(26px, env(safe-area-inset-right)) 0 max(26px, env(safe-area-inset-left));
}

nav { display: flex; gap: 8px; }

.control, .primary, .exit {
  font-weight: 800;
  color: var(--ink);
  text-decoration: none;
}

.control, .primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  border: 0;
  border-radius: 13px;
  padding: 5px 14px;
  background: #faeaf8;
  box-shadow: inset 0 -4px #dac0e3, 0 3px 0 #160b26;
  line-height: 1;
}

.control svg { width: 22px; height: 22px; flex: none; }
.control.round { width: 44px; padding: 8px; }
.control:active, .primary:active { translate: 0 2px; }
.control:disabled { opacity: .55; }

main {
  display: grid;
  grid-template-columns: minmax(215px, .74fr) minmax(0, 1fr);
  align-items: center;
  align-content: center;
  gap: clamp(24px, 5vw, 72px);
  width: min(100%, 1070px);
  min-height: calc(100svh - 64px);
  margin-inline: auto;
  padding: 20px 32px max(28px, env(safe-area-inset-bottom));
}

.identity {
  display: grid;
  justify-items: center;
  align-content: center;
  text-align: center;
}

.wordmark { z-index: 1; }
.brand-kicker {
  margin: 0 0 14px;
  color: #ffd19b;
  font-size: clamp(14px, 1.6vw, 18px);
  font-weight: 800;
  line-height: 1.05;
}

h1 {
  margin: 0;
  color: #fff1fa;
  font: 400 clamp(53px, 6.8vw, 93px)/.84 var(--comic);
  letter-spacing: -.033em;
  transform: rotate(-5deg);
}

h1 span, h1 b {
  display: block;
  width: max-content;
  margin-inline: auto;
  paint-order: stroke fill;
  -webkit-text-stroke: .125em #542154;
  text-shadow: 0 .065em #ed72b6, 0 .12em #542154, 0 .17em #542154;
}

h1 b {
  margin-top: .08em;
  font-weight: 400;
  font-size: 1.09em;
  letter-spacing: 0;
  color: #ffdb74;
  -webkit-text-stroke-color: #622568;
  text-shadow: 0 .06em #e28b6c, 0 .115em #622568, 0 .15em #622568;
}

.toy-stack {
  position: relative;
  width: min(94%, 320px);
  aspect-ratio: 1.38;
  margin: 12px 0 10px;
  isolation: isolate;
}

.toy-stack::before {
  position: absolute;
  inset: 17% -18% -12%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(ellipse, #d55dba6b, #a34aab24 53%, transparent 72%);
  content: "";
}

.toy-stack img {
  position: absolute;
  object-fit: contain;
  filter: drop-shadow(0 9px 10px #180a24a6);
  user-select: none;
}

.hero-mochi { z-index: 2; width: 57%; left: 21%; top: 4%; transform: rotate(-9deg); }
.hero-cube { width: 48%; left: 0; bottom: 4%; transform: rotate(-16deg); }
.hero-butter { width: 56%; right: -2%; bottom: 1%; transform: rotate(12deg); }

.toy-stack i {
  position: absolute;
  z-index: 2;
  color: #ffe391;
  font: normal 42px/1 Georgia, serif;
  text-shadow: 0 2px 0 #8d4a9e, 0 5px 15px #ffab6870;
}

.toy-stack i:first-child { right: 2%; top: 4%; }
.toy-stack i:nth-child(2) { left: 6%; top: 16%; color: #ffdafa; font-size: 29px; }
.toy-stack i:nth-child(3) { right: 17%; bottom: 3%; font-size: 26px; }

.score {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 14px 7px 9px;
  color: #fff4dc;
  background: #59285e;
  border: 1px solid #bb72a5;
  border-radius: 14px;
  box-shadow: 0 4px #1e102c, inset 0 1px #f1acd45c;
}

.score svg { width: 30px; height: 30px; transform: rotate(-9deg); }
.score div { display: flex; gap: 8px; align-items: center; line-height: 1; }
.score span { color: #ffe6f6; font-size: 14px; font-weight: 800; }
.score strong { color: var(--amber); font: 400 clamp(21px, 2.6vw, 28px)/1 var(--comic); }

.cabinet {
  width: 100%;
  max-width: 518px;
  justify-self: center;
}

.level-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px 2px;
}

h2.level-name {
  margin: 0;
  color: #fff2e3;
  font-family: inherit;
  font-size: clamp(19px, 2.5vw, 26px);
  font-weight: 800;
  line-height: 1.04;
  text-wrap: balance;
}

.control.level-select {
  flex-shrink: 0;
  background: #59285e;
  box-shadow: inset 0 -4px #3a1b4d, inset 0 1px #df9ad280, 0 3px #210f31;
  color: #fff2ee;
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(52px, .57fr) minmax(0, 2.1fr) minmax(60px, .65fr);
  gap: 7px;
  margin-bottom: 10px;
}

.dashboard > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 66px;
  padding: 5px 3px 7px;
  border-radius: 13px;
  background: #e9d4fa;
  box-shadow: inset 0 2px #fff9, inset 0 -4px #bc93db, 0 4px #1e0f32;
  color: var(--ink);
  line-height: 1;
  text-align: center;
}

.dashboard > div > span { font-size: clamp(12px, 1.3vw, 15px); font-weight: 800; }
.meter strong { margin-top: 3px; font: 400 clamp(23px, 3.5vw, 36px)/1 var(--comic); }
.dashboard .level { background: #edddfb; }
.dashboard .moves { background: #ffd78d; box-shadow: inset 0 2px #fff9, inset 0 -4px #e9a75e, 0 4px #1e0f32; }
.dashboard .moves.low { color: #651438; background: #ffa9b3; box-shadow: inset 0 2px #fff9, inset 0 -4px #db718c, 0 4px #1e0f32; }
.dashboard .goals { background: #fff2de; box-shadow: inset 0 2px #fff, inset 0 -4px #efc8b3, 0 4px #1e0f32; }

#goals {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px 7px;
  margin-top: 2px;
}

.goal {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: clamp(16px, 2vw, 23px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.goal img, .goal svg { width: clamp(20px, 3.8vw, 31px); height: clamp(20px, 3.8vw, 31px); object-fit: contain; flex: none; }
.goal.done { color: #22664c; }

.tray {
  position: relative;
  isolation: isolate;
  padding: clamp(6px, 1vw, 10px);
  border: 1px solid #e4b7fc;
  border-radius: 23px;
  background: linear-gradient(150deg, #d5a3f0 0%, #ad6fce 35%, #7448b0 68%, #a376c9 100%);
  box-shadow: inset 0 1px 0 #fff9, inset 0 -5px #573581a8, 0 6px #251438, 0 12px 27px #1a0b2859;
}

#board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--board-size), minmax(0, 1fr));
  gap: clamp(2px, .4vw, 4px);
  overflow: hidden;
  padding: clamp(3px, .55vw, 5px);
  border: 1px solid #d4b2f36e;
  border-radius: 14px;
  background: #2c1a48;
  box-shadow: inset 0 3px 9px #1a102f;
  touch-action: pinch-zoom;
  user-select: none;
}

.tile {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  aspect-ratio: 1;
  border: 0;
  border-radius: 23%;
  padding: 0;
  background: linear-gradient(145deg, #503762, #402956);
  box-shadow: inset 0 2px 3px #2e194a75, inset 0 -1px #c78fee4a;
  touch-action: pinch-zoom;
}

.tile:nth-child(even) { background: linear-gradient(145deg, #59426d, #4b335e); }

.tile .toy {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.tile .toy img {
  position: absolute;
  width: 92%;
  height: 92%;
  object-fit: contain;
  filter: drop-shadow(0 2px 1px #211235ba);
}

.tile[data-toy="3"] .toy img { transform: rotate(16deg) scale(.92, 1.02); }

.tile[data-coat]::before {
  position: absolute;
  inset: 0;
  border: 2px solid #b4f2ff;
  border-radius: inherit;
  background:
    radial-gradient(circle at 13% 17%, #effcff 0 4%, #cbf8ff66 5% 10%, transparent 11%),
    radial-gradient(circle at 83% 79%, #f4ffff 0 5%, #acf7ff99 6% 12%, transparent 13%),
    radial-gradient(circle at 78% 14%, #f4ffff 0 4%, transparent 6%),
    linear-gradient(150deg, #568fa4, #355487);
  content: "";
}

.tile:is([data-power="1"], [data-power="2"], [data-power="3"]) .toy::before {
  position: absolute;
  inset: 7%;
  border-radius: 30%;
  background: radial-gradient(ellipse, #fff9ad80 37%, #ffe75a95 71%, #ffca5333);
  box-shadow: 0 0 6px 1px #ffe455ab;
  content: "";
}

.emblem {
  position: absolute;
  display: none;
  width: 46%;
  height: 46%;
  right: 0;
  top: 0;
  filter: drop-shadow(0 1px 1px #38143b) drop-shadow(0 1px 0 #fff6ad);
}

.tile:is([data-power="1"], [data-power="2"], [data-power="3"]) .emblem { display: block; }
.tile[data-power="1"] .emblem { transform: rotate(74deg); }
.tile.hinted { background: #80568f; }
.tile:is(.selected, [aria-pressed="true"]) { z-index: 1; background: #ab6ba5; }
.tile:is(.hinted, .selected, [aria-pressed="true"])::after {
  position: absolute;
  inset: 0;
  border: 2px solid #ffd684;
  border-radius: inherit;
  pointer-events: none;
  content: "";
}
.tile:is(.selected, [aria-pressed="true"])::after { border: 3px solid #ffefa0; }
.tile:focus-visible { z-index: 2; outline: 2px dashed #fff5cf; outline-offset: -4px; }
.tile:active .toy { scale: 1.06 .91; transform-origin: 50% 85%; }

@media (hover: hover) {
  .control:not(:disabled):hover { filter: brightness(1.08); }
  .tile:not(.selected, .hinted, [aria-pressed="true"]):hover {
    background: #664a7b;
    box-shadow: inset 0 0 0 1px #f5d8ff80;
  }
}

.tray.is-combo { box-shadow: inset 0 1px #fff9, inset 0 -5px #573581a8, 0 6px #251438, 0 0 30px #f0a5fbad; }

#effects {
  position: absolute;
  z-index: 3;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
  pointer-events: none;
}

.pop-label, .streak {
  position: absolute;
  z-index: 3;
  color: #ffec9e;
  font: 400 clamp(22px, 3.6vw, 37px)/1 var(--comic);
  paint-order: stroke fill;
  -webkit-text-stroke: .17em #692863;
  text-shadow: 0 .08em #692863;
  text-align: center;
  white-space: nowrap;
}

.pop-label {
  color: var(--burst-color, #ffec9e);
  transform: translateX(-50%);
}

.streak {
  inset: 10px 0 auto;
  margin-inline: auto;
  width: max-content;
  padding: 8px 15px 5px;
  border: 1px solid #f5b5fa;
  border-radius: 50px;
  background: #46215a;
  box-shadow: 0 4px 0 #2d123b, 0 0 22px #db94ffb8;
  font-size: clamp(21px, 4vw, 34px);
  pointer-events: none;
}

.streak[data-big] { color: #fff4b9; border-color: #ffd981; }

.speck {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--burst-color, #fff7ac);
  clip-path: polygon(50% 0, 65% 33%, 100% 50%, 65% 67%, 50% 100%, 34% 67%, 0 50%, 34% 33%);
}

.speck:nth-of-type(3n) { background: #fff7ac; }
.speck:nth-of-type(4n) { background: #fff9f6; }

.bubble-ring, .power-wave {
  position: absolute;
  translate: -50% -50%;
  border: 2px solid var(--burst-color);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--burst-color), inset 0 0 8px var(--burst-color);
}

.power-wave[data-shape="row"], .power-wave[data-shape="column"] {
  border: 0;
  border-radius: 50%;
  background: #fff6ce;
  box-shadow: 0 0 10px 2px #ffd880, 0 0 20px #ff8dde;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 15px 2px 0;
}

#status { margin: 0; color: #f9e4f8; font-size: 16px; font-weight: 700; line-height: 1.12; text-wrap: pretty; }
.actions .control { flex-shrink: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

dialog {
  width: min(400px, calc(100% - 24px));
  max-height: calc(100svh - 24px);
  padding: 0;
  border: 2px solid #c480d0;
  border-radius: 22px;
  background: #fff4ec;
  box-shadow: 0 6px #583061, 0 18px 65px #16091e99;
  color: var(--ink);
  color-scheme: light;
}

dialog::backdrop { background: #1d0e30ac; backdrop-filter: blur(4px); }
dialog :is(button, a):focus-visible { outline-color: #7a347c; }
.dialog-in { padding: clamp(16px, 5vw, 26px); text-align: center; }
dialog h2 { margin: 3px 0 9px; color: #79377c; font: 400 clamp(27px, 5vw, 36px)/.98 var(--comic); }
dialog p { margin: 10px 0; font-size: 17px; line-height: 1.23; }
.recipe { display: flex; align-items: center; gap: 10px; text-align: left; }
.recipe svg { flex: none; width: 34px; height: 34px; }
.recipe p { margin: 6px 0; }

.primary {
  width: 100%;
  min-height: 48px;
  margin-top: 15px;
  background: #ffdc87;
  box-shadow: inset 0 -4px #eeb264, 0 3px #956075;
  font-size: 20px;
}

.exit { display: inline-block; margin-top: 13px; text-decoration: underline; }
#result-toy { width: 102px; height: 102px; object-fit: contain; }
.result-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; margin-top: 12px; }
.result-actions .primary { margin-top: 0; }
.result-actions .exit { grid-column: 1 / -1; grid-row: 2; margin-top: 0; }

#result[data-outcome="won"] { width: min(462px, calc(100% - 24px)); border-color: #f4bb78; }
#result[data-outcome="won"] .dialog-in { background: linear-gradient(#ffeddc 24%, #fff8ed 75%); }
#result[data-outcome="won"] :is(h2, p) { text-wrap: balance; }

.victory-stage {
  isolation: isolate;
  position: relative;
  overflow: hidden;
  height: clamp(182px, 54vw, 264px);
  margin: -2px -2px 16px;
  border: 1px solid #b476b8;
  border-radius: 17px;
  background: radial-gradient(ellipse at 50% 75%, #d187b9 0%, #914e92 35%, #482258 71%, #321642);
}

.victory-stage::after {
  position: absolute;
  z-index: -1;
  left: 8%;
  right: 8%;
  bottom: 5%;
  height: 15%;
  border-radius: 50%;
  background: radial-gradient(ellipse, #ffd783, #fda871 62%, #9a4d80);
  box-shadow: 0 8px 0 #67355f, 0 14px 22px #310e3e9e;
  content: "";
}

.victory-mascot {
  position: absolute;
  z-index: 1;
  left: var(--mascot-x);
  bottom: 9%;
  width: var(--mascot-size);
  height: auto;
  translate: -50%;
  rotate: var(--mascot-tilt);
  filter: drop-shadow(0 5px 6px #40193f80);
}

.victory-mascot[data-seat="0"] { --mascot-x: 25%; --mascot-size: 36%; --mascot-tilt: -9deg; --entrance: 130ms; }
.victory-mascot[data-seat="1"] { --mascot-x: 50%; --mascot-size: 49%; --mascot-tilt: 0deg; --entrance: 0ms; z-index: 2; }
.victory-mascot[data-seat="2"] { --mascot-x: 76%; --mascot-size: 36%; --mascot-tilt: 9deg; --entrance: 210ms; }

.victory-stars {
  position: absolute;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  inset: 5% 0 auto;
}

.victory-stars svg { width: clamp(21px, 6vw, 33px); aspect-ratio: 1; rotate: -16deg; }
.victory-stars svg:nth-child(2) { scale: 1.26; translate: 0 -17%; rotate: 0deg; }
.victory-stars svg:nth-child(3) { rotate: 16deg; }
#result[data-finale] .victory-stars { gap: 18px; filter: drop-shadow(0 0 8px #ffe171ac); }

#result[data-celebrating] .victory-mascot { animation: mascot-cheer 760ms var(--entrance) cubic-bezier(.16, 1, .3, 1) both; }
#result[data-celebrating] .victory-stars { animation: stars-cheer 630ms 230ms cubic-bezier(.16, 1, .3, 1) both; }

@keyframes mascot-cheer {
  0% { transform: translateY(82%) scale(.64, .56); opacity: 0; }
  29% { transform: translateY(-8%) scale(.93, 1.09); opacity: 1; }
  51% { transform: translateY(4%) scale(1.13, .83); }
  70% { transform: translateY(-5%) scale(.98, 1.06); }
  100% { transform: none; }
}

@keyframes stars-cheer {
  0% { transform: translateY(24px) scale(.3); opacity: 0; }
  60% { transform: translateY(-3px) scale(1.18); opacity: 1; }
  100% { transform: none; }
}

#victory-confetti {
  position: fixed;
  z-index: 5;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#levels { width: min(465px, calc(100% - 24px)); }
#levels .dialog-in { text-align: left; }
.map-heading {
  position: sticky;
  z-index: 1;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding-bottom: 6px;
  background: #fff4ec;
}
.map-heading h2 { margin: 4px 0 0; }
.map-close { flex: none; box-shadow: inset 0 -3px #dac0e3, 0 2px #cda9c8; }
.chapter h3 { margin: 12px 0 3px; color: #713679; font-size: 18px; line-height: 1.1; }
.chapter, .level-list { display: grid; gap: 6px; }
.level-list { margin: 0; padding: 0; list-style: none; }
.level-entry {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  width: 100%;
  padding: 4px 9px 5px 5px;
  border: 0;
  border-radius: 12px;
  background: #f0e0f6;
  box-shadow: inset 0 -2px #c29bce;
  color: var(--ink);
  text-align: left;
  line-height: 1;
}

.level-entry[data-progress="current"] { background: #ffdd90; box-shadow: inset 0 -2px #dba46d; }
.level-entry[data-progress="complete"] { background: #e5f5e2; box-shadow: inset 0 -2px #aed1b6; }
.level-entry[data-progress="locked"] { background: #f4e9ee; box-shadow: none; color: #725767; }
.level-entry small { font-size: 12px; font-weight: 800; text-align: end; }
.level-numeral {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 9px;
  background: #774b92;
  color: #fff4ee;
  font-weight: 800;
}
.level-entry[data-progress="complete"] .level-numeral { background: #337863; }
.level-entry[data-progress="locked"] .level-numeral { background: #e5d0db; color: #725767; }

@media (min-width: 681px) and (max-height: 830px) {
  main { padding-top: 12px; }
  .cabinet { max-width: clamp(332px, 100svh - 288px, 500px); }
  .toy-stack { width: min(91%, 276px); }
}

@media (max-width: 680px) {
  body {
    background:
      radial-gradient(ellipse at 50% 25%, #67306880, transparent 55%),
      linear-gradient(155deg, #30133d, #251735 70%, #301942);
  }
  header { padding: max(9px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left)); }
  nav { gap: 6px; }
  main {
    display: block;
    width: min(100%, 474px);
    min-height: 0;
    padding: 12px max(9px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(9px, env(safe-area-inset-left));
  }

  .identity {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    justify-items: start;
    gap: 5px 8px;
    margin: 0 2px 15px;
    text-align: left;
  }

  .brand-kicker { margin: 0 0 5px; font-size: 13px; }
  h1 { font-size: clamp(30px, 8.1vw, 45px); line-height: .88; transform: rotate(-3deg); }
  h1 span, h1 b { display: inline-block; }
  h1 b { margin: 0; font-size: .97em; }
  .toy-stack { display: none; }

  .score { gap: 3px; padding: 4px 7px 4px 5px; border-radius: 10px; }
  .score svg { width: 17px; height: 17px; }
  .score div { gap: 0; flex-direction: column; align-items: flex-start; }
  .score span { font-size: 10px; }
  .score strong { font-size: clamp(15px, 4vw, 21px); }
  .level-heading { margin-bottom: 7px; }
  h2.level-name { font-size: clamp(18px, 5vw, 22px); }
  .dashboard { gap: 5px; margin-bottom: 7px; }
  .dashboard > div { min-height: 52px; border-radius: 11px; }
  .tray { border-radius: 17px; }
  #board { border-radius: 10px; }
  .actions { margin-top: 11px; gap: 6px; }
  #status { font-size: 15px; }
  .control { padding-inline: 10px; }
  .control.level-select { min-height: 40px; font-size: 14px; }
  .control.level-select svg { width: 17px; height: 17px; }
}

@media (max-width: 350px) {
  #back span { display: none; }
  #back { width: 44px; padding-inline: 8px; }
  h1 { font-size: 29px; }
  #goals { gap: 3px; }
  .goal { gap: 1px; }
  .tray { padding: 4px; }
}
