:root {
  --ink: #2a1408;
  --wood: #6b3a18;
  --leaf: #2f9e3a;
  --leaf-dark: #1d7a28;
  --gold: #ffd34d;
  --cream: #fff6df;
  --danger: #e23b2e;
  --sky: #7ec8e8;
  --shadow: 0 10px 0 rgba(42, 20, 8, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #7ec8e8;
  color: var(--ink);
  font-family: Nunito, system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

img { display: block; max-width: 100%; pointer-events: none; }

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#bg {
  position: absolute;
  inset: 0;
  background: url("../assets/bg.webp") center / cover no-repeat;
  transform: scale(1.04);
}

#fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

#world {
  position: absolute;
  inset: 0;
  z-index: 2;
}

#tree-pos {
  position: absolute;
  left: 50%;
  bottom: -6vh;
  width: min(640px, 82vw);
  transform: translateX(-52%);
  z-index: 2;
}

#tree-wrap {
  position: relative;
  width: 100%;
  transform-origin: 50% 92%;
  will-change: transform;
}

#tree { width: 100%; height: auto; filter: drop-shadow(0 18px 16px rgba(0,0,0,.28)); }

#horse-box {
  position: absolute;
  width: 38%;
  left: 52%;
  top: 14%;
  transform-origin: 55% 70%;
  will-change: transform;
  filter: drop-shadow(0 8px 6px rgba(0,0,0,.25));
  z-index: 3;
}

#horse-box.walking {
  position: fixed;
  z-index: 4;
  left: 0;
  top: 0;
  filter: drop-shadow(0 12px 10px rgba(0, 0, 0, 0.32));
}

#horse-box.falling {
  z-index: 8;
  filter: drop-shadow(0 14px 10px rgba(0,0,0,.35));
}

#horse-box img#horse {
  width: 100%;
  height: auto;
  display: block;
  pointer-events: none;
}

#eye-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  --eye-p: 0;
}

#eye-fx.on { opacity: 1; }

.eyeball {
  position: absolute;
  display: block;
  transform: translate(-50%, -50%) scale(var(--eye-s, 1));
  transform-origin: 50% 55%;
  mix-blend-mode: multiply;
  filter: drop-shadow(0 0 calc(var(--eye-p) * 5px) rgba(170, 0, 0, calc(var(--eye-p) * .7)));
  will-change: transform, filter;
}

.eyeball svg { width: 100%; height: 100%; display: block; overflow: visible; }

.eyeball .sclera {
  fill: rgba(255, 214, 214, 0.22);
}

.eyeball .veins {
  stroke: #c41010;
  stroke-width: 2.4;
  opacity: 0.15;
}

.eyeball .pupil, .eyeball .glint { fill: none; opacity: 0; }
.eyeball .lid {
  fill: none;
  stroke: rgba(140, 8, 8, 0.7);
  stroke-width: 4;
  opacity: 0;
}

#eye-fx.hot .veins { opacity: 1; }
#eye-fx.burst .eyeball { animation: eye-throb .18s steps(2) infinite; }

@keyframes eye-throb {
  50% { transform: translate(-50%, -50%) scale(calc(var(--eye-s, 1) * 1.08)); }
}

#dust {
  position: fixed;
  width: min(420px, 70vw);
  pointer-events: none;
  opacity: 0;
  z-index: 9;
  transform: translate(-50%, -50%) scale(.4);
}

#dust.pop {
  animation: dust-pop .7s ease-out forwards;
}

@keyframes dust-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.35); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1.25); }
}

#hud {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

#hud[hidden] { display: none !important; }

#timer {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  font-family: "Baloo 2", Nunito, sans-serif;
  font-size: clamp(32px, 6vw, 56px);
  line-height: 1;
  color: #fff;
  text-shadow: 0 3px 0 #2a1408, 0 8px 0 rgba(0,0,0,.2);
  letter-spacing: 1px;
}

