@font-face {
  font-family: Fredoka;
  font-style: normal;
  font-weight: 600 700;
  font-display: swap;
  src: url("../fonts/fredoka-latin.woff2") format("woff2");
}

@font-face {
  font-family: Nunito;
  font-style: normal;
  font-weight: 700 800;
  font-display: swap;
  src: url("../fonts/nunito-latin.woff2") format("woff2");
}

:root {
  --ink: #fff6e8;
  --gold: #f0c14a;
  --gold-deep: #b86a12;
  --wood: #3a2416;
  --hole: #071510;
  --board: #0e2a22;
  --pc: 20px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: Nunito, "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    radial-gradient(ellipse 80% 38% at 50% -6%, rgba(255, 186, 84, .45), transparent 54%),
    radial-gradient(ellipse 34% 28% at 4% 92%, rgba(226, 61, 140, .22), transparent 62%),
    radial-gradient(ellipse 30% 26% at 98% 78%, rgba(46, 196, 182, .18), transparent 64%),
    linear-gradient(180deg, #3c1c12 0%, #180d0a 42%, #0b1a16 100%);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

.page {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.flags {
  width: min(520px, calc(100% - 140px));
  margin: 10px auto 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  position: relative;
  height: 30px;
}

.flags::before {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  top: 0;
  height: 2px;
  border-radius: 2px;
  background: rgba(255, 236, 214, .8);
}

.flags span {
  width: 15px;
  height: 22px;
  margin-top: 2px;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  animation: sway 2.8s ease-in-out infinite;
}

.flags span:nth-child(odd) { animation-delay: -1.4s; }
.flags span:nth-child(6n+1) { background: #2f9e44; }
.flags span:nth-child(6n+2) { background: #f5c518; }
.flags span:nth-child(6n+3) { background: #e23d8c; }
.flags span:nth-child(6n+4) { background: #4da3ff; }
.flags span:nth-child(6n+5) { background: #ff6b4a; }
.flags span:nth-child(6n+6) { background: #7b5cff; }

@keyframes sway {
  0%, 100% { transform: rotate(-8deg); }
  50% { transform: rotate(8deg); }
}

.title {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px 20px 8vh;
  gap: 6px;
}

.decor {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.decor .gem {
  width: 26px;
  height: 26px;
  border-radius: 7px;
}

.decor .gem:nth-child(1) { transform: translateY(5px); }
.decor .gem:nth-child(2) { transform: translateY(-6px); }
.decor .gem:nth-child(3) { transform: translateY(2px); }
.decor .gem:nth-child(4) { transform: translateY(-3px); }

.logo {
  margin: 0;
  font-family: Fredoka, "Trebuchet MS", sans-serif;
  font-weight: 700;
  font-size: clamp(64px, 16vw, 112px);
  line-height: .86;
  letter-spacing: 0.02em;
  color: #fff8ee;
  text-shadow:
    0 2px 0 #ffe08a,
    0 5px 0 #e0a020,
    0 9px 0 #b86a12,
    0 14px 22px rgba(0, 0, 0, .38);
}

.tag {
  margin: 8px 0 18px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .01em;
  color: #ffe7c2;
}

.how, .hint, .title-record {
  margin: 0;
  color: #f3e0c8;
  font-weight: 700;
  line-height: 1.45;
}

.how {
  margin-top: 18px;
  font-size: 15px;
  max-width: 280px;
  opacity: .88;
}

.title-record {
  margin-top: 12px;
  color: var(--gold);
  letter-spacing: .04em;
}

.btn {
  appearance: none;
  font-family: Fredoka, "Trebuchet MS", sans-serif;
  font-weight: 700;
  font-size: 22px;
  color: #3d2408;
  background: linear-gradient(180deg, #ffe7a3 0%, #ffc83d 48%, #f0a31a 100%);
  border: 0;
  border-radius: 999px;
  padding: 14px 34px;
  min-width: 210px;
  cursor: pointer;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .75),
    0 5px 0 var(--gold-deep),
    0 14px 22px rgba(0, 0, 0, .28);
}

.btn:hover { filter: brightness(1.04); }

.btn:active {
  transform: translateY(4px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .75),
    0 1px 0 var(--gold-deep),
    0 6px 12px rgba(0, 0, 0, .28);
}

.btn:focus-visible,
.iconbtn:focus-visible,
.textbtn:focus-visible {
  outline: 3px solid #fff6e8;
  outline-offset: 3px;
}

.game {
  --board: min(100%, 620px, max(260px, calc(100dvh - 372px)));
  flex: 1;
  width: min(680px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 8px;
  padding: 4px 16px 16px;
}

.brand {
  margin: 0;
  font-family: Fredoka, "Trebuchet MS", sans-serif;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: .16em;
  color: #fff8ee;
  text-shadow: 0 2px 0 #b86a12;
}

.scores {
  width: var(--board);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.plaque {
  background: linear-gradient(180deg, rgba(255, 246, 232, .1), rgba(0, 0, 0, .22));
  border: 1px solid rgba(240, 193, 74, .4);
  border-radius: 16px;
  padding: 6px 10px 8px;
  text-align: center;
}

.plaque span {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #e7c36a;
}

.plaque b {
  display: block;
  font-family: Fredoka, "Trebuchet MS", sans-serif;
  font-size: clamp(28px, 7vw, 34px);
  line-height: 1.05;
  color: #fff8ee;
  font-variant-numeric: tabular-nums;
}

.plaque.record {
  border-color: #ffe08a;
  box-shadow: 0 0 18px rgba(255, 196, 70, .32);
}

.meta {
  width: var(--board);
  min-height: 22px;
  display: flex;
  justify-content: space-between;
  padding: 0 6px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .04em;
  color: rgba(255, 246, 232, .72);
}

#streak.hot {
  color: #ffc14a;
  text-shadow: 0 0 12px rgba(255, 160, 40, .55);
}

.frame {
  width: var(--board);
  padding: 10px;
  border-radius: 26px;
  background: linear-gradient(165deg, #6a4630 0%, #3a2416 38%, #24160f 100%);
  box-shadow:
    0 0 0 2px #f0d48a,
    0 0 0 5px #6d4318,
    0 18px 36px rgba(0, 0, 0, .42),
    inset 0 1px 0 rgba(255, 255, 255, .3);
  position: relative;
}

.frame.on-fire {
  box-shadow:
    0 0 0 2px #ffe7a8,
    0 0 0 5px #c45c12,
    0 0 22px rgba(255, 140, 40, .5),
    0 18px 36px rgba(0, 0, 0, .42),
    inset 0 1px 0 rgba(255, 255, 255, .3);
}

.frame.shake { animation: shake .36s linear; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px) rotate(-.4deg); }
  40% { transform: translateX(4px) rotate(.4deg); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

.grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 5px;
  padding: 8px;
  border-radius: 16px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, .06), transparent 46%),
    linear-gradient(180deg, #12382c, #0c241d);
  touch-action: none;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 22%;
  background: var(--hole);
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, .5);
}

.cell.hot {
  background: #14382c;
  animation: hot 1.15s ease-in-out infinite;
}

@keyframes hot {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(240, 193, 74, .28); }
  50% { box-shadow: inset 0 0 0 2px rgba(255, 226, 150, .95), inset 0 0 10px rgba(255, 200, 80, .35); }
}

.cell.will-clear {
  animation: none;
  background: #1d4a34;
  box-shadow: inset 0 0 0 2px #ffe9a8, inset 0 0 14px rgba(255, 210, 90, .55);
  z-index: 1;
}

.cell.bad::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(176, 32, 42, .5);
  z-index: 2;
}

.gem {
  position: relative;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .35),
    inset 0 -4px 0 rgba(0, 0, 0, .22);
}

.gem::after {
  content: "";
  position: absolute;
  left: 24%;
  right: 24%;
  top: 10%;
  height: 14%;
  border-radius: 99px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .4), rgba(255, 255, 255, 0));
  pointer-events: none;
}

.cell .gem {
  position: absolute;
  inset: 0;
  border-radius: 22%;
  opacity: 0;
  transform: scale(.55);
}

.cell.on .gem {
  opacity: 1;
  transform: none;
}

.cell.pop { z-index: 1; }

.cell.pop .gem { animation: land .2s cubic-bezier(.2, 1.55, .36, 1); }

@keyframes land {
  0% { transform: scale(.4); }
  100% { transform: scale(1); }
}

.cell.clearing { z-index: 2; }

.cell.clearing .gem { animation: burst .32s ease forwards; }

@keyframes burst {
  0% { transform: scale(1); filter: brightness(1); }
  30% { transform: scale(1.16); filter: brightness(1.85); }
  100% { transform: scale(.2); filter: brightness(2); opacity: 0; }
}

.gem[data-c="magenta"] { background: linear-gradient(180deg, #ff8d98 0%, #ff2d42 46%, #c00022 100%); }
.gem[data-c="gold"] { background: linear-gradient(180deg, #fff3a0 0%, #ffe03a 46%, #e09400 100%); }
.gem[data-c="lime"] { background: linear-gradient(180deg, #8dff9e 0%, #22c24a 46%, #0c7a28 100%); }
.gem[data-c="teal"] { background: linear-gradient(180deg, #7ef6f0 0%, #14c8c4 46%, #0a7a78 100%); }
.gem[data-c="coral"] { background: linear-gradient(180deg, #ffc08a 0%, #ff7a1a 46%, #e04800 100%); }
.gem[data-c="violet"] { background: linear-gradient(180deg, #d7b0ff 0%, #9a3dff 46%, #5c14b8 100%); }
.gem[data-c="sky"] { background: linear-gradient(180deg, #9ec6ff 0%, #2f7dff 46%, #143fb8 100%); }

.hint {
  min-height: 1.3em;
  font-size: 13px;
  text-align: center;
  opacity: .82;
}

.hint.gone {
  visibility: hidden;
  height: 0;
  min-height: 0;
  overflow: hidden;
}

.tray {
  --pc: clamp(16px, 3.2vw, 26px);
  width: var(--board);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  min-height: 128px;
}

.slot {
  min-height: 128px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: transparent;
  touch-action: none;
  cursor: grab;
}

.slot.empty {
  cursor: default;
  background: rgba(0, 0, 0, .1);
  box-shadow: inset 0 0 0 1.5px rgba(240, 193, 74, .18);
}

.slot.coach {
  animation: coach 1.35s ease-in-out infinite;
}

@keyframes coach {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 193, 74, 0); }
  50% { box-shadow: 0 0 0 7px rgba(240, 193, 74, .16); }
}

.slot.nope .mini { opacity: .38; }

.slot:not(.empty):hover .mini { transform: translateY(-3px); }

.slot.shake { animation: slotshake .28s ease; }

@keyframes slotshake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-5px); }
  70% { transform: translateX(5px); }
}

.mini {
  display: grid;
  gap: 4px;
  transition: transform .15s ease;
}

.mini .gem {
  width: var(--pc);
  height: var(--pc);
  border-radius: 22%;
  display: block;
}

.textbtn {
  appearance: none;
  font-family: Nunito, "Trebuchet MS", sans-serif;
  font-weight: 800;
  font-size: 14px;
  color: #f6e6d2;
  background: transparent;
  border: 1px solid rgba(240, 193, 74, .35);
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
}

.textbtn:hover { background: rgba(255, 246, 232, .06); }

.home {
  position: fixed;
  z-index: 30;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(240, 193, 74, .5);
  background: rgba(28, 14, 10, .55);
  color: #fff6e8;
  text-decoration: none;
  backdrop-filter: blur(8px);
}

.home:active { transform: translateY(1px) scale(.98); }

.iconbtn {
  position: fixed;
  z-index: 30;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(240, 193, 74, .5);
  background: rgba(28, 14, 10, .55);
  color: #fff6e8;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.iconbtn .slash { display: none; }
.iconbtn.is-muted .wave { display: none; }
.iconbtn.is-muted .slash { display: block; }

.iconbtn:active { transform: translateY(1px) scale(.98); }

#floater {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 7;
  pointer-events: none;
  filter: drop-shadow(0 14px 10px rgba(0, 0, 0, .38));
}

.floater-grid {
  display: grid;
}

.floater-grid .gem {
  border-radius: 22%;
  display: block;
}

.phrase {
  position: fixed;
  z-index: 8;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  opacity: 0;
}

.phrase b {
  display: block;
  font-family: Fredoka, "Trebuchet MS", sans-serif;
  font-size: clamp(36px, 8vw, 60px);
  font-weight: 700;
  line-height: .92;
  color: #fff8ee;
  text-shadow:
    0 3px 0 #b86a12,
    0 10px 18px rgba(0, 0, 0, .35);
}

.phrase small {
  display: block;
  margin-top: 2px;
  font-family: Fredoka, "Trebuchet MS", sans-serif;
  font-size: 26px;
  font-weight: 700;
  color: #ffe08a;
  text-shadow: 0 2px 0 #7a4510;
}

.phrase.show { animation: phrase 1.15s cubic-bezier(.18, 1.2, .32, 1) forwards; }

@keyframes phrase {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.72); }
  16% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  74% { opacity: 1; transform: translate(-50%, -56%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(.98); }
}

.float {
  position: fixed;
  z-index: 8;
  transform: translate(-50%, 0);
  pointer-events: none;
  opacity: 0;
  font-family: Fredoka, "Trebuchet MS", sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: #ffe9a8;
  text-shadow: 0 2px 0 #7a4a12;
}

.float.go { animation: rise .7s ease forwards; }

@keyframes rise {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(.8); }
  22% { opacity: 1; transform: translate(-50%, -4px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -34px) scale(1); }
}

.bump { animation: bump .24s cubic-bezier(.2, 1.4, .4, 1); }

@keyframes bump {
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(10, 6, 4, .58);
  backdrop-filter: blur(8px);
}

.card {
  width: min(92vw, 400px);
  text-align: center;
  padding: 26px 20px 22px;
  border-radius: 28px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 196, 87, .22), transparent 56%),
    linear-gradient(180deg, #4a2b1c, #26140e);
  border: 1px solid rgba(240, 193, 74, .55);
  box-shadow:
    0 24px 70px rgba(0, 0, 0, .5),
    inset 0 1px 0 rgba(255, 255, 255, .22);
  animation: popin .34s cubic-bezier(.2, 1.25, .36, 1);
}

@keyframes popin {
  from { opacity: 0; transform: translateY(10px) scale(.92); }
  to { opacity: 1; transform: none; }
}

.eyebrow {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--gold);
}

.card h2 {
  margin: 4px 0 0;
  font-family: Fredoka, "Trebuchet MS", sans-serif;
  font-size: 34px;
  font-weight: 700;
  color: #fff8ee;
}

.final-score {
  margin: 6px 0 0;
  font-family: Fredoka, "Trebuchet MS", sans-serif;
  font-size: 68px;
  line-height: .95;
  font-variant-numeric: tabular-nums;
  color: #fff8ee;
  text-shadow: 0 3px 0 #c4842a;
}

.stats {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0 20px;
  padding: 0;
}

.stats li {
  background: rgba(0, 0, 0, .22);
  border-radius: 14px;
  padding: 10px 4px 8px;
}

.stats span {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #e7c98a;
}

.stats b {
  display: block;
  margin-top: 2px;
  font-family: Fredoka, "Trebuchet MS", sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: #fff6e8;
}

@media (max-width: 380px) {
  .tag { font-size: 16px; }
  .card h2 { font-size: 28px; }
  .final-score { font-size: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  .flags span,
  .cell.hot,
  .slot.coach,
  .frame.shake { animation: none; }
}
