:root {
  color-scheme: dark;
  --ink: #24160f;
  --cream: #fff6e8;
  --gold: #f0b429;
  --night: #100e18;
  --plum: #6b3d8f;
  --mist: #f3d7b0;
  --panel: rgba(255, 248, 236, 0.97);
  --font-display: "Fraunces", Georgia, "Palatino Linotype", serif;
  --font-ui: "Nunito", "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--night);
  color: var(--cream);
  font-family: var(--font-ui);
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
  overscroll-behavior: none;
}

button,
a {
  font: inherit;
}

button {
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd56a, var(--gold) 55%, #d99412);
  color: var(--ink);
  font-weight: 800;
  padding: 0.75em 1.25em;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  transition: transform 0.12s ease, filter 0.12s ease;
}

button:hover {
  filter: brightness(1.04);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  filter: grayscale(0.35);
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.turn {
  display: none;
  position: fixed;
  top: 8px;
  left: 12px;
  right: 12px;
  z-index: 8;
  margin: 0;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  text-shadow: 0 2px 8px #000;
  pointer-events: none;
}

#stage {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  background: #141226;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  container-type: size;
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(255, 246, 232, 0.08), 0 24px 60px rgba(0, 0, 0, 0.45);
}

body.immersive {
  background: #000;
}

body.immersive #stage {
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  border-radius: 0;
  box-shadow: none;
}

body.immersive .turn {
  display: none;
}

#stage:fullscreen,
#stage:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  border-radius: 0;
  box-shadow: none;
}

#game {
  width: 100%;
  height: 100%;
  display: block;
}

.corner {
  position: absolute;
  z-index: 3;
  top: 12px;
  padding: 0.45em 0.85em;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: rgba(255, 246, 232, 0.94);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

#pause {
  left: 12px;
}

#mute {
  right: 12px;
}

button#pause[hidden],
button#mute[hidden],
button#purr[hidden] {
  display: none;
}

#purr {
  position: absolute;
  z-index: 3;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 96px;
  padding: 0;
  line-height: 1.05;
  color: #2a1240;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  background: radial-gradient(circle at 40% 35%, #fff4c4, #f0a43a 52%, #c86ad4);
}

.purr-word {
  font-size: 22px;
}

.purr-sub {
  font-size: 12px;
  font-weight: 800;
  opacity: 0.9;
}

#purr.low {
  filter: grayscale(0.45) brightness(0.85);
}

#purr.hint {
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  50% { transform: scale(1.07); }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow: auto;
}

.overlay[hidden] {
  display: none;
}

#title {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  pointer-events: none;
}

#title[hidden],
#upgrade[hidden],
#pause-screen[hidden],
#end[hidden] {
  display: none;
}

#title button,
#title .sheet {
  pointer-events: auto;
}

h1 {
  margin: 0 0 0.12em;
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 0.84;
  letter-spacing: -0.03em;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
}

h1 .cat,
h1 .magic {
  display: block;
  font-size: clamp(56px, 12cqi, 112px);
}

h1 .cat {
  color: #ffb15a;
}

h1 .magic {
  color: #e4c6ff;
}

.sheet {
  padding: 3.2em 7% 1.1em;
  text-align: center;
  background: linear-gradient(180deg, transparent, rgba(10, 8, 18, 0.42) 16%, rgba(10, 8, 18, 0.9) 42%);
}

.save,
.before,
.best,
.how,
.kicker {
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

.save {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(18px, 3.5cqi, 30px);
}

.before {
  margin: 0.15em 0 0.7em;
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(15px, 2.6cqi, 22px);
  color: var(--mist);
}

.how {
  list-style: none;
  max-width: 38em;
  margin: 0.75em auto 0;
  padding: 0;
  font-size: clamp(13px, 2.1cqi, 16px);
  line-height: 1.4;
  font-weight: 700;
}

.how li + li {
  margin-top: 0.2em;
}

.best {
  margin: 0.55em 0 0;
  font-size: 14px;
  font-weight: 700;
  color: #ffe7b0;
}

.title-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
}

#title button.ghost.title-continue {
  background: rgba(255, 246, 232, 0.14);
  color: var(--cream);
  box-shadow: inset 0 0 0 2px rgba(255, 246, 232, 0.45);
}