#hud-level {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  font-family: "Baloo 2", sans-serif;
  font-size: 14px;
  letter-spacing: 0.4px;
  color: #fff;
  text-align: center;
  text-shadow: 0 2px 0 #2a1408;
  width: 90%;
  max-width: 460px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#bar-wrap {
  position: absolute;
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  width: min(460px, 86vw);
}

#bar-label {
  font-family: "Baloo 2", sans-serif;
  font-size: 14px;
  letter-spacing: 2px;
  color: #fff;
  text-align: center;
  text-shadow: 0 2px 0 #2a1408;
  margin-bottom: 4px;
}

#bar {
  height: 28px;
  border: 4px solid var(--ink);
  border-radius: 16px;
  background: #3a2212;
  overflow: hidden;
  box-shadow: var(--shadow);
}

#bar-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(#ffce54, #e0891a);
  transform-origin: left center;
  transition: width 40ms linear;
}

#bar-fill.low { background: linear-gradient(#ff7a3a, #d62828); }
#bar-fill.critical {
  background: linear-gradient(#ff4d4d, #9b0d0d);
  animation: bar-flash .18s steps(2) infinite;
}

@keyframes bar-flash {
  50% { filter: brightness(1.35); }
}

#shout {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(22px, 4.4vw, 40px);
  color: #fff;
  text-align: center;
  text-shadow: 0 3px 0 #2a1408, 0 0 18px rgba(255, 200, 40, .45);
  min-height: 1.2em;
  width: 90%;
  pointer-events: none;
  overflow-wrap: anywhere;
}

#combo {
  position: absolute;
  right: 4vw;
  top: 38%;
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(28px, 5vw, 48px);
  color: var(--gold);
  text-shadow: 0 3px 0 #2a1408;
  transform: rotate(8deg);
  opacity: 0;
}

#combo.show { opacity: 1; animation: combo-pop .18s ease-out; }

@keyframes combo-pop {
  from { transform: rotate(8deg) scale(1.4); }
}

#spacekey {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  min-width: min(280px, 70vw);
  padding: 12px 28px 16px;
  background: linear-gradient(#fff, #e8e0d4);
  border: 5px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 10px 0 #2a1408;
  text-align: center;
  pointer-events: none;
}

#spacekey b {
  display: block;
  font-family: "Baloo 2", sans-serif;
  font-size: 28px;
  letter-spacing: 3px;
  line-height: 1;
}

#spacekey span {
  font-size: 12px;
  letter-spacing: 1px;
  opacity: .7;
}

#spacekey.down {
  transform: translateX(-50%) translateY(8px);
  box-shadow: 0 2px 0 #2a1408;
}

body.introing #spacekey,
body.introing #bar-wrap,
body.introing #timer,
body.introing #hud-level,
body.introing #combo {
  opacity: 0;
  pointer-events: none;
}

body.introing #shout {
  top: 14%;
  font-size: clamp(26px, 5.2vw, 48px);
}

#overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 2.4vh 2.4vw 0;
  background: linear-gradient(90deg, rgba(20, 10, 0, .32), transparent 52%);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}

#overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.card {
  width: min(400px, 92vw);
  max-height: 92vh;
  overflow: auto;
  background: rgba(255, 246, 223, 0.95);
  border: 6px solid var(--ink);
  border-radius: 28px;
  padding: 14px 16px 16px;
  text-align: center;
  box-shadow: 0 14px 0 rgba(42, 20, 8, .4);
}

.domain {
  font-size: 13px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--wood);
  font-weight: 800;
}

h1 {
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(40px, 8vw, 58px);
  line-height: .85;
  color: #d62828;
  letter-spacing: 1px;
  text-shadow: 0 4px 0 #2a1408;
  margin: 4px 0 8px;
}

h2 {
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(28px, 6vw, 40px);
  line-height: 1;
  color: #d62828;
  text-shadow: 0 3px 0 #2a1408;
  margin-bottom: 8px;
}

.blurb {
  font-size: 16px;
  line-height: 1.35;
  margin-bottom: 12px;
}

.levels {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 10px;
}

