@font-face {
  font-family: 'Fredoka';
  src: url('fonts/Fredoka.ttf') format('truetype');
  font-weight: 300 700;
  font-display: swap;
}
:root {
  --ink: #1b2440;
  --glass: rgba(255, 255, 255, 0.14);
  --glass-2: rgba(255, 255, 255, 0.24);
  --coral: #ff5f7e;
  --gold: #ffc53d;
  --mint: #36cf9c;
  font-family: 'Fredoka', 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0a1633;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
/* covers everything while an ad loads or plays, so nobody can progress */
.adblock { position: fixed; inset: 0; z-index: 50; background: rgba(5, 12, 30, 0.35); }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
#stage { position: fixed; inset: 0; touch-action: none; display: block; }

svg.ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
svg.ico.fill { fill: currentColor; stroke: none; }

/* ---------------------------------------------------------------- buttons */
.btn {
  border: 0;
  border-radius: 16px;
  padding: 11px 18px;
  font-weight: 600;
  font-size: 18px;
  color: #fff;
  background: var(--glass);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  transition: transform 0.08s ease, background 0.15s ease;
  line-height: 1.15;
}
.btn svg.ico { width: 20px; height: 20px; vertical-align: -4px; margin-right: 4px; }
.btn > svg + * { display: inline; }
.btn:hover { background: var(--glass-2); }
.btn:active { transform: translateY(2px) scale(0.98); }
.btn small { font-size: 13px; font-weight: 500; opacity: 0.82; }
.btn.big { padding: 13px 18px; font-size: 22px; }
.btn.primary {
  background: linear-gradient(180deg, #ff8ea6, #ff5f7e);
  box-shadow: inset 0 -4px 0 #d8476d, 0 8px 20px rgba(255, 95, 126, 0.35);
  color: #fff;
}
.btn.primary:hover { background: linear-gradient(180deg, #ff9bb0, #ff6a87); }
.btn:focus-visible, .icon:focus-visible, .lvl:focus-visible, .tab:focus-visible { outline: 3px solid #9fe3ff; outline-offset: 2px; }
.icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 0;
  background: var(--glass);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  flex: 0 0 auto;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
  transition: transform 0.08s ease;
}
.icon:active { transform: scale(0.94); }

/* ---------------------------------------------------------------- screens */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
  z-index: 2;
}
.title-wrap {
  margin-top: max(3vh, 12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(360px, 92vw);
}
#mascot { width: 120px; height: 110px; margin-bottom: -10px; }
.logo {
  margin: 0;
  font-size: clamp(46px, 12vw, 82px);
  font-weight: 700;
  letter-spacing: 0.5px;
  line-height: 1;
  text-shadow: 0 4px 0 #2b6cb0, 0 10px 26px rgba(0, 0, 0, 0.35);
}
.logo span { color: #9fe3ff; }
.tagline { margin: 8px 0 16px; font-size: 18px; opacity: 0.9; text-align: center; }
.menu { display: grid; gap: 10px; width: 100%; }
.icon-row { display: flex; gap: 12px; margin-top: 14px; }
.site-links { margin: auto 0 10px; padding-top: 16px; font-size: 13px; opacity: 0.75; }
.site-links a { color: #fff; }
body.links-off .site-links { display: none; }
body.landscape #screen-title { align-items: flex-start; padding-left: max(5vw, 16px); }
body.landscape .title-wrap { width: min(380px, 44vw); margin-top: max(4vh, 10px); }
body.landscape .site-links { align-self: flex-start; }
@media (max-height: 640px) {
  #mascot { display: none; }
  .tagline { margin: 6px 0 10px; }
  .btn.big { padding: 9px 16px; font-size: 19px; }
}

/* levels */
.topbar, .world-tabs, .world-info, .level-grid { width: min(720px, 100%); }
.topbar { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.topbar h2 { flex: 1; margin: 0; font-size: 26px; }
.star-total { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--gold); }
.star-total span { color: #fff; }
.world-tabs { display: flex; gap: 8px; margin-top: 14px; overflow-x: auto; padding-bottom: 4px; }
.tab {
  min-width: 62px;
  height: 58px;
  border-radius: 14px;
  border: 0;
  background: var(--glass);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 1 0 auto;
  font-size: 13px;
}
.tab b { font-size: 20px; }
.tab svg.ico { width: 16px; height: 16px; }
.tab.active { background: #fff; color: var(--ink); }
.tab.locked { opacity: 0.55; }
.world-info h3 { margin: 16px 0 4px; font-size: 21px; }
.world-info p { margin: 0 0 12px; opacity: 0.85; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; padding-bottom: 28px; }
.lvl {
  aspect-ratio: 1;
  border: 0;
  border-radius: 18px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  font-size: 22px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}
.lvl.solved { background: var(--glass-2); }
.lvl.locked { opacity: 0.4; cursor: default; }
.lvl:not(.locked):active { transform: scale(0.96); }
.mini-stars { display: flex; gap: 1px; }
.mini-stars svg.ico { width: 13px; height: 13px; color: rgba(255, 255, 255, 0.28); }
.mini-stars i.on svg.ico { color: var(--gold); }

/* ---------------------------------------------------------------- HUD */
.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 12px 8px;
  z-index: 3;
}
.hud-title { flex: 1; text-align: center; min-width: 0; }
#hud-name { font-weight: 700; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hud-moves { font-size: 14px; opacity: 0.88; }
.hud-actions { display: flex; gap: 8px; }
#btn-hint em {
  display: none;
  position: absolute;
  top: -4px;
  right: -6px;
  font-style: normal;
  font-size: 9px;
  font-weight: 700;
  background: var(--gold);
  color: var(--ink);
  border-radius: 6px;
  padding: 1px 4px;
}
#btn-hint.ad em { display: block; }
@media (max-width: 380px) {
  .icon { width: 40px; height: 40px; }
  .hud-actions { gap: 5px; }
  #hud-name { font-size: 17px; }
}

.pad {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: 174px;
  height: 152px;
  display: grid;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(3, 50px);
  grid-template-areas: '. up .' 'left . right' '. down .';
  z-index: 3;
}
.pad button {
  border: 0;
  border-radius: 16px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
}
.pad button:active { background: var(--glass-2); transform: scale(0.95); }
.pad .up { grid-area: up; }
.pad .left { grid-area: left; }
.pad .right { grid-area: right; }
.pad .down { grid-area: down; }
.pad .right svg { transform: rotate(90deg); }
.pad .down svg { transform: rotate(180deg); }
.pad .left svg { transform: rotate(-90deg); }
body.landscape .pad { left: auto; right: 22px; top: 50%; bottom: auto; transform: translateY(-50%); }

.tip {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 188px;
  max-width: min(420px, 88vw);
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 16px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  z-index: 3;
  animation: floaty 2.4s ease-in-out infinite;
}
body.landscape .tip { bottom: 22px; }

/* ---------------------------------------------------------------- modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 12, 30, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}
.card {
  position: relative;
  width: min(400px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: linear-gradient(180deg, #ffffff, #eef7ff);
  color: var(--ink);
  border-radius: 24px;
  padding: 22px 20px 18px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  animation: pop 0.22s ease-out;
}
.card h2 { margin: 4px 26px 8px; font-size: 26px; line-height: 1.15; }
.card p { margin: 6px 0; line-height: 1.4; }
.card .btn { background: #e3effa; color: var(--ink); box-shadow: inset 0 -3px 0 #c5d9ed; -webkit-backdrop-filter: none; backdrop-filter: none; flex-direction: row; }
.card .btn:hover { background: #d8e8f7; }
.card .btn.primary { color: #fff; background: linear-gradient(180deg, #ff8ea6, #ff5f7e); box-shadow: inset 0 -4px 0 #d8476d; }
.card .btn.danger { background: #ffe5ea; color: #c2334f; box-shadow: inset 0 -3px 0 #f4c3cd; }
.card .icon.close { position: absolute; top: 10px; right: 10px; background: transparent; box-shadow: none; color: var(--ink); width: 40px; height: 40px; }
.actions { display: grid; gap: 8px; margin-top: 14px; }
.soft { opacity: 0.75; }
.small { font-size: 13px; }
.score { font-size: 18px; }
.stars { display: flex; justify-content: center; gap: 8px; margin: 6px 0 4px; }
.stars svg.ico { width: 48px; height: 48px; color: #d6e3f0; }
.stars i.on svg.ico { color: var(--gold); animation: starpop 0.45s cubic-bezier(0.3, 1.6, 0.6, 1) both; animation-delay: inherit; }
.stars i { display: inline-block; }
.howto .row { display: flex; align-items: center; gap: 12px; text-align: left; margin: 8px 0; }
.howto canvas { flex: 0 0 56px; }
.howto p { margin: 0; font-size: 15px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.stat { background: #e9f3fc; border-radius: 14px; padding: 10px 6px; }
.stat b { display: block; font-size: 24px; }
.stat span { font-size: 13px; opacity: 0.7; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: left; padding: 10px 2px; border-bottom: 1px solid #e1ebf5; cursor: pointer; }
.toggle small { display: block; font-size: 12px; opacity: 0.65; font-weight: 400; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { width: 48px; height: 28px; border-radius: 14px; background: #c5d3e2; position: relative; flex: 0 0 auto; transition: background 0.15s; }
.toggle i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left 0.15s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); }
.toggle input:checked + i { background: var(--mint); }
.toggle input:checked + i::after { left: 23px; }
.toggle input:focus-visible + i { outline: 3px solid #9fe3ff; outline-offset: 2px; }
.links a { color: #2b6cb0; }
.intro-art { display: block; margin: 0 auto 2px; }
.intro-list { display: grid; gap: 10px; margin-top: 6px; }
.intro-item { display: flex; align-items: center; gap: 10px; text-align: left; }
.intro-item .intro-art { flex: 0 0 auto; margin: 0; }
.intro-item h3 { margin: 0 0 2px; font-size: 17px; }
.intro-item p { margin: 0; font-size: 14px; line-height: 1.35; }
.unlock { margin-top: 12px; padding: 10px 12px 12px; border-radius: 16px; background: #e4f4ff; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.unlock b { font-size: 17px; }
.unlock span { font-size: 14px; opacity: 0.8; }
.score.time b { font-variant-numeric: tabular-nums; }
#hud-moves { font-variant-numeric: tabular-nums; }

.toast {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 22, 51, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  z-index: 30;
  max-width: 88vw;
  white-space: pre-line;
  font-size: 15px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

@keyframes pop { from { transform: scale(0.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes starpop { 0% { transform: scale(0); } 70% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes floaty { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -5px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
