:root {
  --bg: #110f15;
  --panel: #1b1720;
  --panel-2: #251d2b;
  --cream: #fff6df;
  --muted: #c9bdc8;
  --acid: #d8ff57;
  --hot: #ff5d73;
  --hot-2: #ff9b54;
  --purple: #9e77ff;
  --line: rgba(255, 246, 223, 0.14);
  --shadow: 0 28px 70px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(158, 119, 255, 0.16), transparent 35%),
    radial-gradient(circle at 90% 15%, rgba(255, 93, 115, 0.12), transparent 30%),
    var(--bg);
  color: var(--cream);
  font-family: Arial, Helvetica, sans-serif;
  overflow-x: hidden;
}

button { font: inherit; }

button:focus-visible,
[role="button"]:focus-visible {
  outline: 3px solid var(--acid);
  outline-offset: 4px;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
  display: flex;
  justify-content: center;
}

.game-card {
  width: min(1120px, 100%);
}

.topbar,
.hud,
.leaderboard-card {
  background: rgba(27, 23, 32, 0.92);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  border-radius: 24px 24px 0 0;
  border-bottom: 0;
  padding: 20px 22px 16px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--acid);
  font-weight: 900;
  letter-spacing: .14em;
  font-size: .72rem;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 4vw, 3rem);
  line-height: .92;
  letter-spacing: -.055em;
  font-weight: 1000;
}

.icon-button,
.dialog-close {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--cream);
  width: 44px;
  height: 44px;
  border-radius: 14px;
  font-size: 1.2rem;
  font-weight: 900;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}

.icon-button:hover,
.dialog-close:hover { transform: translateY(-2px); background: #30253a; }

.hud {
  border-bottom: 0;
  padding: 12px 18px;
  display: grid;
  grid-template-columns: 130px 100px 1fr;
  gap: 14px;
  align-items: center;
}

.hud-block {
  border-right: 1px solid var(--line);
  min-height: 54px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.hud-label,
.rage-heading,
.final-score-box span {
  color: var(--muted);
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .13em;
}

.hud-block strong {
  font-size: 1.7rem;
  line-height: 1;
}

.rage-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 8px;
}

.rage-heading strong { color: var(--cream); }

.rage-track {
  height: 15px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 999px;
  background: #0d0b10;
}

.rage-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--acid), var(--hot-2), var(--hot));
  transition: width .2s ease;
}

.playfield {
  position: relative;
  min-height: 610px;
  height: min(69vh, 720px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0 0 24px 24px;
  background:
    linear-gradient(rgba(255,255,255,.025), rgba(255,255,255,.01)),
    radial-gradient(circle at 50% 86%, rgba(216,255,87,.09), transparent 30%),
    #151119;
  box-shadow: var(--shadow);
  isolation: isolate;
}

.ambient-grid {
  position: absolute;
  inset: 0;
  opacity: .25;
  background-image:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.8), transparent 92%);
  z-index: -1;
}

.reaction-bubble {
  position: absolute;
  left: 50%;
  bottom: 250px;
  transform: translateX(-50%) scale(.94);
  min-width: 150px;
  max-width: min(74vw, 430px);
  padding: 12px 16px;
  text-align: center;
  background: var(--cream);
  color: #171219;
  border: 3px solid #171219;
  border-radius: 16px 16px 16px 4px;
  box-shadow: 6px 7px 0 #171219;
  font-weight: 1000;
  font-size: clamp(.92rem, 2.2vw, 1.15rem);
  opacity: 0;
  pointer-events: none;
  z-index: 16;
  transition: opacity .12s ease, transform .12s ease;
}

.reaction-bubble.show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.cat {
  --fur: #c98658;
  --fur-dark: #8f5739;
  position: absolute;
  width: 230px;
  height: 235px;
  left: 50%;
  bottom: 55px;
  transform: translateX(-50%);
  z-index: 10;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: filter .18s ease;
}

.cat-head {
  position: absolute;
  width: 170px;
  height: 140px;
  left: 30px;
  top: 8px;
  background: var(--fur);
  border: 6px solid #171219;
  border-radius: 48% 48% 45% 45%;
  box-shadow: inset 0 -11px 0 rgba(80, 38, 22, .12);
  z-index: 4;
}