.btn.lvl {
  animation: none;
  font-size: 18px;
  line-height: 1.15;
  padding: 8px 12px 10px;
  margin: 0;
  color: #fff;
}

.btn.lvl.easy {
  background: linear-gradient(#8dff6a, #2f9e3a);
  box-shadow: 0 6px 0 #145c1c;
  text-shadow: 0 2px 0 #145c1c;
}

.btn.lvl.mid {
  background: linear-gradient(#ffe066, #e09a12);
  box-shadow: 0 6px 0 #8a5a00;
  text-shadow: 0 2px 0 #8a5a00;
  color: #2a1408;
}

.btn.lvl.hard {
  background: linear-gradient(#ff8c42, #d62828);
  box-shadow: 0 6px 0 #7a1010;
  text-shadow: 0 2px 0 #7a1010;
}

.btn.lvl.hell {
  background: linear-gradient(#4a2a6a, #1a1028);
  box-shadow: 0 6px 0 #09050f;
  text-shadow: 0 2px 0 #09050f;
  color: #ffe27a;
}

.btn.lvl:hover { filter: brightness(1.08); }
.btn.lvl:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 #2a1408;
}

.rank-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 8px 0 12px;
}

.rank-tabs .btn {
  margin: 0;
  font-size: 14px;
  padding: 6px 8px 8px;
  box-shadow: 0 4px 0 #2a1408;
  line-height: 1.15;
}

.rank-tabs .btn.on {
  background: var(--gold);
}

.time-big {
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(48px, 10vw, 72px);
  line-height: 1;
  color: var(--wood);
  text-shadow: 0 3px 0 rgba(42, 20, 8, .2);
}

.time-big small { font-size: .45em; }

.btn {
  display: block;
  width: 100%;
  font-family: "Baloo 2", sans-serif;
  font-size: 28px;
  letter-spacing: 1px;
  border: 5px solid var(--ink);
  border-radius: 16px;
  padding: 8px 28px 12px;
  cursor: pointer;
  margin: 8px 0 0;
  color: var(--ink);
}

.btn.play {
  background: linear-gradient(#6adf4a, #2f9e3a);
  box-shadow: 0 8px 0 #145c1c;
  color: #fff;
  text-shadow: 0 2px 0 #145c1c;
  animation: play-bob 1.4s ease-in-out infinite;
}

.btn.play:hover { filter: brightness(1.08); }
.btn.play:active {
  transform: translateY(6px);
  box-shadow: 0 2px 0 #145c1c;
  animation: none;
}

@keyframes play-bob {
  50% { transform: translateY(-4px); }
}

.btn.ghost {
  background: #fff;
  box-shadow: 0 6px 0 #2a1408;
  font-size: 20px;
}

.btn.ghost:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #2a1408;
}

.live-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 12px;
}

.live-stats div {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 6px 8px 8px;
}

.live-stats b {
  display: block;
  font-family: "Baloo 2", sans-serif;
  font-size: 26px;
  line-height: 1;
  color: #d62828;
}

.live-stats span {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  opacity: .7;
  margin-top: 2px;
}

.live-stats.slim {
  display: block;
  margin: 0 0 10px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 800;
}

.contact-line {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 800;
  opacity: .85;
}

.contact-line a {
  color: var(--wood);
  font-weight: 900;
}

.share-card {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  align-items: center;
  text-align: left;
  background: linear-gradient(#fff, #ffe9b8);
  border: 4px solid var(--ink);
  border-radius: 16px;
  padding: 8px 10px;
  margin: 4px 0 8px;
}

.share-card img {
  width: 72px;
  height: auto;
  justify-self: center;
}

.share-kicker {
  font-family: "Baloo 2", sans-serif;
  font-size: 18px;
  line-height: 1;
  color: #d62828;
  text-shadow: 0 2px 0 rgba(42, 20, 8, .15);
}

.share-line {
  font-size: 14px;
  font-weight: 800;
  line-height: 1.25;
  margin: 4px 0 2px;
}

.share-url {
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--wood);
  font-weight: 800;
}

.share-actions { margin: 0 0 8px; }

.share-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}

