@font-face {
  font-family: 'Luckiest Guy';
  src: url('assets/fonts/luckiest-guy-latin.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Baloo 2';
  src: url('assets/fonts/baloo2-latin.woff2') format('woff2');
  font-weight: 500 800;
  font-display: swap;
}

:root {
  --ink: #14151a;
  --paper: #f4f5f6;
  --red: #e63946;
  --orange: #ff8a2a;
  --yellow: #ffd21f;
  --green: #3ddc84;
  --cyan: #19e3ff;
  --blue: #2f7bff;
  --purple: #a259ff;
  --pink: #ff4fa3;
  --display: 'Luckiest Guy', 'Arial Black', Impact, sans-serif;
  --body: 'Baloo 2', 'Trebuchet MS', Verdana, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  font-family: var(--body);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }

#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

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

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

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

#hudLeft { position: absolute; top: 22px; left: 24px; display: flex; flex-direction: column; gap: 14px; }

.hud-label {
  font-family: var(--display);
  font-size: 15px;
  letter-spacing: 0.34em;
  padding-left: 2px;
}
.label-pink {
  color: #ffd9ec;
  text-shadow: 0 0 6px var(--pink), 0 0 14px var(--pink), 2px 2px 0 var(--ink);
}
.label-white {
  color: #ffffff;
  text-shadow: 0 0 8px rgba(255,255,255,0.55), 2px 2px 0 var(--ink);
}

#timer {
  font-family: var(--display);
  font-size: clamp(44px, 4.6vw, 64px);
  line-height: 0.95;
  color: #eafffb;
  text-shadow:
    0 0 8px #17f2cf, 0 0 22px #17f2cf, 0 0 46px #0bbfae,
    3px 3px 0 var(--ink);
  transform: rotate(-1.5deg);
}
#timer.urgent {
  color: #ffecec;
  text-shadow: 0 0 8px #ff3b3b, 0 0 22px #ff3b3b, 0 0 46px #c40000, 3px 3px 0 var(--ink);
  animation: urgentPulse 0.5s steps(2, jump-none) infinite;
}
@keyframes urgentPulse { 50% { transform: rotate(-1.5deg) scale(1.06); } }

#coverRow { display: flex; align-items: center; gap: 12px; }
#coverPct {
  font-family: var(--display);
  font-size: clamp(30px, 3vw, 42px);
  color: #ffffff;
  text-shadow: 2px 2px 0 var(--ink), -2px 2px 0 var(--ink), 2px -2px 0 var(--ink), -2px -2px 0 var(--ink), 4px 5px 0 rgba(0,0,0,0.55);
  min-width: 3.2ch;
}
#coverBar {
  width: clamp(150px, 16vw, 240px);
  height: 16px;
  background: #ffffff;
  border: 3px solid var(--ink);
  border-radius: 9px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.4);
  overflow: hidden;
}
#coverFill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--blue), var(--purple), var(--pink));
  background-size: 300% 100%;
  animation: barShift 3s linear infinite;
  transition: width 0.25s ease-out;
}
@keyframes barShift { to { background-position: 300% 0; } }

#mapBlock {
  position: absolute; top: 20px; right: 22px;
  padding: 6px;
  background: #ffffff;
  border: 4px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 7px 0 rgba(0,0,0,0.4);
  transform: rotate(1.2deg);
}
#minimap { display: block; width: 222px; height: 166px; border-radius: 8px; }
.map-tag {
  position: absolute; top: -14px; left: 12px;
  font-family: var(--display);
  font-size: 13px; letter-spacing: 0.22em;
  background: var(--yellow);
  border: 3px solid var(--ink);
  border-radius: 8px;
  padding: 1px 8px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.4);
  transform: rotate(-2deg);
}

#hint {
  position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.92);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 7px 20px;
  font-weight: 700; font-size: 14px;
  box-shadow: 0 5px 0 rgba(0,0,0,0.35);
  transition: opacity 0.8s ease, transform 0.8s ease;
}
#hint.fade { opacity: 0; transform: translate(-50%, 14px); }
#hint .dot { opacity: 0.45; }

#muteBtn {
  position: absolute; bottom: 22px; right: 22px;
  pointer-events: auto; cursor: pointer;
  font-family: var(--display); font-size: 13px; letter-spacing: 0.18em;
  color: var(--ink); background: #ffffff;
  border: 3px solid var(--ink); border-radius: 10px;
  padding: 6px 12px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.4);
  transform: rotate(-1deg);
}
#muteBtn:active { transform: rotate(-1deg) translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.4); }

/* ---------- keys ---------- */

.key {
  display: inline-grid; place-items: center;
  min-width: 36px; height: 36px; padding: 0 8px;
  background: #ffffff; color: var(--ink);
  border: 3px solid var(--ink); border-radius: 9px;
  box-shadow: 0 3px 0 var(--ink);
  font-family: var(--body); font-weight: 800; font-size: 15px;
}
.key-sm { min-width: 26px; height: 26px; font-size: 12px; border-width: 2px; box-shadow: 0 2px 0 var(--ink); border-radius: 7px; }
.key-wide { padding: 0 16px; }
.key-auto { background: var(--yellow); font-family: var(--display); letter-spacing: 0.1em; font-size: 13px; }
.or { font-weight: 800; opacity: 0.5; }