.cat-ear {
  position: absolute;
  top: 0;
  width: 74px;
  height: 74px;
  background: var(--fur);
  border: 6px solid #171219;
  z-index: 1;
}

.cat-ear::after {
  content: "";
  position: absolute;
  inset: 17px;
  background: #df8b7e;
  border: 3px solid #171219;
}

.ear-left { left: 28px; transform: rotate(45deg); border-radius: 18px 8px 14px 8px; }
.ear-right { right: 28px; transform: rotate(45deg); border-radius: 18px 8px 14px 8px; }

.cat-body {
  position: absolute;
  width: 190px;
  height: 122px;
  left: 20px;
  bottom: 0;
  background: var(--fur);
  border: 6px solid #171219;
  border-radius: 48% 48% 34% 34%;
  z-index: 2;
}

.cat-paw {
  position: absolute;
  width: 58px;
  height: 48px;
  bottom: -10px;
  background: #e0a477;
  border: 5px solid #171219;
  border-radius: 50%;
}

.paw-left { left: 20px; transform: rotate(-5deg); }
.paw-right { right: 20px; transform: rotate(5deg); }

.cat-tail {
  position: absolute;
  width: 125px;
  height: 45px;
  right: -56px;
  bottom: 31px;
  border: 18px solid var(--fur);
  border-left: 0;
  border-bottom-color: transparent;
  border-radius: 0 70px 0 0;
  transform: rotate(12deg);
  transform-origin: left center;
  z-index: 1;
}

.cat-brow {
  position: absolute;
  top: 31px;
  width: 39px;
  height: 6px;
  background: #171219;
  border-radius: 999px;
  opacity: 0;
  z-index: 2;
  transition: transform .2s ease, top .2s ease, opacity .2s ease;
}

.brow-left { left: 28px; transform: rotate(-2deg); }
.brow-right { right: 28px; transform: rotate(2deg); }

.cat-eye {
  position: absolute;
  top: 43px;
  width: 35px;
  height: 28px;
  background: #f4df74;
  border: 4px solid #171219;
  border-radius: 50%;
  overflow: hidden;
  transition: height .2s ease, top .2s ease, background .2s ease, box-shadow .2s ease, transform .2s ease;
}

.cat-eye span {
  position: absolute;
  width: 7px;
  height: 22px;
  left: 10px;
  top: 0;
  border-radius: 50%;
  background: #171219;
  transition: width .18s ease, height .18s ease, left .18s ease, top .18s ease, background .18s ease;
}

.eye-left { left: 31px; transform: rotate(5deg); }
.eye-right { right: 31px; transform: rotate(-5deg); }

.cat-nose {
  position: absolute;
  left: 72px;
  top: 78px;
  width: 18px;
  height: 13px;
  background: #4c2f34;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.cat-mouth {
  position: absolute;
  width: 35px;
  height: 17px;
  left: 64px;
  top: 94px;
  border-bottom: 5px solid #171219;
  border-radius: 0 0 50% 50%;
  transition: width .2s ease, height .2s ease, left .2s ease, top .2s ease, border .2s ease, border-radius .2s ease, background .2s ease;
}

.cat-mouth::before,
.cat-mouth::after {
  content: "";
  position: absolute;
  opacity: 0;
  transition: opacity .18s ease;
}

.cat-whisker {
  position: absolute;
  width: 51px;
  height: 3px;
  background: #171219;
  top: 96px;
}

.whisker-l1 { left: -29px; transform: rotate(8deg); }
.whisker-l2 { left: -27px; top: 111px; transform: rotate(-7deg); }
.whisker-r1 { right: -29px; transform: rotate(-8deg); }
.whisker-r2 { right: -27px; top: 111px; transform: rotate(7deg); }

/* Version 2 mood progression: the cat gets visibly more expressive as rage rises. */
.cat-calm .cat-head { animation: calm-bob 2.8s ease-in-out infinite; }
.cat-calm .cat-eye span { animation: cat-blink 4.2s ease-in-out infinite; }

