/* WordMelt — melting candy-glass look. 4 worlds are swapped with [data-world] on #app. */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: #1b1033; }
body { font-family: "Fredoka", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible, .board:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* ---------- worlds (colours checked by tools/contrast-check.mjs) ---------- */
#app { --bg1: #FFE9E3; --bg2: #FFD6E8; --bg3: #D9F7EA; --ui: #4A2340; --ui2: #7a4a73; --accent: #E0386C; --ink: #3B1F2B; --panel: rgba(255,255,255,.72); --panel-ink: #4A2340;
  --blob: #FF8FC0; --t0a: #FFC9A8; --t0b: #FF9E7A; --t1a: #FFB3D1; --t1b: #FF7FB0; --t2a: #A8F0CF; --t2b: #5FD3A4; }
#app[data-world="lava"]  { --bg1: #1B0A24; --bg2: #3A0F3F; --bg3: #5B1237; --ui: #FFF1F7; --ui2: #F0BCD6; --accent: #FFD166; --ink: #2A0A1A; --panel: rgba(255,255,255,.12); --panel-ink: #FFF1F7;
  --blob: #8E2A78; --t0a: #FFB45E; --t0b: #FF7A1A; --t1a: #FF9A9A; --t1b: #F0495A; --t2a: #FF8AD8; --t2b: #D93DB4; }
#app[data-world="frost"] { --bg1: #0B1B3A; --bg2: #12315F; --bg3: #1D4E89; --ui: #EAF5FF; --ui2: #AFCFF0; --accent: #7CF0FF; --ink: #0B2447; --panel: rgba(255,255,255,.13); --panel-ink: #EAF5FF;
  --blob: #2F7BD6; --t0a: #F4FBFF; --t0b: #BFE6FF; --t1a: #DDF3FF; --t1b: #8CCBFF; --t2a: #E6F0FF; --t2b: #A9B8FF; }
#app[data-world="neon"]  { --bg1: #0A0615; --bg2: #160B2E; --bg3: #24104A; --ui: #F4EEFF; --ui2: #BDA9EA; --accent: #FF4FD8; --ink: #14052E; --panel: rgba(255,255,255,.11); --panel-ink: #F4EEFF;
  --blob: #6A2FE0; --t0a: #C9A7FF; --t0b: #8F5BFF; --t1a: #D9FF7A; --t1b: #9BEA2E; --t2a: #8CF6FF; --t2b: #26D0E6; }

#app { position: relative; height: 100vh; height: 100dvh; width: 100%; overflow: hidden; color: var(--ui);
  background: linear-gradient(160deg, var(--bg1), var(--bg2) 55%, var(--bg3)); transition: background .6s;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); touch-action: none; user-select: none; -webkit-user-select: none; }