.share-mini {
  display: block;
  text-align: center;
  font-family: Nunito, sans-serif;
  font-size: 11px;
  font-weight: 800;
  text-decoration: none;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 7px 4px 8px;
  cursor: pointer;
  box-shadow: 0 3px 0 #2a1408;
}

.share-mini:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #2a1408;
}

#card-result .btn {
  font-size: 20px;
  padding: 6px 16px 8px;
  margin-top: 6px;
}

#card-result .btn.play { animation: none; }

#card-result .time-big {
  font-size: clamp(36px, 7vw, 56px);
}

#card-result .contact-line { margin-top: 8px; }

#nick-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 12px;
}

#nick-form[hidden] { display: none !important; }

#nick-form label {
  font-size: 14px;
  font-weight: 800;
}

#nick {
  width: 100%;
  font-family: Nunito, sans-serif;
  font-size: 20px;
  font-weight: 800;
  text-align: center;
  padding: 10px 12px;
  border: 4px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}

.board {
  list-style: none;
  margin: 8px 0 16px;
  text-align: left;
}

.board li {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 7px 10px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  margin-bottom: 6px;
  font-weight: 800;
}

.board li .pos { font-family: "Baloo 2", sans-serif; font-size: 22px; color: var(--wood); }
.board li .nick { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li .t { font-family: "Baloo 2", sans-serif; color: #d62828; }

.board li.me {
  background: var(--gold);
}

.board li:nth-child(1) { background: #ffe27a; }
.board li:nth-child(1).me { background: #ffd34d; }

.empty-board { opacity: .75; margin: 12px 0 16px; }

#modal {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(20, 10, 0, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#modal[hidden] { display: none !important; }

.board-card { max-height: 90vh; overflow: auto; }

#ad-banner {
  position: absolute;
  top: 10px;
  right: 64px;
  z-index: 31;
  width: min(320px, 38vw);
  height: 56px;
  pointer-events: auto;
}

.ad-slot {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 3px dashed rgba(42, 20, 8, .45);
  border-radius: 10px;
  background: rgba(255, 246, 223, .72);
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(42, 20, 8, .2);
  overflow: hidden;
}

.ad-kicker {
  font-family: "Baloo 2", sans-serif;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: var(--gold);
  border: 2px solid var(--ink);
  border-radius: 6px;
  padding: 1px 6px;
}

.ad-copy {
  font-size: 12px;
  font-weight: 800;
  opacity: .8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.playing #ad-banner {
  background: transparent;
}

#btn-mute {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 32;
  width: 48px;
  height: 48px;
  border: 4px solid var(--ink);
  border-radius: 50%;
  background: var(--cream);
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 4px 0 #2a1408;
}

#btn-mute.muted { opacity: .5; }

#card-result[hidden],
#card-title[hidden],
#result-board[hidden],
#btn-diploma[hidden] { display: none !important; }

#tissues {
  position: fixed;
  z-index: 11;
  width: min(170px, 40vw);
  pointer-events: none;
  opacity: 0;
  filter: drop-shadow(0 10px 8px rgba(0,0,0,.3));
}

#tissues[hidden] { display: none !important; }

#tissues.show {
  animation: tissues-in .5s cubic-bezier(.12, 1.4, .3, 1) forwards;
}

#tissues img { width: 100%; height: auto; }

.tissues-bubble {
  position: relative;
  margin: 0 0 6px 8px;
  padding: 8px 12px 10px;
  background: #fff;
  border: 4px solid var(--ink);
  border-radius: 16px 16px 16px 4px;
  color: var(--ink);
  font-family: "Baloo 2", sans-serif;
  font-size: 22px;
  line-height: 1;
  text-align: center;
  box-shadow: 0 4px 0 #2a1408;
  width: fit-content;
  max-width: 100%;
}