.cat-annoyed .cat-ear { top: 8px; }
.cat-annoyed .ear-left { transform: rotate(33deg); }
.cat-annoyed .ear-right { transform: rotate(57deg); }
.cat-annoyed .cat-brow { opacity: 1; top: 35px; }
.cat-annoyed .brow-left { transform: rotate(12deg); }
.cat-annoyed .brow-right { transform: rotate(-12deg); }
.cat-annoyed .cat-eye { height: 22px; top: 47px; }
.cat-annoyed .cat-eye span { height: 18px; top: -1px; }
.cat-annoyed .cat-mouth {
  width: 34px; height: 8px; left: 65px; top: 101px;
  border: 0; border-top: 5px solid #171219; border-radius: 50% 50% 0 0;
}
.cat-annoyed .cat-tail { animation: tail-snap .52s ease-in-out infinite alternate; }

.cat-angry .cat-ear { top: 18px; }
.cat-angry .ear-left { transform: rotate(23deg); }
.cat-angry .ear-right { transform: rotate(67deg); }
.cat-angry .cat-brow { opacity: 1; top: 34px; }
.cat-angry .brow-left { transform: rotate(22deg); }
.cat-angry .brow-right { transform: rotate(-22deg); }
.cat-angry .cat-eye { height: 20px; top: 48px; background: #ffc34d; }
.cat-angry .cat-eye span { width: 15px; height: 18px; left: 7px; background: #8e0c24; }
.cat-angry .cat-mouth {
  width: 42px; height: 14px; left: 61px; top: 101px;
  border: 0; border-top: 6px solid #171219; border-radius: 50% 50% 0 0;
}
.cat-angry .cat-tail { animation: tail-snap .25s ease-in-out infinite alternate; }
.cat-angry .cat-head { animation: angry-breathe .55s ease-in-out infinite alternate; }

.cat-furious { filter: drop-shadow(0 0 15px rgba(255,93,115,.48)); animation: cat-rattle .12s linear infinite; }
.cat-furious .cat-ear { top: 30px; }
.cat-furious .ear-left { transform: rotate(12deg); }
.cat-furious .ear-right { transform: rotate(78deg); }
.cat-furious .cat-brow { opacity: 1; top: 31px; height: 7px; }
.cat-furious .brow-left { transform: rotate(30deg); }
.cat-furious .brow-right { transform: rotate(-30deg); }
.cat-furious .cat-eye {
  height: 22px; top: 47px; background: #ff5d73;
  box-shadow: 0 0 13px rgba(255,93,115,.9), inset 0 0 8px rgba(255,255,255,.55);
}
.cat-furious .cat-eye span { width: 18px; height: 18px; left: 6px; top: 0; background: #5b0614; }
.cat-furious .cat-mouth {
  width: 45px; height: 27px; left: 59px; top: 91px;
  border: 5px solid #171219; border-radius: 45% 45% 55% 55%; background: #5b1520;
}
.cat-furious .cat-mouth::before {
  opacity: 1; width: 9px; height: 8px; left: 5px; top: -1px;
  background: #fff6df; clip-path: polygon(0 0,100% 0,50% 100%);
  box-shadow: 21px 0 0 #fff6df;
}
.cat-furious .cat-head::before,
.cat-furious .cat-head::after {
  content: ""; position: absolute; width: 24px; height: 24px; top: -15px;
  border: 5px solid rgba(255,246,223,.75); border-bottom-color: transparent; border-left-color: transparent;
  border-radius: 50%; opacity: .8; animation: steam-pop .7s ease-out infinite;
}
.cat-furious .cat-head::before { left: 13px; transform: rotate(-35deg); }
.cat-furious .cat-head::after { right: 13px; transform: rotate(35deg); animation-delay: .25s; }
.cat-furious .cat-tail { animation: tail-snap .13s ease-in-out infinite alternate; }


@keyframes calm-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(2px); }
}

@keyframes cat-blink {
  0%, 44%, 48%, 100% { transform: scaleY(1); }
  46% { transform: scaleY(.12); }
}

@keyframes angry-breathe {
  from { transform: translateY(0) scale(1); }
  to { transform: translateY(-2px) scale(1.018); }
}

@keyframes steam-pop {
  0% { opacity: 0; transform: translateY(8px) scale(.55) rotate(0deg); }
  35% { opacity: .9; }
  100% { opacity: 0; transform: translateY(-18px) scale(1.15) rotate(25deg); }
}

@keyframes tail-snap {
  from { transform: rotate(-8deg); }
  to { transform: rotate(26deg); }
}

@keyframes cat-rattle {
  0%,100% { transform: translateX(-50%) translate(0,0); }
  25% { transform: translateX(-50%) translate(2px,-1px); }
  50% { transform: translateX(-50%) translate(-2px,1px); }
  75% { transform: translateX(-50%) translate(1px,1px); }
}

.cat.bump .cat-head { animation: head-bump .2s ease; }
@keyframes head-bump {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px) scale(1.03); }
}