#app.shake2 { animation: appshake .28s; }
@keyframes appshake { 20% { transform: translate(2px, -1px); } 40% { transform: translate(-2px, 1px); } 60% { transform: translate(1px, 1px); } 80% { transform: translate(-1px, -1px); } }
.bg { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.bg i { position: absolute; width: 60vmax; height: 60vmax; border-radius: 50%; filter: blur(60px); opacity: .3; background: var(--blob, var(--accent)); animation: drift 22s ease-in-out infinite alternate; will-change: transform; }
.bg i:nth-child(1) { left: -20vmax; top: -20vmax; }
.bg i:nth-child(2) { right: -25vmax; bottom: -22vmax; background: var(--t1b); animation-duration: 28s; }
.bg i:nth-child(3) { left: 30%; top: 40%; width: 35vmax; height: 35vmax; background: var(--t2b); opacity: .16; animation-duration: 34s; }
@keyframes drift { to { transform: translate3d(8vmax, 6vmax, 0) scale(1.15); } }

.screen { position: absolute; inset: 0; display: none; flex-direction: column; padding: inherit; }
.screen.active { display: flex; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wicon { width: 1em; height: 1em; vertical-align: -.12em; display: inline-block; }

/* ---------- level map ---------- */
.map-head { text-align: center; padding: 14px 16px 6px; position: relative; z-index: 2; }
.logo { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: .5px; line-height: 1; }
.logo span { color: var(--accent); }

.tag { margin: 4px 0 0; font-size: 14px; opacity: .85; }
.map-stats { display: flex; gap: 10px; justify-content: center; align-items: center; margin-top: 8px; font-size: 14px; }
.chip { background: var(--panel); color: var(--panel-ink); border-radius: 999px; padding: 6px 14px; border: 0; min-height: 44px; font-weight: 600; backdrop-filter: blur(6px); display: inline-flex; align-items: center; gap: 6px; }
.map-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; z-index: 1; touch-action: pan-y; -webkit-overflow-scrolling: touch; scroll-behavior: smooth; }
.map-path { position: relative; margin: 0 auto; max-width: 440px; width: 100%; }
.map-path svg.line { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.world-tag { position: absolute; left: 0; right: 0; text-align: center; font-size: 13px; letter-spacing: 2px; text-transform: uppercase; font-weight: 700; opacity: .85; display: flex; align-items: center; justify-content: center; gap: 8px; }
.world-tag.gate { opacity: .6; }
.world-tag.gate::before, .world-tag.gate::after { content: ""; height: 2px; width: 28px; background: currentColor; opacity: .5; border-radius: 2px; }
.node { position: absolute; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%; border: 1px solid rgba(255,255,255,.6); display: grid; place-items: center; font-size: 22px; font-weight: 700;
  color: #2a1330; background: linear-gradient(135deg, var(--na), var(--nb)); box-shadow: inset 0 3px 0 rgba(255,255,255,.55), inset 0 -5px 8px rgba(0,0,0,.14), 0 8px 14px rgba(0,0,0,.25); }
.node[data-state="locked"] { background: rgba(150,150,165,.6); color: rgba(255,255,255,.9); box-shadow: none; cursor: default; border-color: transparent; }
.node[data-state="current"] { animation: pulse 1.6s ease-in-out infinite; }
.node[data-state="done"] { box-shadow: inset 0 3px 0 rgba(255,255,255,.55), inset 0 -5px 8px rgba(0,0,0,.14), 0 0 0 4px rgba(255,207,51,.35), 0 0 22px 4px rgba(255,207,51,.45), 0 8px 14px rgba(0,0,0,.25); }
.node .badge { position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; border-radius: 50%; background: #ffcf33; color: #8a5a00; font-size: 15px; display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.node .st { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font-size: 12px; letter-spacing: 1px; color: #ffcf33; text-shadow: 0 1px 2px rgba(0,0,0,.6); white-space: nowrap; }
#app[data-world="sorbet"] .node .st { color: #d98a00; text-shadow: none; }
@keyframes pulse { 50% { transform: scale(1.12); box-shadow: inset 0 3px 0 rgba(255,255,255,.55), 0 0 0 10px rgba(255,255,255,.2), 0 8px 14px rgba(0,0,0,.25); } }

/* ---------- play screen ---------- */
.hud { display: flex; align-items: center; gap: 8px; padding: 8px 12px 4px; position: relative; z-index: 2; }
.hud button { background: var(--panel); color: var(--panel-ink); border: 0; width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; backdrop-filter: blur(6px); font-size: 22px; line-height: 1; }
.hud button svg { width: 24px; height: 24px; }
.hud-mid { flex: 1; text-align: center; line-height: 1.15; min-width: 0; }
.hud-mid b { font-size: 20px; display: block; }
.hud-mid small { font-size: 13px; opacity: .9; letter-spacing: 1.5px; text-transform: uppercase; display: inline-flex; align-items: center; gap: 5px; }
.stars { display: flex; gap: 2px; font-size: 18px; color: #ffcf33; min-width: 62px; justify-content: flex-end; text-shadow: 0 1px 2px rgba(0,0,0,.35); }
#app[data-world="sorbet"] .stars { color: #f2a900; }
.stars .off { opacity: .28; }
.preview { height: 48px; margin: 4px auto 0; min-width: 120px; max-width: 94vw; padding: 0 16px; display: flex; align-items: center; justify-content: center; gap: 4px; border-radius: 999px; background: var(--panel); color: var(--panel-ink);
  font-size: 15px; font-weight: 500; position: relative; z-index: 2; transition: background .15s, box-shadow .15s, transform .15s; backdrop-filter: blur(6px); overflow: hidden; }
.preview.ok { box-shadow: 0 0 0 3px var(--accent), 0 0 18px var(--accent); transform: scale(1.05); }
.preview .pl { min-width: 26px; height: 32px; padding: 0 4px; border-radius: 10px; display: grid; place-items: center; font-style: normal; font-weight: 700; font-size: 22px; color: var(--ink); text-transform: uppercase;
  background: linear-gradient(135deg, var(--ta), var(--tb)); border: 1px solid rgba(255,255,255,.6); box-shadow: inset 0 2px 0 rgba(255,255,255,.55); }
.preview .pl[data-k="0"] { --ta: var(--t0a); --tb: var(--t0b); } .preview .pl[data-k="1"] { --ta: var(--t1a); --tb: var(--t1b); } .preview .pl[data-k="2"] { --ta: var(--t2a); --tb: var(--t2b); }
.preview .pl.pop { animation: plpop .22s cubic-bezier(.3,1.7,.5,1); }
@keyframes plpop { from { transform: scale(.3) translateY(8px); opacity: 0; } }
.stage { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; z-index: 2; min-height: 0; }
.board-wrap { position: relative; --bs: min(92vw, 62dvh); width: var(--bs); height: var(--bs); }
.board { position: absolute; inset: 0; outline: none; touch-action: none; }
.tile { position: absolute; left: 0; top: 0; width: calc(100% / var(--cols)); height: calc(100% / var(--rows));
  transform: translate(calc(var(--c) * 100%), calc(var(--r) * 100%)); transition: transform .5s cubic-bezier(.3, 1.45, .5, 1); will-change: transform; }
.tile[data-k="0"] { --ta: var(--t0a); --tb: var(--t0b); } .tile[data-k="1"] { --ta: var(--t1a); --tb: var(--t1b); } .tile[data-k="2"] { --ta: var(--t2a); --tb: var(--t2b); }
.tile i { position: absolute; inset: 5%; border-radius: 24%; display: grid; place-items: center; font-style: normal; font-weight: 700; color: var(--ink);
  font-size: calc(var(--bs) / var(--cols) * .5); text-transform: uppercase; line-height: 1;
  background: linear-gradient(135deg, var(--ta), var(--tb)); border: 1px solid rgba(255,255,255,.55);
  box-shadow: inset 0 3px 0 rgba(255,255,255,.5), inset 0 -6px 8px rgba(0,0,0,.16), 0 6px 10px rgba(0,0,0,.22);
  transition: transform .12s, box-shadow .12s, filter .12s; transform-origin: 50% 100%; }
.tile i::after { content: ""; position: absolute; left: 14%; top: 9%; width: 36%; height: 15%; border-radius: 50%; background: rgba(255,255,255,.35); transform: rotate(-18deg); }
.tile.sel i { transform: scale(1.08); filter: brightness(1.1) saturate(1.1); box-shadow: inset 0 3px 0 rgba(255,255,255,.6), 0 0 0 3px #fff, 0 0 22px 4px var(--accent); }
.tile.cur i { outline: 3px dashed #fff; outline-offset: 1px; }
.tile.hint i { animation: hintpulse .7s ease-in-out infinite alternate; }
.tile.shake i { animation: shake .36s; }
.tile.melt { transition: none; }
.tile.melt i { animation: melt .42s ease-in forwards; }
.tile.melt::before { content: ""; position: absolute; left: 44%; bottom: 8%; width: 13%; height: 18%; border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%; background: var(--tb); z-index: 2; opacity: 0; animation: drip .5s ease-in .08s forwards; }
.tile.shuf i { animation: shuf .5s; }
@keyframes hintpulse { to { transform: scale(1.14); box-shadow: inset 0 3px 0 rgba(255,255,255,.6), 0 0 0 3px #fff, 0 0 20px 6px var(--accent); } }
@keyframes shake { 20% { transform: translateX(-9%) scale(1.04); } 40% { transform: translateX(9%) scale(1.04); } 60% { transform: translateX(-6%); } 80% { transform: translateX(5%); } }
@keyframes melt { 0% { transform: scale(1.08); opacity: 1; filter: none; } 28% { transform: scale(1.14, .82); } 100% { transform: scale(.55, .04) translateY(60%); opacity: 0; filter: blur(4px) saturate(1.6); } }
@keyframes drip { 0% { opacity: 0; transform: translateY(0) scale(.5); } 25% { opacity: 1; transform: translateY(6%) scale(1); } 100% { opacity: 0; transform: translateY(190%) scale(.8, 1.4); } }
@keyframes shuf { 0% { transform: scale(1); } 50% { transform: scale(.6) rotate(12deg); opacity: .4; } 100% { transform: scale(1); } }
@keyframes meltfade { to { opacity: 0; } }
.trail { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; z-index: 3; }
.trail polyline { fill: none; stroke: var(--accent); stroke-opacity: .55; stroke-width: 15; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 12px var(--accent)); }
.spark { position: absolute; width: 8px; height: 8px; border-radius: 50%; pointer-events: none; z-index: 4; }
.spark.star { border-radius: 0; clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); width: 12px; height: 12px; }
.float { position: absolute; z-index: 5; pointer-events: none; font-weight: 700; font-size: 22px; color: var(--accent); text-shadow: 0 2px 6px rgba(0,0,0,.55), 0 0 2px rgba(0,0,0,.5); white-space: nowrap; }
#app[data-world="sorbet"] .float { color: #E0386C; text-shadow: 0 2px 0 rgba(255,255,255,.9); }

.tools { display: flex; justify-content: center; gap: 12px; padding: 6px 12px 14px; position: relative; z-index: 2; }
.tool { position: relative; min-width: 88px; min-height: 60px; padding: 6px 10px; border: 0; border-radius: 18px; background: var(--panel); color: var(--panel-ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: 13px; font-weight: 600; backdrop-filter: blur(6px); box-shadow: 0 4px 10px rgba(0,0,0,.15); }
.tool svg { width: 24px; height: 24px; }
.tool em { position: absolute; top: -6px; right: -4px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; background: var(--accent); color: var(--ink); font-style: normal; font-size: 13px; display: grid; place-items: center; font-weight: 700; }
#app[data-world="sorbet"] .tool em { color: #fff; background: #E0386C; }
#app[data-world="neon"] .tool em { color: #14052E; }
.tool:disabled { opacity: .4; cursor: default; }
.tool:active:not(:disabled), .chip:active, .hud button:active { transform: scale(.95); }

/* ---------- overlays ---------- */
#overlay { position: absolute; inset: 0; z-index: 20; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(10, 5, 25, .62); backdrop-filter: blur(4px); touch-action: none; overflow-y: auto; }
#overlay.show { display: flex; }
.card { width: min(92vw, 380px); max-height: 100%; overflow-y: auto; border-radius: 28px; padding: 22px 22px 20px; text-align: center; background: linear-gradient(165deg, #fff, #ffe6f2); color: #3b1f45; box-shadow: 0 20px 50px rgba(0,0,0,.45); animation: pop .35s cubic-bezier(.3,1.4,.5,1); }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.card h2 { margin: 0 0 4px; font-size: 26px; }
.card p { margin: 6px 0 14px; font-size: 15px; color: #5f4060; line-height: 1.4; }
.big-stars { font-size: 44px; letter-spacing: 6px; color: #ffbf1f; text-shadow: 0 2px 0 #e08a00; margin: 4px 0 8px; }
.big-stars b { display: inline-block; opacity: 0; transform: scale(0) rotate(-40deg); animation: starIn .55s cubic-bezier(.3,1.7,.5,1) forwards; font-weight: 400; }
.big-stars b.off { color: #d9c6d6; text-shadow: none; }
.big-stars b:nth-child(2) { animation-delay: .24s; } .big-stars b:nth-child(3) { animation-delay: .48s; }
@keyframes starIn { to { opacity: 1; transform: none; } }
.btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.btn { border: 0; border-radius: 16px; padding: 12px 20px; min-height: 48px; font-weight: 700; font-size: 16px; background: #fff; color: #4A2340; box-shadow: 0 4px 0 rgba(0,0,0,.12); }
.btn.main { background: linear-gradient(165deg, #ff7eb0, #e8366f); color: #fff; box-shadow: 0 4px 0 #b02a59; }
.btn.danger { background: #fff0f0; color: #a3122e; }
.btn:disabled { opacity: .4; }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.settings { text-align: left; }
.settings h2 { text-align: center; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 4px; border-bottom: 1px solid rgba(74,35,64,.12); min-height: 54px; }
.row:last-of-type { border-bottom: 0; }
.row .lbl { font-weight: 600; font-size: 16px; }
.row .lbl small { display: block; font-weight: 400; font-size: 12.5px; color: #6b4c6b; }
.switch { position: relative; flex: none; width: 54px; height: 32px; border-radius: 999px; border: 0; background: #c9bccb; padding: 0; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.3); transition: transform .2s; }
.switch[aria-checked="true"] { background: #e8366f; }
.switch[aria-checked="true"]::after { transform: translateX(22px); }
.switch:disabled { opacity: .45; }
.toast { position: absolute; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 50; background: rgba(20,10,40,.9); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; pointer-events: none; animation: toast 1.8s forwards; }
@keyframes toast { 0%, 85% { opacity: 1; } 100% { opacity: 0; } }
#confetti { position: absolute; inset: 0; z-index: 30; pointer-events: none; width: 100%; height: 100%; }
.loading-wrap { position: absolute; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #1b1033, #3a1b5c); }
.loading { color: #fff; font-size: 18px; text-align: center; padding: 0 24px; }

/* ---------- article under the game ---------- */
.info-page { max-width: 720px; width: 100%; margin: 0 auto; padding: 28px 20px 48px; color: #d2c6f0; font: 15px/1.7 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.info-page h1 { font-size: 24px; color: #fff; margin: 0 0 12px; }
.info-page h2 { font-size: 18px; color: #fff; margin: 24px 0 6px; }
.info-page h3 { font-size: 15px; color: #fff; margin: 16px 0 4px; }

/* landscape phones: the board shrinks to the free height so it never covers the word preview */
@media (max-height: 520px) and (orientation: landscape) {
  .board-wrap { --bs: min(60vw, calc(100dvh - 160px)); }
  .hud { padding-top: 4px; } .tools { padding-bottom: 6px; }
  .preview { height: 38px; margin-top: 0; } .preview .pl { height: 26px; font-size: 18px; min-width: 22px; }
  .tool { min-height: 50px; } .hud button { width: 44px; height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  .bg i, .node[data-state="current"], .tile.hint i, #app.shake2 { animation: none; }
  .tile { transition-duration: .01s; }
  .tile.melt i { animation: meltfade .15s forwards; }
  .tile.melt::before { display: none; }
  .card, .big-stars b, .preview .pl.pop { animation-duration: .01s; }
}