/* ---------- popups ---------- */

#popups { position: absolute; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }

.popup {
  position: absolute; left: 50%; top: 33%;
  font-family: var(--display);
  font-size: clamp(46px, 6.4vw, 88px);
  line-height: 1;
  white-space: nowrap;
  color: var(--pc, var(--yellow));
  paint-order: stroke fill;
  -webkit-text-stroke: 9px var(--ink);
  text-shadow: 6px 7px 0 rgba(0,0,0,0.5);
  transform: translate(-50%, -50%) rotate(var(--pr, 0deg)) scale(0.1);
  animation: popIn 0.3s cubic-bezier(0.2, 1.6, 0.4, 1) forwards, popOut 0.35s ease-in 0.85s forwards;
}
.popup.big { font-size: clamp(70px, 10vw, 140px); -webkit-text-stroke: 12px var(--ink); }
.popup.small { font-size: clamp(28px, 3.6vw, 46px); -webkit-text-stroke: 6px var(--ink); top: 42%; }
@keyframes popIn {
  0% { transform: translate(-50%, -50%) rotate(var(--pr, 0deg)) scale(0.1); }
  60% { transform: translate(-50%, -50%) rotate(var(--pr, 0deg)) scale(1.22); }
  100% { transform: translate(-50%, -50%) rotate(var(--pr, 0deg)) scale(1); }
}
@keyframes popOut {
  to { opacity: 0; transform: translate(-50%, -80%) rotate(var(--pr, 0deg)) scale(0.9); }
}

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

.screen {
  position: absolute; inset: 0; z-index: 50;
  display: flex; flex-direction: column;
}
.screen[hidden] { display: none; }
#startScreen {
  justify-content: space-between;
  padding: clamp(20px, 4.5vh, 48px) clamp(22px, 4.5vw, 64px);
  background: linear-gradient(180deg, rgba(20,21,26,0.28) 0%, rgba(20,21,26,0) 26%, rgba(20,21,26,0) 52%, rgba(20,21,26,0.55) 100%);
}

#startGrid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  gap: clamp(18px, 3vw, 48px);
  align-items: start;
}

#titleBlock { line-height: 0.86; margin-bottom: 14px; }
.t-letter {
  display: inline-block;
  font-family: var(--display);
  font-size: clamp(64px, 9.5vw, 138px);
  color: var(--tc);
  paint-order: stroke fill;
  -webkit-text-stroke: 10px var(--ink);
  text-shadow: 7px 8px 0 rgba(0,0,0,0.45);
  transform: rotate(var(--tr));
  animation: letterDrop 0.55s cubic-bezier(0.2, 1.5, 0.4, 1) both;
  animation-delay: var(--td);
}
.t-small { font-size: clamp(46px, 6.6vw, 96px); }
@keyframes letterDrop {
  0% { opacity: 0; transform: rotate(var(--tr)) translateY(-90px) scale(0.4); }
  100% { opacity: 1; transform: rotate(var(--tr)) translateY(0) scale(1); }
}

#subtitle {
  display: inline-block;
  font-family: var(--display);
  font-size: clamp(16px, 1.9vw, 26px);
  letter-spacing: 0.3em;
  color: #ffffff;
  background: var(--ink);
  padding: 5px 16px 3px;
  border-radius: 8px;
  transform: rotate(-1.6deg);
  box-shadow: 4px 5px 0 rgba(0,0,0,0.4);
  animation: letterDrop 0.5s 0.5s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
#blurb {
  margin-top: 16px;
  font-size: clamp(14px, 1.4vw, 19px);
  font-weight: 700;
  color: #ffffff;
  text-shadow: 1px 2px 0 rgba(0,0,0,0.65);
  line-height: 1.45;
  animation: fadeUp 0.6s 0.65s ease both;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } }

.comic-panel {
  position: relative;
  background: #ffffff;
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: 9px 10px 0 rgba(0,0,0,0.45);
}
.dots::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: 14px;
  background-image: radial-gradient(rgba(20,21,26,0.075) 1.6px, transparent 1.7px);
  background-size: 13px 13px;
  pointer-events: none;
}

#controlsCard { padding: 18px 20px 14px; transform: rotate(1.1deg); animation: fadeUp 0.6s 0.45s ease both; }
.panel-title {
  font-family: var(--display);
  font-size: 22px; letter-spacing: 0.14em;
  color: var(--red);
  text-shadow: 2px 2px 0 rgba(20,21,26,0.15);
  margin-bottom: 12px;
  transform: rotate(-1deg);
}
.ctl-row { display: flex; align-items: center; gap: 12px; padding: 6px 0; }
.ctl-row .keys { display: inline-flex; align-items: center; gap: 5px; min-width: 158px; }
.ctl-row .keys.pad { min-width: 0; margin-left: 14px; }
.ctl-name { font-weight: 700; font-size: 15px; }
.ctl-row.small { margin-top: 6px; padding-top: 10px; border-top: 3px dashed rgba(20,21,26,0.18); }
.ctl-row.small .ctl-name { font-size: 13px; opacity: 0.85; }

