:root {
  --ink: #2a211e;
  --cream: #fff8e8;
  --sun: #ffd23f;
  --grass: #3bd16f;
  --red: #ff5a5f;
  --sky: #8fd3ff;
  --stick: clamp(118px, 34vmin, 210px);
  --grab: clamp(76px, 22vmin, 128px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky);
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--sky);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
canvas.splats { pointer-events: none; z-index: 4; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, .btn, .banner, .name, .round, .replay-tag, .grab-btn span, .lvl-num, .coin-n, .shop-item b, .earn b {
  font-family: "Lilita One", "Arial Rounded MT Bold", system-ui, sans-serif;
  font-weight: 400;
  letter-spacing: 0.02em;
}

/* --- What shows on which screen. */
.hud, .controls, .banner, .replay-tag, .card, .ready { display: none; }
#game[data-screen="fight"] .hud,
#game[data-screen="paused"] .hud,
#game[data-screen="replay"] .hud { display: flex; }
#game.touch[data-screen="fight"] .controls { display: block; }
#game[data-screen="fight"] .banner:not([hidden]),
#game[data-screen="replay"] .banner:not([hidden]) { display: block; }
#game[data-screen="replay"] .replay-tag { display: flex; }
#game[data-screen="title"] .title-card,
#game[data-screen="paused"] .pause-card,
#game[data-screen="result"] .result { display: flex; }
#game[data-screen="ready"] .ready { display: block; }
.settings:not([hidden]), .fs-tip:not([hidden]) { display: flex; z-index: 30; }
#game[data-screen="replay"] .icons { visibility: hidden; }
#game.touch .keys-how { display: none; }
#game:not(.touch) .touch-how { display: none; }
#game.is-fs [data-fs] { opacity: 0.55; }

/* --- Cards. */
.card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 460px);
  max-height: calc(100% - 20px);
  overflow: auto;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1.6vmin, 12px);
  padding: clamp(12px, 3vmin, 26px) clamp(16px, 4vmin, 30px);
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 24px;
  box-shadow: 0 8px 0 var(--ink);
  text-align: center;
  z-index: 10;
}

h1 {
  margin: 0;
  font-size: clamp(38px, 10vmin, 70px);
  line-height: 0.95;
  color: var(--grass);
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--ink);
}
h1 span { color: var(--sun); display: inline-block; transform: rotate(-4deg); }
h2 { margin: 0; font-size: clamp(26px, 6.5vmin, 42px); line-height: 1; }
.card p { margin: 0; font-size: clamp(14px, 3.4vmin, 18px); line-height: 1.35; }
.card .tag { font-weight: 600; opacity: 0.8; }
.card .how { font-size: clamp(12px, 2.8vmin, 15px); opacity: 0.75; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.btn {
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  padding: 8px 18px;
  font-size: clamp(16px, 3.8vmin, 20px);
  box-shadow: 0 4px 0 var(--ink);
  min-height: 44px;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.big {
  background: var(--sun);
  font-size: clamp(22px, 6vmin, 34px);
  padding: 6px 40px;
}
.made { font-size: 12px; color: var(--ink); opacity: 0.6; margin-top: 2px; }
.linkish { background: none; border: 0; text-decoration: underline; font-size: 13px; opacity: 0.6; padding: 6px; }

/* --- Result card. */
.result .res-big { font-size: clamp(44px, 12vmin, 80px); color: var(--sun); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 4px 0 var(--ink); }
.result.fail .res-big { color: var(--red); }
.earn { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; font-size: clamp(14px, 3.4vmin, 17px); }
.earn li { display: flex; justify-content: space-between; gap: 24px; min-width: 210px; }
.earn li.total { border-top: 2px dashed rgba(42, 33, 30, 0.3); padding-top: 4px; margin-top: 2px; }
.earn b { color: #b07a00; }
.result.fail .earn { display: none; }

/* --- Settings. */
.settings { width: min(92vw, 420px); }
.set-row { display: flex; justify-content: space-between; align-items: center; width: 100%; font-weight: 700; font-size: 17px; gap: 12px; }
.set-row.col { flex-direction: column; align-items: flex-start; }
.toggle {
  width: 64px;
  height: 36px;
  border-radius: 999px;
  border: 3px solid var(--ink);
  background: #d8d2c6;
  position: relative;
  padding: 0;
}
.toggle i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--ink);
  transition: transform 0.15s;
}
.toggle[aria-checked="true"] { background: var(--grass); }
.toggle[aria-checked="true"] i { transform: translateX(28px); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  padding: 0;
  font-size: 11px;
  font-weight: 800;
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--cream), 0 0 0 6px var(--ink); }
.settings.off .swatches { opacity: 0.35; pointer-events: none; }