.bowl {
  position: absolute;
  width: 230px;
  height: 72px;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  border-radius: 14px 14px 55px 55px;
  border: 6px solid #171219;
  background: var(--purple);
  box-shadow: inset 0 -14px 0 rgba(0,0,0,.15), 0 12px 30px rgba(0,0,0,.25);
  z-index: 12;
  display: grid;
  place-items: center;
  text-align: center;
  font-weight: 1000;
  line-height: .9;
  color: #171219;
}

.bowl small { font-size: .64rem; }

.cat-warning {
  position: absolute;
  bottom: 4px;
  left: 18px;
  margin: 0;
  color: rgba(255,246,223,.52);
  font-size: .66rem;
  font-weight: 900;
  letter-spacing: .12em;
  z-index: 18;
}

.falling-item {
  position: absolute;
  top: -100px;
  width: 90px;
  min-height: 78px;
  padding: 8px 6px 9px;
  border: 4px solid #171219;
  border-radius: 18px;
  background: #fff6df;
  color: #171219;
  box-shadow: 6px 7px 0 #171219;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  z-index: 8;
  text-align: center;
  transform: translateX(-50%);
  animation-name: fall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

.falling-item .item-icon {
  display: block;
  font-size: 2rem;
  line-height: 1;
  margin-bottom: 4px;
}

.falling-item .item-label {
  display: block;
  font-size: .68rem;
  font-weight: 1000;
  line-height: 1;
  letter-spacing: .02em;
}

.falling-item:hover { filter: brightness(1.05); }
.falling-item.good { background: #efffc1; }
.falling-item.bad { background: #ffd6dc; }
.falling-item.hit { animation: item-pop .2s ease forwards !important; pointer-events: none; }

@keyframes fall {
  from { top: -100px; transform: translateX(-50%) rotate(-4deg); }
  to { top: calc(100% - 120px); transform: translateX(-50%) rotate(7deg); }
}

@keyframes item-pop {
  to { transform: translateX(-50%) scale(1.35) rotate(8deg); opacity: 0; }
}

.score-pop {
  position: absolute;
  z-index: 20;
  color: var(--acid);
  font-weight: 1000;
  font-size: 1.15rem;
  pointer-events: none;
  text-shadow: 2px 2px 0 #171219;
  animation: score-float .65s ease forwards;
}

.score-pop.bad-pop { color: var(--hot); }

@keyframes score-float {
  from { opacity: 1; transform: translate(-50%, 0) scale(.9); }
  to { opacity: 0; transform: translate(-50%, -55px) scale(1.2); }
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 22px;
  background: rgba(11, 9, 13, .78);
  backdrop-filter: blur(7px);
  z-index: 50;
}

.overlay.active { display: grid; }

.overlay-panel {
  width: min(560px, 100%);
  max-height: 92%;
  overflow-y: auto;
  padding: clamp(22px, 4vw, 36px);
  background: #201925;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 24px;
  box-shadow: 0 32px 90px rgba(0,0,0,.56);
  text-align: center;
}

.overlay-panel h2 {
  margin: 13px 0 13px;
  font-size: clamp(2rem, 6vw, 3.7rem);
  line-height: .92;
  letter-spacing: -.055em;
}

.overlay-panel > p:not(.tiny-copy) {
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 18px;
}

.status-pill {
  display: inline-flex;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--acid);
  color: #171219;
  font-size: .66rem;
  font-weight: 1000;
  letter-spacing: .1em;
}

.status-pill.danger { background: var(--hot); color: white; }

.mini-rule-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 20px 0;
  text-align: left;
}

.mini-rule-grid > div {
  padding: 13px;
  border-radius: 15px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 9px;
  align-items: center;
}

.mini-rule-grid small {
  grid-column: 2;
  color: var(--muted);
  line-height: 1.35;
  margin-top: 2px;
}

.mini-icon {
  grid-row: span 2;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--cream);
  color: #171219;
  display: grid;
  place-items: center;
  font-weight: 1000;
}