#startBottom {
  display: flex; align-items: center; gap: 22px;
  padding-bottom: clamp(4px, 2vh, 18px);
  animation: fadeUp 0.6s 0.8s ease both;
}

.btn-comic {
  cursor: pointer;
  font-family: var(--display);
  font-size: clamp(24px, 2.6vw, 34px);
  letter-spacing: 0.06em;
  color: var(--ink);
  background: var(--yellow);
  border: 4px solid var(--ink);
  border-radius: 16px;
  padding: 10px 34px 7px;
  box-shadow: 0 7px 0 var(--ink);
  transform: rotate(-1.4deg);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  animation: btnPulse 1.6s ease-in-out infinite;
}
.btn-comic:hover { transform: rotate(-1.4deg) translateY(-3px) scale(1.03); box-shadow: 0 10px 0 var(--ink); background: #ffdd55; }
.btn-comic:active { transform: rotate(-1.4deg) translateY(3px); box-shadow: 0 2px 0 var(--ink); animation: none; }
@keyframes btnPulse { 50% { box-shadow: 0 7px 0 var(--ink), 0 0 0 7px rgba(255,210,31,0.28); } }

#dropHint { font-weight: 700; font-size: 15px; color: #fff; text-shadow: 1px 2px 0 rgba(0,0,0,0.65); display: flex; align-items: center; gap: 7px; }

/* ---------- end screen ---------- */

#endScreen {
  align-items: center; justify-content: center;
  background: rgba(20,21,26,0.46);
  backdrop-filter: blur(2px);
}
#endPanel {
  width: min(620px, 92vw);
  padding: 26px 34px 24px;
  text-align: center;
  transform: rotate(-0.8deg);
  animation: panelSlam 0.4s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
@keyframes panelSlam {
  0% { opacity: 0; transform: rotate(-0.8deg) scale(0.5) translateY(60px); }
  100% { opacity: 1; transform: rotate(-0.8deg) scale(1) translateY(0); }
}
#endTitle {
  font-family: var(--display);
  font-size: clamp(34px, 4.6vw, 52px);
  color: var(--red);
  paint-order: stroke fill;
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 3px 4px 0 rgba(20,21,26,0.2);
  transform: rotate(-1.4deg);
}
#endBigRow { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 8px 0 6px; position: relative; }
#endPct {
  font-family: var(--display);
  font-size: clamp(84px, 11vw, 128px);
  line-height: 0.9;
  color: var(--green);
  paint-order: stroke fill;
  -webkit-text-stroke: 9px var(--ink);
  text-shadow: 6px 7px 0 rgba(0,0,0,0.35);
}
#endPct small { font-size: 0.45em; }
#endPctLabel {
  font-family: var(--display);
  font-size: 17px; letter-spacing: 0.22em; line-height: 1.35;
  text-align: left; opacity: 0.75;
}
#gradeStamp {
  position: absolute; right: -6px; top: -18px;
  width: 88px; height: 88px;
  display: grid; place-items: center;
  font-family: var(--display); font-size: 56px;
  color: var(--grade, var(--green));
  border: 6px solid currentColor;
  border-radius: 50%;
  transform: rotate(12deg);
  opacity: 0.92;
  animation: stampHit 0.3s 0.55s cubic-bezier(0.3, 2, 0.4, 1) both;
}
@keyframes stampHit { 0% { transform: rotate(12deg) scale(2.4); opacity: 0; } 100% { transform: rotate(12deg) scale(1); opacity: 0.92; } }

#endStats { display: flex; justify-content: center; gap: 12px; margin: 14px 0 18px; flex-wrap: wrap; }
.stat {
  min-width: 108px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 8px 12px 6px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.25);
}
.stat:nth-child(1) { transform: rotate(-1.4deg); }
.stat:nth-child(2) { transform: rotate(1deg); }
.stat:nth-child(3) { transform: rotate(-0.8deg); }
.stat:nth-child(4) { transform: rotate(1.4deg); }
.stat-v { font-family: var(--display); font-size: 27px; }
.stat-k { font-size: 11px; font-weight: 800; letter-spacing: 0.18em; opacity: 0.6; }

#endActions { display: flex; align-items: center; justify-content: center; gap: 18px; }
#againHint { font-weight: 700; font-size: 14px; opacity: 0.7; display: flex; align-items: center; gap: 6px; }

#nogl { position: absolute; inset: 0; z-index: 60; display: grid; place-items: center; background: var(--paper); }
#nogl[hidden] { display: none; }
#nogl .comic-panel { padding: 26px 34px; font-weight: 700; font-size: 18px; }

@media (max-width: 860px) {
  #startGrid { grid-template-columns: 1fr; }
  #controlsCard { transform: none; }
  #minimap { width: 168px; height: 126px; }
}
