:root {
  --ink: #1f160c;
  --panel: rgba(34, 24, 14, 0.92);
  --panel-edge: #5a4026;
  --green: #6fbf3f;
  --green-dark: #3f7a22;
  --yellow: #f5c518;
  --red: #d6382a;
  --cream: #f6ecd2;
  --display: 'Bangers', Impact, 'Arial Black', sans-serif;
  --body: 'Lilita One', 'Trebuchet MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #24180d; color: var(--cream);
  font-family: var(--body);
  touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
canvas#game { position: fixed; inset: 0; display: block; outline: none; }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--display); letter-spacing: 1.5px;
  font-size: 22px; color: var(--ink);
  background: linear-gradient(#ffd84a, #e9a915);
  border: 4px solid var(--ink); border-radius: 14px;
  padding: 10px 26px; margin: 6px;
  box-shadow: 0 6px 0 var(--ink), inset 0 3px 0 rgba(255,255,255,.45);
  cursor: pointer; transition: transform .08s, box-shadow .08s;
}
.btn:hover { transform: translateY(-2px) rotate(-1deg); }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.btn:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }
.btn.big { font-size: clamp(26px, 5vw, 36px); padding: 12px 34px; }
.btn.ghost { background: transparent; color: var(--cream); border-color: rgba(246,236,210,.4); box-shadow: none; font-size: 18px; }
.btn.ghost:hover { border-color: var(--cream); }
#btn-start { animation: throb 1.1s ease-in-out infinite; }

/* ---------- overlay screens ---------- */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: radial-gradient(ellipse at center, rgba(20,12,4,.25), rgba(20,12,4,.7));
  animation: fade .35s ease-out;
  overflow-y: auto;
}
.panel {
  position: relative; text-align: center;
  background: var(--panel);
  border: 4px solid var(--ink); border-radius: 22px;
  box-shadow: 0 0 0 4px var(--panel-edge), 0 18px 40px rgba(0,0,0,.6);
  padding: 30px 26px 22px; max-width: 760px; width: 100%;
  animation: drop .45s cubic-bezier(.2,1.4,.4,1);
}
.panel::before {
  content: ''; position: absolute; left: 18px; right: 18px; top: -4px; height: 12px;
  background: repeating-linear-gradient(-45deg, var(--yellow) 0 12px, var(--ink) 12px 24px);
  border: 3px solid var(--ink); border-radius: 6px; transform: translateY(-50%);
}
.title-panel { background: rgba(34, 24, 14, 0.8); }

.logo {
  font-family: var(--display); font-weight: 400; margin: 4px 0 2px; line-height: .9;
  font-size: clamp(56px, 14vw, 116px); letter-spacing: 3px;
  display: flex; justify-content: center; gap: .25em; flex-wrap: wrap;
}
.logo span {
  display: inline-block; -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill;
  text-shadow: 0 7px 0 var(--ink);
}
.logo .w1 { color: var(--red); animation: wobble 2.4s ease-in-out infinite; }
.logo .w2 { color: var(--green); animation: wobble 2.4s ease-in-out -1.2s infinite; }
.tagline { font-size: clamp(16px, 3.4vw, 21px); margin: 10px 0 12px; }
.tagline b, .cause b { color: var(--yellow); }

