/* 喷涂画作 — Splatoon-style sticker UI. All text is heavy system font. */

:root {
  --ink: rgb(2, 75, 227);
  --ink-dark: rgb(1, 45, 136);
  --ink-light: rgb(118, 155, 240);
  --outline: #15132b;
  --cream: #f6eedb;
  --pink: #ff4fa3;
  --lime: #3cf2a0;
  --yellow: #ffe14d;
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #10123a;
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  font-weight: 900;
  color: #fff;
}

button {
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* ---------------------------------------------------------------- sticker text */

.sticker {
  font-weight: 900;
  color: #fff;
  -webkit-text-stroke: 0.2em var(--outline);
  paint-order: stroke fill;
  text-shadow: 0 0.1em 0 var(--outline);
  letter-spacing: 0.03em;
  line-height: 1.15;
}

/* Chromium < 123 ignores paint-order on HTML text and would paint the stroke
   over the glyphs; a text-shadow ring stands in there (class set in ui.js). */
.no-paint-order .sticker,
.no-paint-order .big-btn {
  -webkit-text-stroke: 0;
  text-shadow:
    0.07em 0 0 var(--outline),
    -0.07em 0 0 var(--outline),
    0 0.07em 0 var(--outline),
    0 -0.07em 0 var(--outline),
    0.05em 0.05em 0 var(--outline),
    -0.05em 0.05em 0 var(--outline),
    0.05em -0.05em 0 var(--outline),
    -0.05em -0.05em 0 var(--outline),
    0 0.12em 0 var(--outline);
}

/* ---------------------------------------------------------------- layers */

#bg,
#fx {
  position: fixed;
  left: 0;
  top: 0;
}

#bg {
  z-index: 0;
}

#stage {
  position: fixed;
  z-index: 1;
  left: 0;
  top: 0;
  width: 10px;
  height: 10px;
  background: var(--cream);
  border-radius: 4px;
  box-shadow:
    0 0 0 5px var(--cream),
    0 0 0 8.5px var(--outline),
    0 9px 0 6px var(--outline),
    0 22px 40px rgba(0, 0, 0, 0.55);
  will-change: transform;
}

body.anim #stage {
  transition:
    left 0.55s cubic-bezier(0.3, 1.2, 0.4, 1),
    top 0.55s cubic-bezier(0.3, 1.2, 0.4, 1),
    width 0.55s cubic-bezier(0.3, 1.2, 0.4, 1),
    height 0.55s cubic-bezier(0.3, 1.2, 0.4, 1);
}

#gl {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 2px;
}

/* pencil lines, drawn over the painting (moves with the stage shake) */
#sketch {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  border-radius: 2px;
  transition: opacity 0.5s ease-out;
}

#fx {
  z-index: 2;
  pointer-events: none;
}

#probe {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  visibility: hidden;
  pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------------------------------------------------------------- HUD */

#hud {
  position: fixed;
  z-index: 3;
  left: 0;
  right: 0;
  top: 0;
  padding-top: calc(env(safe-area-inset-top) + 14px);
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.turf {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(560px, calc(100vw - 132px));
}

.turf-bar {
  position: relative;
  flex: 1;
  height: 28px;
}

.turf-clip {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  overflow: hidden;
  background: #262955;
  border: 3px solid var(--outline);
  box-shadow:
    0 0 0 3px #fff,
    0 6px 0 3px var(--outline),
    inset 0 4px 0 rgba(0, 0, 0, 0.3);
}

.turf-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 7%;
  border-radius: 999px;
  background: var(--ink);
  transition: background-color 0.4s;
}

.turf-shine {
  position: absolute;
  left: 8px;
  right: 16px;
  top: 3px;
  height: 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.5);
}

/* gooey leading edge: an ink blob head bulging over the bar's rim */
.turf-blob {
  position: absolute;
  left: 7%;
  top: 50%;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -22px;
  border-radius: 46% 54% 50% 50%;
  background: var(--ink);
  border: 3px solid var(--outline);
  transition: background-color 0.4s;
  animation: blobWobble 0.7s ease-in-out infinite alternate;
}

.turf-blob::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 5px;
  width: 9px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  transform: rotate(-30deg);
}

.turf-goal {
  position: absolute;
  left: 88%;
  top: -7px;
  bottom: -9px;
  width: 6px;
  margin-left: -3px;
  border-radius: 4px;
  background: var(--yellow);
  border: 2px solid var(--outline);
}

.turf-pct {
  min-width: 2.7em;
  font-size: 28px;
  text-align: right;
  transform: rotate(3deg);
}