#title button.ghost.title-continue[hidden] {
  display: none;
}

#pause-screen,
#upgrade,
#end {
  display: grid;
  place-items: center;
  padding: 16px;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(200, 106, 212, 0.14), transparent 55%),
    rgba(8, 6, 16, 0.58);
  backdrop-filter: blur(2px);
}

.panel {
  width: min(100%, 460px);
  padding: 1.2em 1.25em 1.1em;
  border-radius: 22px;
  background: var(--panel);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.panel h2 {
  margin: 0.1em 0;
  font-family: var(--font-display);
  font-size: clamp(26px, 4cqi, 36px);
  line-height: 1.1;
}

.panel p {
  margin: 0.4em 0;
  font-weight: 700;
}

.panel .best {
  text-shadow: none;
  color: var(--ink);
}

.kicker {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #8a4b16;
  text-shadow: none;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 0.9em;
}

.panel.wide {
  width: min(100%, 760px);
}

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 0.75em 0 0.35em;
}

.stat-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 5.5em;
  padding: 0.45em 0.7em;
  border-radius: 12px;
  background: rgba(36, 22, 15, 0.06);
  box-shadow: inset 0 0 0 1px rgba(36, 22, 15, 0.08);
}

.stat-chip strong {
  font-family: var(--font-display);
  font-size: 18px;
  line-height: 1.1;
}

.stat-chip span {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #7a5a42;
}

.next-night {
  margin: 0.35em 0 0.15em !important;
  font-size: 14px;
  color: #5a4638;
}

.owned-powers {
  margin: 0.35em 0 0.15em !important;
  font-size: 13px;
  color: #5a4638;
  min-height: 1.2em;
}

.upgrade-picks {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 0.85em;
}

.upgrade-picks button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.28em;
  width: 100%;
  min-height: 9.5em;
  padding: 0.9em 0.95em;
  border-radius: 16px;
  text-align: left;
  background: linear-gradient(180deg, #fffdf8, #fff1dc);
  color: var(--ink);
  box-shadow: inset 0 0 0 2px rgba(36, 22, 15, 0.1);
}

.upgrade-picks button:hover,
.upgrade-picks button:focus-visible {
  box-shadow: inset 0 0 0 2px #c86ad4, 0 10px 22px rgba(0, 0, 0, 0.12);
  filter: none;
}

.upgrade-picks .up-top {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 0.4em;
}

.upgrade-picks .up-tag {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7a3f9a;
  background: rgba(200, 106, 212, 0.16);
  padding: 0.2em 0.5em;
  border-radius: 999px;
}

.upgrade-picks .up-stack {
  font-size: 11px;
  font-weight: 800;
  color: #8a4b16;
}

.upgrade-picks .up-name {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
}

.upgrade-picks .up-desc {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  color: #5a4638;
}

.upgrade-picks .up-delta {
  margin-top: auto;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  color: #2f6b45;
  background: rgba(74, 150, 96, 0.12);
  border-radius: 8px;
  padding: 0.4em 0.5em;
  width: 100%;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0.85em 0 0.35em;
  text-align: left;
}

.controls-grid div {
  display: flex;
  flex-direction: column;
  gap: 0.15em;
  padding: 0.55em 0.7em;
  border-radius: 12px;
  background: rgba(36, 22, 15, 0.06);
}

.controls-grid strong {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8a4b16;
}

.controls-grid span {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

button.ghost {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 2px rgba(36, 22, 15, 0.35);
}

@media (max-width: 700px) {
  .upgrade-picks,
  .controls-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  #purr.hint,
  button {
    animation: none;
    transition: none;
  }
}

@media (max-height: 520px) {
  h1 .cat,
  h1 .magic {
    font-size: 48px;
  }

  .how {
    display: none;
  }

  .sheet {
    padding-top: 1em;
  }
}

@media (orientation: portrait) and (max-width: 900px) {
  .turn {
    display: block;
  }

  .how {
    display: none;
  }

  h1 .cat,
  h1 .magic {
    font-size: 44px;
  }

  .before {
    font-size: 14px;
  }
}
