* { box-sizing: border-box; }
:root {
  --paper: #FDFDF6; --blue: #2B59C3; --red: #E63946; --green: #06A77D; --yellow: #FFB400; --ink: #2F3E46;
  --font: "Baloo 2", "Nunito", system-ui, "Noto Sans", sans-serif;
  --wob: 255px 15px 225px 15px / 15px 225px 15px 255px;
  --wob2: 15px 255px 15px 225px / 225px 15px 255px 15px;
}
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #1c2a52; color: var(--ink); font-family: var(--font);
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none;
}
#viewport { position: fixed; inset: 0; }
#stage { position: absolute; left: 0; top: 0; width: 1280px; height: 720px; transform-origin: 0 0; overflow: hidden; }
#game { position: absolute; inset: 0; width: 1280px; height: 720px; display: block; touch-action: none; }
button, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- notebook paper */
.card, .btn, .tag, .rbtn, .toast, .bubble {
  background-color: var(--paper);
  background-image: linear-gradient(rgba(43,89,195,.1) 1px, transparent 1px), linear-gradient(90deg, rgba(43,89,195,.1) 1px, transparent 1px);
  background-size: 16px 16px;
}
.card {
  position: relative; width: 600px; max-width: 92%; padding: 24px 32px 22px;
  border: 3px solid var(--blue); border-radius: var(--wob); box-shadow: 6px 7px 0 rgba(43,89,195,.35);
  animation: cardIn .35s cubic-bezier(.2,1.6,.4,1) both;
}
.card::after { /* taped corner */
  content: ''; position: absolute; top: -14px; left: 50%; width: 110px; height: 28px; margin-left: -55px;
  background: rgba(255,180,0,.45); transform: rotate(-3deg); border-left: 2px dashed rgba(0,0,0,.08); border-right: 2px dashed rgba(0,0,0,.08);
}
.card.wide { width: 1000px; }
.card.narrow { width: 420px; }
.card h2 { margin: 4px 0 6px; font-size: 42px; line-height: 1.05; color: var(--red); overflow-wrap: anywhere; transform: rotate(-1.5deg); }
.card .sub { margin: 4px 0 12px; font-size: 20px; font-weight: 700; color: #4b5563; line-height: 1.3; }
.card .sub.small { font-size: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
@keyframes cardIn { from { transform: translateY(40px) rotate(-4deg) scale(.8); opacity: 0; } }

.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.overlay.dim { background: rgba(28,42,82,.55); }

/* ---------------------------------------------------------------- buttons */
.btn {
  position: relative; border: 3px solid var(--ink); cursor: pointer; padding: 10px 26px; min-height: 58px; border-radius: var(--wob2);
  font-size: 25px; font-weight: 800; color: var(--ink); box-shadow: 4px 4px 0 var(--ink); transition: transform .08s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; line-height: 1.1; text-align: center;
}
.btn:hover { transform: translate(-1px, -2px) rotate(-1deg); }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn.play { background: var(--red); color: #fff; text-shadow: 2px 2px 0 rgba(0,0,0,.25); }
.btn.daily { background: var(--green); color: #fff; flex-direction: column; gap: 0; text-shadow: 2px 2px 0 rgba(0,0,0,.2); }
.btn.daily small, .btn small { font-size: 15px; opacity: .95; font-weight: 700; }
.btn.ghost { background: rgba(253,253,246,.8); }
.btn.small { font-size: 19px; min-height: 52px; padding: 8px 14px; }
.btn .em { font-size: 24px; }
.btn[disabled] { filter: grayscale(.8); opacity: .55; cursor: default; }
.rbtn {
  width: 52px; height: 52px; border-radius: 50%; border: 3px solid var(--ink); cursor: pointer; font-size: 20px; font-weight: 800;
  box-shadow: 3px 3px 0 var(--ink); display: grid; place-items: center;
}
.rbtn:active { transform: translate(2px, 2px); box-shadow: none; }
.badge {
  position: absolute; top: -10px; right: -10px; min-width: 26px; height: 26px; border-radius: 13px; background: var(--red);
  color: #fff; font-style: normal; font-size: 15px; line-height: 22px; border: 2px solid var(--ink); animation: bob 1s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-4px); } }
.actions { display: flex; gap: 12px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 14px; border-radius: var(--wob2); border: 3px solid var(--ink);
  font-weight: 800; font-size: 21px; box-shadow: 3px 3px 0 var(--ink); white-space: nowrap;
}
.ico-coin { display: inline-block; width: 28px; height: 28px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #ffe28a, var(--yellow) 55%, #c98a00 72%); border: 2px solid var(--ink); }

/* ---------------------------------------------------------------- HUD */
#hud { position: absolute; left: 0; right: 0; top: 0; height: 90px; pointer-events: none; }
.hud-left { position: absolute; left: 14px; top: 12px; max-width: 420px; }
.tag.lvl b { color: var(--red); }
.tag.lvl span { overflow: hidden; text-overflow: ellipsis; max-width: 300px; font-size: 19px; }
.hud-right { position: absolute; right: 14px; top: 12px; display: flex; gap: 10px; align-items: center; pointer-events: auto; }
.tag.timer { font-variant-numeric: tabular-nums; font-size: 20px; min-width: 116px; justify-content: center; }
.hintbtn { cursor: pointer; font-size: 18px; }
.hintbtn.free { background: var(--yellow); animation: wiggle .5s ease-in-out infinite; }
.hintbtn.on { background: #ffd5d9; }
.hud-deaths {
  position: absolute; left: 50%; top: 4px; transform: translateX(-50%) rotate(-2deg); display: flex; align-items: baseline; gap: 8px;
  color: var(--red); font-weight: 800; text-shadow: 2px 2px 0 #fff, -2px -2px 0 #fff, 2px -2px 0 #fff, -2px 2px 0 #fff;
}
.hud-deaths .skull { font-size: 40px; color: var(--ink); }
.hud-deaths b { font-size: 60px; line-height: 1; }
.hud-deaths small { font-size: 20px; color: var(--ink); }
.hud-deaths.bump { animation: bump .45s cubic-bezier(.2,2,.4,1); }
@keyframes bump { 0% { transform: translateX(-50%) scale(1.8) rotate(-12deg); } 100% { transform: translateX(-50%) scale(1) rotate(-2deg); } }
@keyframes wiggle { 50% { transform: rotate(3deg) scale(1.05); } }

/* jester narrator */
#jester { position: absolute; right: 8px; top: 66px; width: 560px; height: 110px; pointer-events: none; transition: opacity .25s; }
#jester.faded { opacity: .22; }
#jester.menu { top: auto; bottom: 20px; right: 30px; height: 240px; }
.jpic { position: absolute; right: 0; bottom: 0; transform-origin: bottom center; }
.jpic.hop { animation: jhop .5s cubic-bezier(.2,2,.4,1); }
@keyframes jhop { 30% { transform: translateY(-14px) rotate(-4deg); } }
.bubble {
  position: absolute; right: 84px; top: 4px; max-width: 440px; padding: 8px 16px; border: 3px solid var(--ink); border-radius: var(--wob);
  font-size: 20px; opacity: .93; font-weight: 800; line-height: 1.2; box-shadow: 3px 4px 0 rgba(0,0,0,.2); animation: bubIn .3s cubic-bezier(.2,1.8,.4,1);
}
.bubble::after { content: ''; position: absolute; right: -16px; top: 16px; border: 10px solid transparent; border-left: 14px solid var(--ink); }
#jester.menu .bubble { right: 150px; top: 20px; }
@keyframes bubIn { from { transform: scale(.4) rotate(6deg); opacity: 0; } }

.tut {
  position: absolute; left: 50%; top: 190px; transform: translateX(-50%) rotate(-1deg); padding: 8px 22px; font-size: 26px; font-weight: 800;
  color: var(--blue); background: rgba(253,253,246,.92); border: 3px dashed var(--blue); border-radius: var(--wob2); white-space: nowrap; pointer-events: none;
  max-width: 1100px; overflow: hidden; text-overflow: ellipsis; animation: cardIn .3s both;
}
.toast {
  position: absolute; left: 50%; bottom: 30px; transform: translateX(-50%); padding: 12px 28px; border: 3px solid var(--ink); border-radius: var(--wob2);
  font-size: 22px; font-weight: 800; box-shadow: 4px 4px 0 var(--ink); animation: cardIn .3s both; max-width: 80%; text-align: center; pointer-events: none; z-index: 5;
}

/* touch pad */
#pad { position: absolute; inset: 0; pointer-events: none; }
.pbtn {
  position: absolute; bottom: 8px; width: 118px; height: 118px; border-radius: 50%; border: 4px solid rgba(47,62,70,.7); background: rgba(253,253,246,.45);
  font-size: 48px; font-weight: 800; color: var(--ink); pointer-events: auto; touch-action: none; display: grid; place-items: center;
}
#pad-l { left: 10px; } #pad-r { left: 140px; }
.pbtn.jump { right: 12px; width: 132px; height: 132px; background: rgba(230,57,70,.35); }
.pbtn.on { background: rgba(255,180,0,.7); transform: scale(.94); }

/* ---------------------------------------------------------------- menu */
#menu { justify-content: flex-start; align-items: flex-start; padding: 60px 0 0 70px; background: linear-gradient(90deg, rgba(253,253,246,.92) 0, rgba(253,253,246,.7) 44%, rgba(253,253,246,0) 70%); }
.menu-top { position: absolute; top: 18px; right: 20px; display: flex; gap: 12px; align-items: center; }
.tag.coins { font-size: 24px; }
.tag.streak { color: var(--red); font-size: 18px; }
.logo h1 { margin: 0; line-height: .88; transform: rotate(-4deg); animation: logoBob 3s ease-in-out infinite; }
.logo .l1 { display: inline-block; font-size: 70px; color: var(--blue); }
.logo .l2 { display: block; width: max-content; white-space: nowrap; font-size: 104px; color: var(--red); text-shadow: 4px 4px 0 var(--yellow), 7px 7px 0 var(--ink); position: relative; }
.logo .l2::after { content: ''; position: absolute; left: 4%; right: 6%; bottom: 8px; height: 8px; background: var(--blue); border-radius: 4px; transform: rotate(-1.5deg); opacity: .7; }
.logo p { margin: 16px 0 0 6px; font-size: 26px; font-weight: 800; color: var(--ink); max-width: 620px; }
@keyframes logoBob { 50% { transform: rotate(-3deg) translateY(-6px); } }
.menu-main { display: flex; flex-direction: column; gap: 14px; margin-top: 24px; width: 400px; }
.menu-main .btn { width: 100%; }
#btn-play { font-size: 40px; min-height: 84px; animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.04) rotate(-1deg); } }
.menu-row { display: flex; gap: 10px; margin-top: 14px; width: 560px; }
.menu-row .btn { flex: 1; padding: 8px 8px; font-size: 18px; }
.menu-foot { margin-top: 16px; font-size: 22px; font-weight: 800; color: var(--ink); display: flex; gap: 20px; }

/* ---------------------------------------------------------------- levels */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { border: 3px solid var(--ink); background: var(--paper); border-radius: var(--wob2); padding: 4px 12px; font-weight: 800; font-size: 17px; cursor: pointer; }
.tab.on { background: var(--yellow); box-shadow: 3px 3px 0 var(--ink); }
.tab.locked { opacity: .5; }
.world-info { margin: 10px 0 4px; font-size: 18px; font-weight: 800; color: #4b5563; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.world-info .m { background: rgba(43,89,195,.12); border: 2px solid rgba(43,89,195,.3); border-radius: 12px; padding: 0 10px; }
.level-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 10px; }
.lv {
  position: relative; text-align: left; border: 3px solid rgba(47,62,70,.35); border-radius: var(--wob2); padding: 8px 12px; cursor: pointer;
  background: rgba(255,255,255,.8); min-height: 92px; display: flex; flex-direction: column; gap: 2px; transition: transform .1s;
}
.lv:hover { transform: translateY(-3px) rotate(-.8deg); }
.lv .id { font-size: 16px; font-weight: 800; color: var(--red); }
.lv .nm { font-size: 21px; font-weight: 800; line-height: 1.05; overflow-wrap: anywhere; }
.lv .st { font-size: 20px; color: var(--yellow); letter-spacing: 2px; text-shadow: 1px 1px 0 var(--ink); }
.lv .st .off { color: #d4d4d4; text-shadow: none; }
.lv .meta { font-size: 14px; font-weight: 700; color: #6b7280; }
.lv.done { border-color: var(--green); }
.lv.cur { border-color: var(--red); box-shadow: 4px 4px 0 var(--red); animation: wiggle 1.4s ease-in-out infinite; }
.lv.locked { cursor: default; opacity: .45; }
.lv.locked:hover { transform: none; }
.lv .lock { position: absolute; right: 10px; top: 8px; font-size: 22px; }
.lv .hat { position: absolute; right: 8px; bottom: 6px; font-size: 18px; }

/* ---------------------------------------------------------------- daily / stats */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: rgba(6,167,125,.1); border: 2px solid rgba(47,62,70,.2); border-radius: 10px; padding: 8px 12px; font-size: 19px; font-weight: 800; }
.stat small { display: block; font-size: 14px; color: #6b7280; }
.causes { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.cause { display: grid; grid-template-columns: 200px 1fr 60px; gap: 10px; align-items: center; font-size: 17px; font-weight: 800; }
.cause .bar { height: 14px; background: rgba(47,62,70,.12); border-radius: 7px; overflow: hidden; }
.cause .bar i { display: block; height: 100%; background: repeating-linear-gradient(90deg, var(--red) 0 8px, #f07a84 8px 16px); }
/* Hall of Shame: 4 stat tiles per row and causes in 2 columns so the card fits 720px in every language */
#stats .card { width: 960px; }
#stats .stats { grid-template-columns: repeat(4, 1fr); }
#stats .causes { display: grid; grid-template-columns: 1fr 1fr; column-gap: 28px; row-gap: 6px; }
#stats .causes > .stat { grid-column: 1 / -1; }
#stats .cause { grid-template-columns: minmax(0, 170px) 1fr 50px; }
#stats .cause > :first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- hats */
.hat-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-top: 12px; }
.hatc {
  position: relative; border: 3px solid rgba(47,62,70,.3); border-radius: var(--wob2); padding: 6px; cursor: pointer; background: rgba(255,255,255,.7);
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 150px;
}
.hatc .pic { height: 70px; display: flex; align-items: flex-end; justify-content: center; }
.hatc.locked .pic div { filter: brightness(0) opacity(.3); }
.hatc .nm { font-size: 15px; font-weight: 800; text-align: center; line-height: 1.1; }
.hatc .rq { font-size: 12px; font-weight: 700; color: #6b7280; text-align: center; line-height: 1.1; }
.hatc.on { border-color: var(--red); box-shadow: 4px 4px 0 var(--red); }
.hatc:hover .pic div { animation: wiggle .4s ease-in-out infinite; }

/* ---------------------------------------------------------------- settings */
.set-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.set { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 22px; font-weight: 800; }
.toggle { min-width: 90px; height: 42px; border-radius: var(--wob2); border: 3px solid var(--ink); cursor: pointer; font-weight: 800; background: #e5e7eb; box-shadow: 3px 3px 0 var(--ink); }
.toggle.on { background: var(--green); color: #fff; }
select { height: 44px; border-radius: 10px; border: 3px solid var(--ink); background: var(--paper); font-size: 19px; font-weight: 700; padding: 0 8px; max-width: 260px; }

/* ---------------------------------------------------------------- result */
#result { background: radial-gradient(ellipse at center, rgba(28,42,82,.2), rgba(28,42,82,.6)); }
.card.result { width: 640px; text-align: center; }
.res-kicker { margin: 0; font-size: 20px; font-weight: 800; color: var(--green); }
.res-stars { display: flex; justify-content: center; gap: 14px; margin: 6px 0; }
.res-stars i { width: 70px; height: 70px; font-style: normal; font-size: 64px; line-height: 70px; color: #ddd; }
.res-stars i::before { content: '★'; }
.res-stars i.on { color: var(--yellow); text-shadow: 3px 3px 0 var(--ink); animation: stampIn .45s cubic-bezier(.2,2,.4,1) both; }
@keyframes stampIn { 0% { transform: scale(3) rotate(-30deg); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.res-body { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.res-line { display: flex; flex-direction: column; align-items: center; font-size: 20px; font-weight: 800; color: #6b7280; }
.res-line b { font-size: 52px; color: var(--ink); line-height: 1.05; font-variant-numeric: tabular-nums; }
.newbest { display: inline-block; margin-top: 6px; font-size: 24px; font-weight: 800; color: #fff; background: var(--red); border: 3px solid var(--ink); padding: 2px 16px; transform: rotate(-4deg); animation: stampIn .4s .6s both, bob 1s 1.1s infinite; }
.goal { margin: 10px 0 0; font-size: 19px; font-weight: 800; color: var(--blue); }
.retry-hint { margin: 10px 0 0; font-size: 16px; font-weight: 700; color: #6b7280; animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .4; } }

/* ---------------------------------------------------------------- loading / rotate */
#loading { background: #FDFDF6 url(assets/cover.webp) center / cover no-repeat; }
.loader { text-align: center; color: var(--ink); font-size: 26px; font-weight: 800; background: rgba(253,253,246,.85); padding: 18px 30px; border-radius: var(--wob); border: 3px solid var(--blue); }
.spin { width: 60px; height: 60px; margin: 0 auto 10px; border-radius: 50%; border: 6px solid rgba(43,89,195,.25); border-top-color: var(--red); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#rotate {
  display: none; position: fixed; inset: 0; z-index: 9; background: var(--blue); color: #fff; font-size: 22px; font-weight: 800;
  flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px;
}
#rotate span { font-size: 60px; animation: bob 1.2s infinite; }
@media (orientation: portrait) and (max-width: 700px) and (pointer: coarse) { body.touch #rotate { display: flex; } }

/* phones: the stage is scaled to ~50%, so small print grows */
@media (max-height: 500px), (max-width: 700px) {
  .lv .meta, .hatc .rq { font-size: 16px; }
  .lv .nm { font-size: 24px; }
  .card .sub { font-size: 23px; }
  .stat { font-size: 23px; }
  .bubble { font-size: 27px; }
  .tut { font-size: 32px; }
  .rbtn { width: 64px; height: 64px; font-size: 24px; }
  .tag { height: 54px; font-size: 25px; }
  .menu-foot { font-size: 26px; }
  .retry-hint, .goal { font-size: 23px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