/* --- HUD. */
.hud {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 12px) 0 calc(var(--safe-l) + 12px);
  gap: 10px;
  align-items: flex-start;
  pointer-events: none;
  z-index: 5;
}
.bar { flex: 1; display: flex; flex-direction: column; gap: 3px; max-width: 40%; }
.foes { flex: 1; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; max-width: 40%; margin-left: auto; }
.foes .bar { width: 100%; max-width: none; align-items: flex-end; }
.foes .bar.small .track { height: clamp(8px, 1.8vmin, 12px); }
.foes .bar.small .name { font-size: clamp(11px, 2.6vmin, 15px); }
.bar.out { opacity: 0.4; }
.name {
  font-size: clamp(14px, 3.4vmin, 22px);
  color: #fff;
  -webkit-text-stroke: 1.5px var(--ink);
  paint-order: stroke fill;
}
.track {
  width: 100%;
  height: clamp(12px, 2.6vmin, 20px);
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  overflow: hidden;
}
.fill {
  height: 100%;
  background: var(--bar, var(--grass));
  transform-origin: left center;
  transition: transform 0.15s;
}
.foes .fill { transform-origin: right center; }
.bar.low .fill { animation: blink 0.5s steps(2) infinite; }
@keyframes blink { 50% { filter: brightness(1.5); } }
.mid { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.round { font-size: clamp(12px, 2.6vmin, 16px); color: #fff; -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill; }
.icons { display: flex; gap: 8px; pointer-events: auto; }
.icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: rgba(255, 255, 255, 0.85);
  display: grid;
  place-items: center;
  padding: 0;
}
.icon svg { width: 22px; height: 22px; fill: var(--ink); stroke: var(--ink); }

/* --- Touch controls: Grab bottom left, joystick bottom right. Both see-through and
   fixed in place: nothing here ever moves or scales, so a press can't shift them. */
.controls { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.grab-btn {
  -webkit-appearance: none;
  appearance: none;
  position: absolute;
  left: calc(var(--safe-l) + 18px);
  bottom: calc(var(--safe-b) + 16px);
  width: var(--grab);
  height: var(--grab);
  border-radius: 50%;
  border: 3px solid rgba(42, 33, 30, 0.45);
  background: rgba(255, 255, 255, 0.22);
  color: rgba(42, 33, 30, 0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  touch-action: none;
  padding: 0;
  margin: 0;
}
.grab-btn svg { width: 46%; height: 46%; fill: none; stroke: rgba(42, 33, 30, 0.7); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.grab-btn span { font-size: clamp(13px, 3.4vmin, 19px); line-height: 1; }
.grab-btn.on { background: rgba(59, 209, 111, 0.45); }
.grab-btn.can-grab { background: rgba(255, 210, 63, 0.5); border-color: rgba(42, 33, 30, 0.7); box-shadow: 0 0 0 6px rgba(255, 210, 63, 0.35); }

.stick-zone {
  position: absolute;
  right: calc(var(--safe-r) + 18px - var(--stick) * 0.3);
  bottom: calc(var(--safe-b) + 14px - var(--stick) * 0.3);
  width: calc(var(--stick) * 1.6);
  height: calc(var(--stick) * 1.6);
  pointer-events: auto;
  touch-action: none;
}
.stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--stick);
  height: var(--stick);
  margin: calc(var(--stick) / -2) 0 0 calc(var(--stick) / -2);
  border-radius: 50%;
  border: 3px solid rgba(42, 33, 30, 0.4);
  background: rgba(255, 255, 255, 0.18);
  pointer-events: none;
}
.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  height: 42%;
  margin: -21% 0 0 -21%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  border: 3px solid rgba(42, 33, 30, 0.55);
}
.ico { position: absolute; width: 24%; height: 24%; display: grid; place-items: center; border-radius: 50%; }
.ico svg { width: 100%; height: 100%; fill: none; stroke: rgba(42, 33, 30, 0.6); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.ico.up { left: 38%; top: 3%; }
.ico.down { left: 38%; bottom: 3%; }
.ico.left { left: 3%; top: 38%; }
.ico.right { right: 3%; top: 38%; }
.stick.up .ico.up, .stick.down .ico.down, .stick.left .ico.left, .stick.right .ico.right { background: rgba(255, 210, 63, 0.6); }
.stick.up .ico.up svg, .stick.down .ico.down svg, .stick.left .ico.left svg, .stick.right .ico.right svg { stroke: var(--ink); }

/* --- Ready screen: level picker on top, weapon shop down the left. */
.ready { position: absolute; inset: 0; z-index: 8; pointer-events: none; }
.ready > * { pointer-events: auto; }
.ready-top {
  position: absolute;
  top: calc(var(--safe-t) + 8px);
  left: calc(var(--safe-l) + 10px);
  right: calc(var(--safe-r) + 10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}
.ready-top > * { pointer-events: auto; }
.coins {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 4px 14px 4px 6px;
  box-shadow: 0 3px 0 var(--ink);
}
.coin {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3b0, #ffc42e 45%, #e09a12);
  border: 2px solid var(--ink);
  display: inline-block;
}
.coin-n { font-size: 22px; }
.coins.bump { animation: bump 0.3s; }
@keyframes bump { 50% { transform: scale(1.15); } }
.lvl { display: flex; align-items: center; gap: 6px; }
.lvl-text { display: flex; flex-direction: column; align-items: center; text-align: center; }
.lvl-num { font-size: clamp(22px, 5.5vmin, 36px); color: #fff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; line-height: 1; }
.lvl-name { font-weight: 800; font-size: clamp(12px, 2.8vmin, 16px); background: var(--cream); border: 2px solid var(--ink); border-radius: 999px; padding: 1px 10px; }
.arrow { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--ink); background: #fff; font-size: 26px; line-height: 1; padding: 0 0 4px; font-weight: 800; }
.arrow:disabled { opacity: 0.3; }
.ready-icons { display: flex; gap: 8px; }

.shop {
  position: absolute;
  left: calc(var(--safe-l) + 10px);
  top: calc(var(--safe-t) + 66px);
  bottom: 10px;
  width: clamp(160px, 26vw, 230px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 2px 4px 10px 2px;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.shop-item {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 0 6px;
  background: rgba(255, 248, 232, 0.92);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 4px 8px 4px 10px;
  text-align: left;
  min-height: 56px;
}
.shop-item b { font-size: clamp(13px, 2.8vmin, 16px); }
.shop-item .price { font-size: 13px; font-weight: 800; display: flex; align-items: center; gap: 4px; justify-self: end; }
.shop-item .price .coin { width: 16px; height: 16px; }
.shop-item canvas { grid-column: 1 / span 2; position: static; width: 100% !important; height: auto !important; max-height: 36px; object-fit: contain; }
.shop-item.owned .price { color: #2b7a46; }
.shop-item.equipped { background: var(--sun); box-shadow: 0 3px 0 var(--ink); }
.shop-item.poor { opacity: 0.55; }
.shop-item.none { min-height: 44px; grid-template-rows: auto; }

.ready-go {
  position: absolute;
  left: calc(clamp(160px, 26vw, 230px) + var(--safe-l) + 24px);
  right: calc(var(--safe-r) + 16px);
  bottom: calc(var(--safe-b) + 14px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.ready-go .tip {
  margin: 0;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: clamp(13px, 3vmin, 16px);
  text-align: center;
  max-width: 520px;
}
.ready-go .btn.big { font-size: clamp(26px, 7vmin, 40px); padding: 6px 54px; }

@media (orientation: portrait) {
  .shop {
    top: auto;
    bottom: calc(var(--safe-b) + 150px);
    left: 10px;
    right: 10px;
    width: auto;
    height: 118px;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x;
  }
  .shop-item { min-width: 132px; }
  .ready-go { left: 16px; }
  .lvl-name { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* --- Banner and replay tag. */
.banner {
  position: absolute;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  z-index: 7;
}
.banner .big {
  font-size: clamp(48px, 15vmin, 130px);
  color: var(--sun);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink);
  line-height: 1;
}
.banner.fail .big { color: var(--red); }
.banner.win .big { color: var(--grass); }
.banner .small {
  font-size: clamp(18px, 4.6vmin, 34px);
  color: #fff;
  -webkit-text-stroke: 1.5px var(--ink);
  paint-order: stroke fill;
}
.banner.go { animation: pop 1.6s ease-out both; }
@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  12% { transform: translate(-50%, -50%) scale(1.12); opacity: 1; }
  20% { transform: translate(-50%, -50%) scale(1); }
  82% { opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

.replay-tag {
  position: absolute;
  top: calc(var(--safe-t) + 64px);
  left: 50%;
  transform: translateX(-50%);
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 14px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--cream);
  font-size: 18px;
  z-index: 8;
}
.replay-tag .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--red); animation: blink 0.8s steps(2) infinite; }
.replay-tag button { border: 2px solid var(--ink); border-radius: 999px; background: #fff; padding: 4px 12px; font: inherit; font-size: 15px; min-height: 36px; }

@media (prefers-reduced-motion: reduce) {
  .banner.go { animation: none; }
}

.result.fail [data-go="again"] { display: none; }
