:root {
  --brand: #4f46e5;
  --on-brand: #fff;
  --brand-soft: rgb(79 70 229 / 10%);
  --ink: #1f2330;
  --muted: #6b7080;
  --line: #e4e6ee;
  --card: #ffffff;
  --bg: #f6f7fb;
  --good: #16a34a;
  --good-soft: #dcfce7;
  --warn: #eab308;
  --warn-soft: #fef9c3;
  --bad: #dc2626;
  --skip: #9ca3af;
  --skip-soft: #f3f4f6;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
/* Dark mode: ?theme=dark, or a customer's brand setting */
:root[data-theme="dark"] {
  --ink: #eef0f6;
  --muted: #a3a8b8;
  --line: #2e3242;
  --card: #171a24;
  --bg: #20242f;
  --good-soft: #14532d;
  --warn-soft: #422006;
  --skip-soft: #262a35;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: transparent; }
body { padding: 8px; }
[hidden] { display: none !important; }

.card {
  position: relative;
  max-width: 460px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 18px 12px;
  box-shadow: 0 2px 4px rgb(0 0 0 / 4%), 0 12px 32px -12px rgb(0 0 0 / 18%);
  overflow: hidden;
}
.card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 5px;
  background: linear-gradient(90deg, var(--brand), color-mix(in srgb, var(--brand) 55%, #fff));
}

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 750; font-size: 1.05rem; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand img { height: 28px; max-width: 90px; object-fit: contain; border-radius: 4px; }
.meta { color: var(--muted); font-size: .82rem; white-space: nowrap; background: var(--bg); padding: 2px 9px; border-radius: 999px; }

.view { text-align: center; padding: 10px 0 4px; animation: fadein .35s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
h1 { font-size: 1.45rem; margin: 10px 0 4px; letter-spacing: -0.01em; }
.sub { color: var(--muted); margin: 0 0 10px; font-size: .95rem; }
.streakline { display: inline-block; background: var(--warn-soft); color: var(--ink); font-weight: 650; font-size: .9rem; padding: 4px 12px; border-radius: 999px; margin: 0 0 12px; }
.rules { text-align: left; line-height: 1.55; padding-left: 20px; margin: 4px 0 18px; font-size: .95rem; color: var(--muted); }
.rules b { color: var(--ink); }

/* Start-screen animated tiles */
.demotiles { display: flex; justify-content: center; gap: 6px; margin: 8px 0 4px; }
.demotiles span {
  width: 38px; height: 42px; border-radius: 9px; background: var(--brand); color: var(--on-brand);
  display: grid; place-items: center; font-weight: 800; font-size: 1.2rem;
  box-shadow: 0 3px 0 color-mix(in srgb, var(--brand) 65%, #000);
  animation: bob 2.4s ease-in-out infinite;
}
.demotiles span:nth-child(2) { animation-delay: .12s; }
.demotiles span:nth-child(3) { animation-delay: .24s; }
.demotiles span:nth-child(4) { animation-delay: .36s; }
.demotiles span:nth-child(5) { animation-delay: .48s; }
@keyframes bob { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-7px) rotate(-3deg); } }

.btn {
  font: inherit; font-weight: 650;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 11px; padding: 9px 14px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  transition: transform .1s, filter .15s, background .15s;
}
.btn:hover { background: var(--bg); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); box-shadow: 0 3px 0 color-mix(in srgb, var(--brand) 65%, #000); }
.btn.primary:hover { filter: brightness(1.08); background: var(--brand); }
.btn.outline { background: transparent; border: 2px solid var(--brand); color: var(--ink); }
.btn.outline:hover { background: var(--brand-soft); }
.btn.ghost { border-color: transparent; color: var(--muted); background: transparent; }
.btn.big { width: 100%; padding: 13px; font-size: 1.05rem; }
.btn:focus-visible, .tile:focus-visible, .slot:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.progress { display: flex; justify-content: center; gap: 6px; margin: 4px 0 10px; }
.dot { width: 28px; height: 6px; border-radius: 3px; background: var(--line); transition: background .3s; }
.dot.current { background: var(--brand); }
.dot.solved { background: var(--good); }
.dot.hint { background: var(--warn); }
.dot.skipped { background: var(--skip); }

.clue { font-size: 1.05rem; color: var(--muted); margin: 6px 0 14px; min-height: 1.4em; }
.clue strong { color: var(--ink); }

.slots, .tiles { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; }
.slots { margin-bottom: 16px; }
.slot, .tile {
  width: 44px; height: 50px; border-radius: 10px;
  font: inherit; font-size: 1.4rem; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
  text-transform: uppercase;
}
.slot { border: 2px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer; transition: border-color .15s, background .2s; }
.slot.filled { border-color: var(--brand); background: var(--card); animation: pop .16s ease-out; }
.slot.locked { border-color: var(--warn); background: var(--warn-soft); cursor: default; }
@keyframes pop { 0% { transform: scale(.8); } 70% { transform: scale(1.08); } 100% { transform: scale(1); } }
.slots.correct .slot { border-color: var(--good); background: var(--good-soft); animation: flip .5s ease both; }
.slots.correct .slot:nth-child(2) { animation-delay: .05s; }
.slots.correct .slot:nth-child(3) { animation-delay: .1s; }
.slots.correct .slot:nth-child(4) { animation-delay: .15s; }
.slots.correct .slot:nth-child(5) { animation-delay: .2s; }
.slots.correct .slot:nth-child(6) { animation-delay: .25s; }
.slots.correct .slot:nth-child(7) { animation-delay: .3s; }
.slots.correct .slot:nth-child(8) { animation-delay: .35s; }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
.slots.revealed .slot { border-color: var(--skip); background: var(--skip-soft); color: var(--muted); }
.slots.wrong { animation: shake .4s; }
.slots.wrong .slot.filled { border-color: var(--bad); }
.tile {
  border: none; background: var(--brand); color: var(--on-brand); cursor: pointer;
  box-shadow: 0 3px 0 color-mix(in srgb, var(--brand) 65%, #000);
  transition: transform .08s, box-shadow .08s;
}
.tile:hover { transform: translateY(-2px); }
.tile:active { transform: translateY(2px); box-shadow: 0 1px 0 color-mix(in srgb, var(--brand) 65%, #000); }
.tile.used { visibility: hidden; }
.tiles.shuffling .tile { animation: shuf .3s ease; }
@keyframes shuf { 50% { transform: scale(.85) rotate(-6deg); } }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.actions { display: flex; justify-content: center; gap: 8px; margin-top: 20px; }
.timer { color: var(--muted); font-variant-numeric: tabular-nums; margin: 10px 0 0; font-size: .9rem; }

/* Done */
.grid { font-size: 1.9rem; letter-spacing: 4px; margin: 2px 0 10px; }
.stats { display: flex; justify-content: center; gap: 26px; margin-bottom: 14px; }
.stats div { display: flex; flex-direction: column; }
.stats strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); font-size: .76rem; }
.stats.small { gap: 18px; margin: 12px 0 4px; flex-wrap: wrap; }
.stats.small strong { font-size: 1.1rem; }
.toast { color: var(--good); font-weight: 650; margin: 8px 0 0; }
.cta { margin: 16px 0 4px; padding: 14px; border-radius: 14px; background: var(--brand-soft); }
.cta p { margin: 0 0 10px; font-weight: 650; }
.more { margin-top: 14px; text-align: left; }
.more summary { cursor: pointer; color: var(--muted); font-size: .9rem; text-align: center; }
.answers { margin: 12px auto 0; padding-left: 22px; max-width: 320px; color: var(--muted); line-height: 1.7; }
.answers strong { color: var(--ink); letter-spacing: 1px; }
.next { color: var(--muted); font-size: .88rem; margin: 14px 0 0; font-variant-numeric: tabular-nums; }

.foot { text-align: center; color: var(--muted); font-size: .72rem; margin-top: 12px; }
.foot a { color: inherit; }

/* Confetti */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 12px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: .8; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .confetti { display: none; }
}
@media (max-width: 380px) {
  .slot, .tile { width: 36px; height: 44px; font-size: 1.15rem; }
  .card { padding: 14px 12px 10px; }
  .stats { gap: 16px; }
}