.tissues-bubble small {
  display: block;
  margin-top: 4px;
  font-family: Nunito, sans-serif;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.2px;
  opacity: .75;
}

@keyframes tissues-in {
  from { opacity: 0; transform: rotate(-14deg) scale(.35) translateY(28px); }
  to { opacity: 1; transform: rotate(-8deg) scale(1) translateY(0); }
}

#diploma {
  position: absolute;
  inset: 0;
  z-index: 16;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 2.4vh 2.4vw 0;
  background: rgba(20, 10, 0, .28);
}

#diploma[hidden] { display: none !important; }

.diploma-sheet {
  width: min(420px, 94vw);
  max-height: 94vh;
  overflow: auto;
  position: relative;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(180, 140, 70, .06) 0 2px,
      transparent 2px 8px
    ),
    linear-gradient(#fffaf0, #f4e2bc);
  border: 8px solid #2a1408;
  border-radius: 10px;
  padding: 22px 18px 16px;
  text-align: center;
  box-shadow: 0 16px 0 rgba(42, 20, 8, .42);
}

.diploma-sheet::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 3px solid #c9a227;
  border-radius: 4px;
  pointer-events: none;
}

.diploma-kicker {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--wood);
  font-weight: 800;
  margin: 4px 0 6px;
}

.diploma-sheet h2 {
  font-size: clamp(22px, 5.2vw, 30px);
  line-height: 1.05;
  margin: 4px 0 12px;
}

.diploma-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 8px 0 12px;
}

.diploma-stats div {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 8px 6px 10px;
}

.diploma-stats span {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  opacity: .7;
}

.diploma-stats b {
  display: block;
  font-family: "Baloo 2", sans-serif;
  font-size: 26px;
  line-height: 1.1;
  color: var(--wood);
}

.diploma-souls {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.3;
  color: #9b0d0d;
  background: #fff3e0;
  border: 3px dashed #d62828;
  border-radius: 12px;
  padding: 8px 10px;
  margin: 0 0 10px;
}

.diploma-advice {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.35;
  margin: 0 0 8px;
}

.diploma-stamp {
  display: inline-block;
  margin: 4px 0 8px;
  padding: 6px 12px;
  border: 4px solid #d62828;
  color: #d62828;
  font-family: "Baloo 2", sans-serif;
  font-size: 20px;
  letter-spacing: 2px;
  transform: rotate(-11deg);
  border-radius: 8px;
  background: rgba(255, 255, 255, .55);
}

@media (max-width: 700px) {
  #diploma {
    justify-content: center;
    padding: 8px 10px 0;
  }
  #tissues { width: min(132px, 36vw); }
  .tissues-bubble { font-size: 18px; padding: 6px 10px 8px; }
}

body.flash { background: #fff6d4; }
body.flash #bg { filter: brightness(1.25) saturate(1.1); }

@media (max-width: 700px) {
  #overlay {
    justify-content: center;
    padding: 8px 10px 0;
    background: linear-gradient(to bottom, rgba(20, 10, 0, .4), transparent 48%);
  }
  #tree-pos { width: min(420px, 88vw); left: 46%; bottom: -6vh; }
  #horse-box { width: 34%; left: 52%; top: 13%; }
  h1 { font-size: 34px; }
  .blurb { font-size: 14px; }
  .btn.lvl { font-size: 16px; padding: 7px 10px 8px; }
  #spacekey b { font-size: 22px; }
  .btn.play { font-size: 24px; }
  #btn-mute { top: auto; bottom: 14px; right: 12px; }
  #ad-banner {
    top: auto;
    bottom: 70px;
    right: 10px;
    left: 10px;
    width: auto;
    height: 48px;
  }
  body.playing #ad-banner { display: none; }
  .share-row { grid-template-columns: 1fr 1fr; }
  .live-stats b { font-size: 22px; }
}

@media (max-height: 700px) {
  #tree-pos { width: min(480px, 60vw); bottom: -8vh; }
  .card { padding: 14px 16px 16px; }
  h1 { font-size: 40px; }
}