.chain { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: 2px; margin: 6px 0 4px; }
.chain-item { display: flex; flex-direction: column; align-items: center; width: 64px; }
.chain-item canvas { width: 54px; height: 54px; }
.chain-item span { font-size: 11px; line-height: 1.1; opacity: .85; white-space: nowrap; }
.chain-item.you canvas { filter: drop-shadow(0 0 6px var(--yellow)); }
.chain-item.you span { color: var(--yellow); opacity: 1; font-size: 13px; }
.chain-item.food span { color: #9fe36d; }
.chain-arrow { font-family: var(--display); font-size: 22px; color: rgba(246,236,210,.45); padding-bottom: 22px; }

.legend { font-size: 14px; opacity: .9; margin: 8px 0 12px; }
.dot { display: inline-block; width: 14px; height: 8px; border-radius: 50%; border: 3px solid; vertical-align: middle; }
.dot.green { border-color: #78ff50; }
.dot.red { border-color: #ff3220; }
.seg { display: inline-flex; align-items: center; gap: 0; margin: 0 0 12px; border: 3px solid var(--ink); border-radius: 12px; overflow: hidden; background: rgba(0,0,0,.35); }
.seg-lbl { font-size: 13px; opacity: .7; padding: 0 10px; text-transform: uppercase; letter-spacing: 1px; }
.seg button { font-family: var(--display); letter-spacing: 1px; font-size: 18px; padding: 6px 14px; border: 0; border-left: 3px solid var(--ink); background: transparent; color: var(--cream); cursor: pointer; }
.seg button.on { background: var(--yellow); color: var(--ink); }
.seg button:focus-visible { outline: 3px solid #fff; outline-offset: -3px; }
#screen-pause .seg { display: flex; width: max-content; margin: 14px auto; }
.hint { font-size: 14px; opacity: .75; margin: 12px 0 0; }
kbd { font-family: var(--body); background: rgba(255,255,255,.12); border: 2px solid rgba(255,255,255,.25); border-bottom-width: 3px; border-radius: 6px; padding: 0 6px; }
.best { color: var(--yellow); margin: 8px 0 0; min-height: 1em; }
body.touch .desktop-only, body:not(.touch) .touch-only { display: none; }

.headline {
  font-family: var(--display); font-weight: 400; letter-spacing: 3px; margin: 0;
  font-size: clamp(54px, 13vw, 96px); line-height: 1;
  -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--ink);
  color: var(--cream);
}
.headline.red { color: var(--red); animation: shudder .5s ease-out; }
.headline.gold { color: var(--yellow); animation: throb 1s ease-in-out infinite; }
.cause { font-size: 20px; margin: 4px 0 14px; }
#over-killer { width: 110px; height: 110px; display: block; margin: 6px auto 0; }
#win-portrait { width: 150px; height: 150px; display: block; margin: 6px auto 0; filter: drop-shadow(0 0 14px rgba(245,197,24,.6)); }

.stats { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.stats > div { background: rgba(0,0,0,.35); border: 3px solid var(--ink); border-radius: 12px; padding: 8px 16px; min-width: 96px; }
.stats .lbl { display: block; font-size: 12px; opacity: .7; text-transform: uppercase; letter-spacing: 1px; }
.stats b { font-size: 22px; font-weight: 400; color: var(--yellow); }
.journey { display: flex; align-items: center; gap: 8px; font-size: 12px; margin: 0 auto 16px; max-width: 420px; opacity: .9; }
.journey .bar { flex: 1; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; left: 0; right: 0; top: 0; pointer-events: none;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
}
.hud-card {
  display: flex; align-items: center; gap: 8px;
  background: rgba(31,22,12,.78); border: 3px solid var(--ink); border-radius: 16px;
  box-shadow: 0 0 0 2px var(--panel-edge); padding: 6px 12px 6px 6px;
}
#hud-portrait { width: 64px; height: 64px; background: radial-gradient(circle, rgba(245,197,24,.25), transparent 70%); border-radius: 12px; }
.hud-info { min-width: 150px; }
#hud-name { font-family: var(--display); font-size: 24px; letter-spacing: 1.5px; line-height: 1; color: var(--yellow); -webkit-text-stroke: 1px var(--ink); }
.bar { height: 14px; background: rgba(0,0,0,.5); border: 3px solid var(--ink); border-radius: 9px; overflow: hidden; margin: 5px 0 4px; }
.bar > div { height: 100%; width: 0; background: linear-gradient(#9be05e, #4f9a31); border-radius: 6px; transition: width .25s ease-out; box-shadow: inset 0 2px 0 rgba(255,255,255,.35); }
.hud-next-row { display: flex; align-items: center; gap: 4px; font-size: 13px; opacity: .85; }
#hud-next-icon { width: 24px; height: 24px; }
#hud-eats { font-size: 11px; opacity: .65; margin-top: 2px; max-width: 220px; }
.hud-right { display: flex; align-items: center; gap: 8px; }
.stat {
  background: rgba(31,22,12,.78); border: 3px solid var(--ink); border-radius: 12px;
  padding: 4px 12px; text-align: center; min-width: 64px; box-shadow: 0 0 0 2px var(--panel-edge);
}
.stat .lbl { display: block; font-size: 10px; opacity: .65; text-transform: uppercase; letter-spacing: 1px; }
.stat span:last-child { font-family: var(--display); font-size: 22px; letter-spacing: 1px; }
.icon-btn {
  pointer-events: auto; width: 46px; height: 46px; border-radius: 12px; cursor: pointer;
  background: rgba(31,22,12,.78); border: 3px solid var(--ink); box-shadow: 0 0 0 2px var(--panel-edge);
  display: grid; place-items: center; padding: 0;
}
.icon-btn svg { width: 24px; height: 24px; fill: var(--cream); stroke: var(--cream); stroke-width: 2; stroke-linecap: round; }
.icon-btn .off, .icon-btn.off .on { display: none; }
.icon-btn.off .off { display: block; }
.icon-btn:hover { background: rgba(70,50,28,.9); }

/* ---------- banner ---------- */
#banner {
  position: fixed; left: 50%; top: 24%; transform: translate(-50%, -50%) scale(.6);
  opacity: 0; pointer-events: none; text-align: center; white-space: nowrap;
  font-size: clamp(18px, 4vw, 28px); color: var(--cream);
  -webkit-text-stroke: 1px var(--ink); text-shadow: 0 3px 0 var(--ink), 0 0 12px rgba(0,0,0,.6);
}
#banner.show { animation: bannerIn 2.4s ease-out forwards; }
#banner b { color: var(--yellow); }
#banner .waagh {
  display: block; font-family: var(--display); letter-spacing: 3px;
  font-size: clamp(56px, 13vw, 110px); line-height: 1; color: var(--yellow);
  -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; text-shadow: 0 7px 0 var(--ink);
}
#banner.big { top: 30%; }

/* ---------- joystick ---------- */
#joystick { position: fixed; inset: 0; pointer-events: none; }
.js-base, .js-knob { position: absolute; left: 0; top: 0; border-radius: 50%; }
.js-base {
  width: 124px; height: 124px; margin: -62px 0 0 -62px;
  background: radial-gradient(circle, rgba(0,0,0,.25), rgba(0,0,0,.4));
  border: 4px solid rgba(246,236,210,.35);
}
.js-knob {
  width: 58px; height: 58px; margin: -29px 0 0 -29px;
  background: radial-gradient(circle at 35% 30%, #ffe27a, #e9a915);
  border: 4px solid var(--ink); box-shadow: 0 4px 0 rgba(0,0,0,.4);
  opacity: .55;
}
#joystick.active .js-knob { opacity: .95; }
#joystick.active .js-base { border-color: rgba(246,236,210,.6); }
#joystick:not(.active) { opacity: .7; }

/* ---------- animation ---------- */
@keyframes fade { from { opacity: 0; } }
@keyframes drop { from { transform: translateY(-30px) scale(.94); opacity: 0; } }
@keyframes throb { 50% { transform: scale(1.06); } }
@keyframes wobble { 0%,100% { transform: rotate(-3deg) translateY(0); } 50% { transform: rotate(3deg) translateY(-6px); } }
@keyframes shudder { 0%,100% { transform: none; } 20% { transform: translateX(-10px) rotate(-3deg); } 40% { transform: translateX(10px) rotate(3deg); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  20% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(.96); }
}

/* ---------- small screens ---------- */
@media (max-width: 560px) {
  .panel { padding: 24px 12px 16px; }
  .chain-item { width: 46px; }
  .chain-item canvas { width: 42px; height: 42px; }
  .chain-item span { font-size: 9px; }
  .chain-arrow { display: none; }
  .hud-card { padding: 4px 8px 4px 4px; }
  #hud-portrait { width: 46px; height: 46px; }
  .hud-info { min-width: 110px; }
  #hud-name { font-size: 18px; }
  #hud-eats { display: none; }
  .stat { min-width: 48px; padding: 2px 8px; }
  .stat span:last-child { font-size: 18px; }
  .icon-btn { width: 40px; height: 40px; }
  .hud-right { gap: 5px; flex-wrap: wrap; justify-content: flex-end; max-width: 120px; }
  #banner { white-space: normal; width: 92vw; }
}
@media (max-height: 520px) {
  .panel { padding: 18px 16px 12px; }
  .logo { font-size: 56px; }
  .chain-item canvas { width: 40px; height: 40px; }
  .legend, .hint { margin: 4px 0; }
}
@media (prefers-reduced-motion: reduce) {
  .screen, .panel, .logo span, .btn, .headline { animation: none !important; }
}
