@font-face {
  font-family: 'Lilita One';
  src: url('fonts/lilita-one.woff2') format('woff2');
  font-display: block;
}

:root {
  --paper: #fff3df;
  --ink: #1f2f5c;
  --pink: #ff5d8f;
  --lemon: #ffd23f;
  --blue: #3f7cc2;
  --leaf: #2fa84f;
  --off: 3px; /* print misregistration */
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1f2f5c;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: 'Lilita One', 'Trebuchet MS', sans-serif;
  color: var(--ink);
}

#stage {
  position: relative;
  margin: 0 auto;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
  background: var(--paper);
}
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.grain { position: absolute; inset: 0; pointer-events: none; background-repeat: repeat; }

.hidden { display: none !important; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible { outline: 3px dashed var(--pink); outline-offset: 3px; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
}
#lives { display: flex; gap: 4px; }
#lives svg { width: clamp(22px, 5vmin, 30px); height: auto; }
#score { text-align: center; line-height: 0.9; }
#score b {
  font-weight: 400;
  font-size: clamp(40px, 11vmin, 72px);
  color: var(--ink);
  text-shadow: var(--off) var(--off) 0 var(--pink);
}
#score span { font-size: clamp(18px, 4vmin, 26px); margin-left: 2px; }
#score small { display: block; font-size: clamp(14px, 3vmin, 18px); color: var(--pink); margin-top: 4px; }
#pauseBtn { justify-self: end; pointer-events: auto; }

.icon {
  display: inline-grid;
  place-items: center;
  width: clamp(44px, 9vmin, 54px);
  height: clamp(44px, 9vmin, 54px);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 10px;
  box-shadow: var(--off) var(--off) 0 var(--ink);
  color: var(--ink);
}
.icon svg { width: 60%; height: 60%; fill: currentColor; }
.icon svg[fill="none"] { fill: none; stroke: currentColor; }
.icon:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.icon.wide { width: auto; padding: 0 12px; grid-auto-flow: column; gap: 6px; }
.icon.wide svg { width: 26px; height: 26px; fill: var(--pink); }
.icon.wide b { font-weight: 400; font-size: 20px; }

.hint {
  position: absolute;
  left: 0; right: 0;
  top: 58%;
  margin: 0;
  text-align: center;
  font-size: clamp(24px, 6vmin, 38px);
  color: var(--ink);
  text-shadow: var(--off) var(--off) 0 var(--lemon);
  animation: nod 1.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes nod { 50% { transform: translateY(6px); } }

/* ---------- title ---------- */
#title {
  position: absolute; inset: 0; pointer-events: none;
  --logo-size: clamp(46px, 13vmin, 110px);
  --under-logo: calc(max(4%, env(safe-area-inset-top)) + var(--logo-size) * 1.9 + 22px);
}
#title .hint { top: var(--under-logo); }
#title > * { pointer-events: auto; }
#title .hint { pointer-events: none; }
#logo {
  position: absolute;
  top: max(4%, env(safe-area-inset-top));
  left: 0; right: 0;
  margin: 0;
  text-align: center;
  font-weight: 400;
  font-size: var(--logo-size);
  line-height: 0.95;
  color: var(--pink);
  text-shadow: var(--off) var(--off) 0 var(--ink), calc(var(--off) * -1) 0 0 var(--lemon);
  pointer-events: none;
}
#logo span {
  display: inline-block;
  transform: translateY(calc(sin(var(--i) * 1.7) * 0.07em)) rotate(calc(sin(var(--i) * 2.3) * 6deg));
  animation: wob 2.4s ease-in-out infinite;
  animation-delay: calc(var(--i) * -0.19s);
}
@keyframes wob { 50% { translate: 0 -0.06em; } }
#howto {
  position: absolute;
  top: calc(var(--under-logo) + clamp(40px, 9vmin, 60px));
  left: 0; right: 0;
  margin: 0 auto;
  max-width: 30ch;
  text-align: center;
  font-size: clamp(15px, 3.4vmin, 20px);
  color: var(--ink);
  pointer-events: none;
}
.bar {
  position: absolute;
  left: 0; right: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px 18px;
  padding: 0 12px;
}
.sea { display: flex; align-items: center; gap: 8px; }
.sea > div {
  min-width: 9em;
  text-align: center;
  background: var(--lemon);
  border: 3px solid var(--ink);
  border-radius: 6px 18px 6px 18px;
  padding: 6px 12px;
  box-shadow: var(--off) var(--off) 0 var(--ink);
}
.sea b { font-weight: 400; font-size: clamp(18px, 4vmin, 24px); display: inline-flex; gap: 4px; align-items: center; }
.sea b svg { width: 18px; height: 18px; fill: currentColor; }
.sea small { display: block; font-size: 14px; color: var(--ink); opacity: 0.8; }
.tools { display: flex; gap: 8px; }
#credits {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  top: max(8px, env(safe-area-inset-top));
  margin: 0;
  font-size: 13px;
  opacity: 0.6;
}