.turf-pct.bump {
  animation: bump 0.45s cubic-bezier(0.2, 1.8, 0.4, 1);
}

#chip {
  position: fixed;
  z-index: 3;
  font-size: 15px;
  white-space: pre;
  padding: 5px 12px 7px;
  border-radius: 12px;
  background: var(--ink);
  border: 3px solid var(--outline);
  box-shadow:
    0 0 0 2.5px #fff,
    0 5px 0 2.5px var(--outline);
  transform: rotate(-4deg);
  pointer-events: none;
  transition: background-color 0.4s;
}

#chip.bump {
  animation: chipBump 0.5s cubic-bezier(0.2, 1.8, 0.4, 1);
}

.icon-btn {
  position: fixed;
  z-index: 7;
  top: calc(env(safe-area-inset-top) + 10px);
  right: calc(env(safe-area-inset-right) + 12px);
  width: 46px;
  height: 46px;
  padding: 7px;
  border-radius: 50%;
  background: #fff;
  border: 3.5px solid var(--outline);
  box-shadow: 0 4px 0 var(--outline);
}

.icon-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--outline);
}

.icon-btn svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: var(--outline);
  stroke-width: 4.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn .spk {
  fill: var(--ink);
}

.icon-btn .cross {
  display: none;
}

.icon-btn.muted .wave {
  display: none;
}

.icon-btn.muted .cross {
  display: inline;
}

.icon-btn.muted .spk {
  fill: #c9c6d8;
}

/* ---------------------------------------------------------------- hint */

#hint {
  position: fixed;
  z-index: 3;
  width: 0;
  height: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

#hint.show {
  opacity: 1;
}

.hint-ring {
  position: absolute;
  left: -34px;
  top: -34px;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 5px solid #fff;
  box-shadow:
    0 0 0 3px var(--outline),
    inset 0 0 0 3px var(--outline);
  animation: ring 1.2s ease-out infinite;
}

.hint-ring.r2 {
  animation-delay: 0.6s;
}

.hint-finger {
  position: absolute;
  left: -10px;
  top: -6px;
  width: 58px;
  height: 58px;
  fill: #fff;
  stroke: var(--outline);
  stroke-width: 4;
  stroke-linejoin: round;
  animation: tapFinger 1.2s ease-in-out infinite;
}

.hint-text {
  position: absolute;
  left: 50%;
  top: 52px;
  transform: translateX(-50%) rotate(-3deg);
  white-space: nowrap;
  font-size: 17px;
  color: var(--yellow);
}

/* ---------------------------------------------------------------- pops & banners */

#pops,
#banner {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

#pops {
  z-index: 4;
}

#banner {
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pop {
  position: fixed;
  font-size: 22px;
  white-space: nowrap;
  color: var(--yellow);
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  animation: popUp 1.05s cubic-bezier(0.2, 1.6, 0.4, 1) forwards;
}

.pop.warn {
  color: #ff6b8e;
  font-size: 24px;
}

.pop.special {
  font-size: 40px;
  color: var(--yellow);
}

/* tool swap / zone tip: big, lingers a little longer than a hit pop */
.pop.tool {
  font-size: 34px;
  color: #fff;
  animation-duration: 1.35s;
}

/* coverage milestones */
.pop.cheer {
  font-size: 30px;
  color: #7dffb0;
}

.banner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transform: rotate(var(--rot, -3deg));
  animation: bannerIn 0.55s cubic-bezier(0.2, 1.7, 0.4, 1) both;
  filter: drop-shadow(0 6px 0 rgba(21, 19, 43, 0.9));
}

.banner.out {
  animation: bannerOut 0.35s ease-in forwards;
}

.banner-splat {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 330px;
  height: 330px;
  margin: -165px 0 0 -165px;
  background: var(--ink);
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  z-index: -1;
}

.banner.big .banner-splat {
  width: 400px;
  height: 400px;
  margin: -200px 0 0 -200px;
}

.banner-title {
  font-size: clamp(32px, 9vw, 56px);
  white-space: nowrap;
}

.banner-sub {
  font-size: clamp(22px, 5.5vw, 32px);
  color: var(--yellow);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- screens */

.screen {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 9, 32, 0.66);
  transition: opacity 0.35s;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen.leaving {
  opacity: 0;
  pointer-events: none;
}

.start-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 20px;
}

.title-wrap {
  position: relative;
  padding: 18px 26px;
}

.title-splat {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 118%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%) rotate(12deg);
  background: #2f6bff;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  filter: drop-shadow(0 6px 0 var(--outline));
}