.primary-button {
  width: min(320px, 100%);
  border: 0;
  border-radius: 15px;
  padding: 15px 18px;
  background: var(--acid);
  color: #171219;
  box-shadow: 0 7px 0 #879f35;
  font-weight: 1000;
  letter-spacing: .05em;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}

.primary-button:hover { transform: translateY(-2px); box-shadow: 0 9px 0 #879f35; }
.primary-button:active { transform: translateY(5px); box-shadow: 0 2px 0 #879f35; }

.tiny-copy {
  margin: 17px 0 0;
  color: rgba(255,246,223,.56);
  font-size: .75rem;
}

.final-score-box {
  width: min(260px, 100%);
  margin: 22px auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.04);
}

.final-score-box strong {
  display: block;
  margin-top: 5px;
  font-size: 3rem;
  line-height: 1;
}

.leaderboard-card {
  margin-top: 18px;
  padding: 20px;
  border-radius: 22px;
}

.leaderboard-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 14px;
}

.leaderboard-heading h2 { margin: 0; font-size: 1.4rem; }
.leaderboard-note { color: var(--muted); font-size: .78rem; }

#mis-leaderboard:empty::before {
  content: "Leaderboard will appear here when MIS Helper is available.";
  display: block;
  color: rgba(255,246,223,.5);
  padding: 13px 0 2px;
  font-size: .78rem;
}

.how-dialog {
  width: min(560px, calc(100% - 28px));
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 24px;
  padding: 28px;
  background: #201925;
  color: var(--cream);
  box-shadow: 0 30px 100px rgba(0,0,0,.65);
}

.how-dialog::backdrop { background: rgba(9,7,11,.82); backdrop-filter: blur(4px); }
.how-dialog h2 { font-size: 2.3rem; line-height: .95; letter-spacing: -.04em; margin-bottom: 18px; }
.how-dialog ol { margin: 0; padding-left: 22px; color: var(--muted); line-height: 1.55; }
.how-dialog li + li { margin-top: 9px; }
.how-dialog strong { color: var(--cream); }
.dialog-close { position: absolute; top: 14px; right: 14px; }
.dialog-footnote { margin: 20px 0 0; color: rgba(255,246,223,.55); font-size: .82rem; }

.screen-shake { animation: screen-shake .28s linear; }
@keyframes screen-shake {
  0%,100% { transform: translate(0,0); }
  20% { transform: translate(-6px, 2px); }
  40% { transform: translate(5px, -3px); }
  60% { transform: translate(-4px, -2px); }
  80% { transform: translate(4px, 3px); }
}

@media (max-width: 700px) {
  .app-shell { padding: 10px; }
  .topbar { padding: 16px; }
  .hud { grid-template-columns: 1fr 1fr; gap: 10px; }
  .hud-block { border-right: 0; border-bottom: 1px solid var(--line); padding-bottom: 8px; min-height: 48px; }
  .hud-center { text-align: right; align-items: flex-end; }
  .rage-block { grid-column: 1 / -1; }
  .playfield { height: 66vh; min-height: 530px; }
  .cat { transform: translateX(-50%) scale(.86); transform-origin: bottom center; bottom: 51px; }
  .cat-furious { animation: cat-rattle-mobile .12s linear infinite; }
  @keyframes cat-rattle-mobile {
    0%,100% { transform: translateX(-50%) scale(.86) translate(0,0); }
    50% { transform: translateX(-50%) scale(.86) translate(2px,-1px); }
  }
  .bowl { width: 205px; }
  .falling-item { width: 77px; min-height: 70px; }
  .falling-item .item-icon { font-size: 1.65rem; }
  .falling-item .item-label { font-size: .6rem; }
  .reaction-bubble { bottom: 235px; }
  .mini-rule-grid { grid-template-columns: 1fr; }
  .leaderboard-heading { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