/* ---------- cards: printed cargo slips ---------- */
.card {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  width: min(92vw, 440px);
  max-height: 92dvh;
  overflow: auto;
  padding: 22px 20px 20px;
  background:
    radial-gradient(circle at 4px 4px, rgba(31, 47, 92, 0.12) 1.2px, transparent 1.6px) 0 0 / 8px 8px,
    var(--paper);
  border: 3px solid var(--ink);
  border-radius: 4px;
  box-shadow: 6px 6px 0 var(--pink);
  text-align: center;
  animation: slip 0.28s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes slip { from { transform: translateY(24px) rotate(-2deg); opacity: 0; } }
.card h2 { margin: 0 0 4px; font-weight: 400; font-size: clamp(28px, 7vmin, 40px); color: var(--pink); text-shadow: 2px 2px 0 var(--ink); }
.card h2 svg { width: 44px; height: 44px; stroke: var(--ink); }
.card h3 { margin: 16px 0 6px; font-weight: 400; font-size: 20px; }
.bignum { font-size: clamp(56px, 16vmin, 88px); line-height: 1; color: var(--ink); text-shadow: var(--off) var(--off) 0 var(--lemon); }
.bignum small { font-size: 0.4em; margin-left: 4px; }
.close, .sub, .unlock, .stamps { margin: 8px 0; font-size: 19px; }
.close { color: var(--pink); font-size: 21px; }
.unlock { color: var(--leaf); font-size: 22px; }
.stamps { display: flex; align-items: center; justify-content: center; gap: 6px; }
.stamps i svg { width: 24px; height: 24px; fill: var(--pink); display: block; }
.card > .x { position: absolute; right: 10px; top: 10px; width: 44px; height: 44px; }

.row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 14px; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 8px 20px;
  font-size: 22px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 8px;
  box-shadow: var(--off) var(--off) 0 var(--ink);
  position: relative;
}
.btn i svg { width: 22px; height: 22px; fill: currentColor; display: block; }
.btn.primary { background: var(--pink); color: #fff; }
.btn.gold { background: var(--lemon); }
.btn.big { font-size: 26px; padding: 10px 28px; }
.btn.small { font-size: 17px; min-height: 44px; margin-top: 12px; }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled { opacity: 0.55; }
.btn .ad {
  font-style: normal;
  font-size: 13px;
  background: var(--ink);
  color: var(--lemon);
  border-radius: 4px;
  padding: 2px 5px;
}

.missions { list-style: none; margin: 12px 0 0; padding: 0; text-align: left; }
.missions li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  padding: 7px 0;
  border-bottom: 2px dashed rgba(31, 47, 92, 0.25);
  font-size: 17px;
}
.missions li b {
  grid-column: 1 / -1;
  height: 8px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: linear-gradient(90deg, var(--leaf) calc(var(--p) * 100%), transparent 0);
}
.missions li em { font-style: normal; color: var(--leaf); grid-row: 1; grid-column: 2; }
.missions li.daily span { color: var(--pink); }
.missions li.done span { text-decoration: line-through; text-decoration-thickness: 2px; }

.paints { gap: 10px; }
.swatch {
  width: 52px; height: 52px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--a) 55%, var(--b) 55% 75%, var(--a) 75%);
  box-shadow: var(--off) var(--off) 0 var(--ink);
  display: grid; place-items: center;
}
.swatch.on { outline: 3px solid var(--pink); outline-offset: 3px; }
.swatch:disabled { filter: grayscale(0.8) opacity(0.6); }
.swatch small { font-size: 13px; background: var(--paper); border-radius: 4px; padding: 1px 3px; display: flex; align-items: center; }
.swatch small svg { width: 12px; height: 12px; fill: var(--pink); }

.langs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 10px; }
.langs .btn { justify-content: center; font-size: 19px; }

#tapAfter {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(31, 47, 92, 0.55);
  color: var(--paper);
  font-size: clamp(28px, 7vmin, 44px);
  text-shadow: var(--off) var(--off) 0 var(--pink);
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 18%;
  translate: -50% 0;
  max-width: 88%;
  padding: 10px 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 8px;
  font-size: 17px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
#toast.on { opacity: 1; }

/* night sea: light ink on the dark sky */
#stage.night #score b { color: var(--paper); }
#stage.night #score span, #stage.night .hint, #stage.night #howto, #stage.night #credits { color: var(--paper); }
#stage.night .hint { text-shadow: var(--off) var(--off) 0 var(--pink); }

@media (prefers-reduced-motion: reduce) {
  .hint, #logo span, .card { animation: none; }
}
@media (max-height: 460px) {
  #howto { display: none; }
}