.title-splat.s2 {
  width: 60%;
  left: 96%;
  top: 8%;
  background: var(--pink);
  transform: translate(-50%, -50%) rotate(-30deg);
}

.title-splat.s3 {
  width: 46%;
  left: 6%;
  top: 92%;
  background: var(--yellow);
  transform: translate(-50%, -50%) rotate(70deg);
}

.title {
  position: relative;
  margin: 0;
  font-size: clamp(50px, 14vw, 96px);
  transform: rotate(-4deg);
  animation: titleBob 2.4s ease-in-out infinite;
}

.title-wrap,
.subtitle,
.howto,
#startBtn {
  position: relative;
}

.subtitle,
.howto,
#startBtn {
  z-index: 1;
}

.howto {
  padding: 6px 14px 6px 8px;
  border-radius: 16px;
  background: rgba(10, 11, 40, 0.72);
}

.subtitle {
  font-size: clamp(20px, 5.5vw, 30px);
  color: var(--yellow);
  transform: rotate(2deg);
}

.howto {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 800;
  color: #dfe2ff;
  line-height: 1.5;
}

.howto svg {
  width: 120px;
  height: 68px;
  overflow: visible;
}

.howto .arc {
  fill: none;
  stroke: rgba(255, 255, 255, 0.5);
  stroke-width: 3;
  stroke-dasharray: 3 7;
  stroke-linecap: round;
}

.howto .dot {
  fill: #2f6bff;
  stroke: var(--outline);
  stroke-width: 2.5;
  animation: dotPop 1.6s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}

.howto .d2 { animation-delay: 0.12s; }
.howto .d3 { animation-delay: 0.24s; fill: var(--pink); }
.howto .d4 { animation-delay: 0.3s; fill: var(--pink); }
.howto .d5 { animation-delay: 0.34s; fill: var(--pink); }

.howto .finger {
  fill: #fff;
  stroke: var(--outline);
  stroke-width: 3;
  stroke-linejoin: round;
}

.big-btn {
  position: relative;
  font-size: clamp(22px, 6vw, 30px);
  font-weight: 900;
  color: #fff;
  -webkit-text-stroke: 0.18em var(--outline);
  paint-order: stroke fill;
  text-shadow: 0 0.08em 0 var(--outline);
  letter-spacing: 0.04em;
  padding: 14px 36px 17px;
  border-radius: 999px;
  border: 4px solid var(--outline);
  background: #6b6d8f;
  box-shadow:
    0 7px 0 var(--outline),
    inset 0 -6px 0 rgba(0, 0, 0, 0.18),
    inset 0 5px 0 rgba(255, 255, 255, 0.25);
  white-space: nowrap;
}

.big-btn.ready,
#end .big-btn,
#backBtn {
  background: var(--pink);
}

#startBtn.ready {
  animation: btnWobble 1.3s ease-in-out infinite;
}

.big-btn:active {
  transform: translateY(5px) !important;
  box-shadow:
    0 2px 0 var(--outline),
    inset 0 -6px 0 rgba(0, 0, 0, 0.18);
  animation-play-state: paused;
}

#end .big-btn.alt {
  background: var(--lime);
}

.big-btn.small {
  font-size: 18px;
  padding: 9px 22px 11px;
}

#backBtn {
  position: fixed;
  z-index: 7;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  transform: translateX(-50%);
}

#backBtn:active {
  transform: translate(-50%, 4px) !important;
}

/* ---------------------------------------------------------------- end card */

.end-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
  animation: bannerIn 0.6s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}

.end-splat {
  position: absolute;
  left: 50%;
  top: 12px;
  width: 220px;
  height: 220px;
  margin-left: -110px;
  margin-top: -80px;
  background: var(--yellow);
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  transform: rotate(-12deg);
  filter: drop-shadow(0 5px 0 var(--outline));
}

.end-title {
  position: relative;
  margin: 0;
  font-size: clamp(46px, 12vw, 76px);
  transform: rotate(-4deg);
}

.end-time {
  font-size: 20px;
  color: var(--yellow);
  transform: rotate(2deg);
}

.flipbook {
  position: relative;
  /* --app-h: the visible height, set in ui.js (100vh ignores the toolbars) */
  width: min(80vw, 540px, calc((var(--app-h, 100vh) - 290px) * 1.5));
  aspect-ratio: 1280 / 853;
  background: var(--cream);
  border-radius: 4px;
  box-shadow:
    0 0 0 5px var(--cream),
    0 0 0 8.5px var(--outline),
    0 8px 0 6px var(--outline);
  transform: rotate(1deg);
}

.flipbook img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 2px;
}

.flip-label {
  position: absolute;
  left: -10px;
  top: -14px;
  font-size: 15px;
  padding: 3px 10px 5px;
  border-radius: 10px;
  background: var(--ink);
  border: 3px solid var(--outline);
  box-shadow: 0 0 0 2.5px #fff;
  transform: rotate(-5deg);
}

.end-btns {
  display: flex;
  gap: 14px;
  margin-top: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

#end .big-btn {
  font-size: 22px;
  padding: 11px 26px 13px;
}

@media (orientation: landscape) and (max-height: 520px) {
  .start-inner {
    gap: 8px;
  }
  .title {
    font-size: 54px;
  }
  .title-wrap {
    padding: 8px 20px;
  }
  .howto {
    font-size: 13px;
  }
  .end-card {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-areas:
      "flip title"
      "flip time"
      "flip btns";
    column-gap: 26px;
    row-gap: 6px;
    align-items: center;
  }
  .end-title { grid-area: title; font-size: 50px; }
  .end-time { grid-area: time; }
  .end-btns { grid-area: btns; flex-direction: column; }
  .flipbook {
    grid-area: flip;
    width: min(52vw, calc((var(--app-h, 100vh) - 60px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 1.5));
  }
  .end-splat { left: 75%; }
}

/* ---------------------------------------------------------------- debug / error */

#debug {
  position: fixed;
  z-index: 9;
  left: calc(env(safe-area-inset-left) + 8px);
  bottom: calc(env(safe-area-inset-bottom) + 8px);
  margin: 0;
  padding: 6px 9px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  font: 600 12px/1.45 ui-monospace, Menlo, monospace;
  color: #9effc8;
  pointer-events: none;
  white-space: pre;
}

#error {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 30px;
  text-align: center;
  background: rgba(8, 9, 32, 0.9);
}

.error-title {
  font-size: 48px;
  color: var(--pink);
}

.error-msg {
  max-width: 420px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.6;
  color: #e6e8ff;
}

/* ---------------------------------------------------------------- keyframes */

@keyframes blobWobble {
  0% { transform: scale(1, 0.92); }
  100% { transform: scale(1.18, 1.08); }
}

@keyframes bump {
  0% { transform: rotate(3deg) scale(1); }
  40% { transform: rotate(-4deg) scale(1.45); }
  100% { transform: rotate(3deg) scale(1); }
}

@keyframes chipBump {
  0% { transform: rotate(-4deg) scale(0.4); }
  60% { transform: rotate(-7deg) scale(1.2); }
  100% { transform: rotate(-4deg) scale(1); }
}

@keyframes ring {
  0% { transform: scale(0.45); opacity: 1; }
  100% { transform: scale(1.5); opacity: 0; }
}

@keyframes tapFinger {
  0%, 100% { transform: translate(0, 0) rotate(-12deg); }
  50% { transform: translate(-3px, -9px) rotate(-18deg); }
}

@keyframes popUp {
  0% { transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(0); opacity: 1; }
  22% { transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(1.3); }
  36% { transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(1); }
  75% { transform: translate(-50%, -80%) rotate(var(--rot, 0deg)) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -110%) rotate(var(--rot, 0deg)) scale(0.85); opacity: 0; }
}

@keyframes bannerIn {
  0% { transform: rotate(var(--rot, -3deg)) scale(0.2); opacity: 0; }
  60% { transform: rotate(var(--rot, -3deg)) scale(1.12); opacity: 1; }
  100% { transform: rotate(var(--rot, -3deg)) scale(1); opacity: 1; }
}

@keyframes bannerOut {
  0% { transform: rotate(var(--rot, -3deg)) scale(1); opacity: 1; }
  100% { transform: rotate(var(--rot, -3deg)) scale(1.3) translateY(-20px); opacity: 0; }
}

@keyframes btnWobble {
  0%, 100% { transform: rotate(-3deg) scale(1); }
  25% { transform: rotate(2.5deg) scale(1.05); }
  50% { transform: rotate(-1.5deg) scale(0.98); }
  75% { transform: rotate(3deg) scale(1.04); }
}

@keyframes titleBob {
  0%, 100% { transform: rotate(-4deg) translateY(0); }
  50% { transform: rotate(-2deg) translateY(-5px); }
}

@keyframes dotPop {
  0%, 30% { transform: scale(0); }
  45% { transform: scale(1.3); }
  60%, 100% { transform: scale(1); }
}
