:root {
  color-scheme: light;
  --ink: #171511;
  --muted: #6f675d;
  --paper: #fff7eb;
  --panel: #fffdf8;
  --line: #e0d0b8;
  --amber: #f5a623;
  --gold: #ffd166;
  --foam: #fff4d2;
  --rose: #e85d75;
  --teal: #1b998b;
  --green: #6a994e;
  --night: #292f36;
  --shadow: 0 18px 45px rgba(41, 47, 54, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: ui-rounded, "Avenir Next", Avenir, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(27, 153, 139, 0.13), transparent 38%),
    linear-gradient(215deg, rgba(232, 93, 117, 0.13), transparent 44%),
    var(--paper);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1040px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 32px;
}

.topbar,
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  padding: 8px 2px 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2.1rem, 8vw, 5.1rem);
  line-height: 0.88;
}

h2 {
  font-size: clamp(1.35rem, 4vw, 2rem);
}

.score-pill,
.phase {
  border: 2px solid var(--ink);
  border-radius: 999px;
  box-shadow: 4px 4px 0 var(--ink);
  background: var(--gold);
  color: var(--ink);
  font-weight: 900;
  white-space: nowrap;
}

.score-pill {
  display: grid;
  place-items: center;
  min-width: 100px;
  min-height: 72px;
  padding: 10px 16px;
  text-transform: uppercase;
}

.score-pill span:first-child {
  font-size: 2.15rem;
  line-height: 0.92;
}

.score-pill span:last-child {
  font-size: 0.76rem;
}

.portrait-stage {
  position: relative;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 8px;
  min-height: 360px;
  padding: 24px 18px 18px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.2) 0 12px, transparent 12px 28px),
    linear-gradient(160deg, #ffe2a7, #f6bb53 46%, #e85d75 100%);
  box-shadow: var(--shadow), 7px 7px 0 var(--ink);
}

.stage-lights {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 8%, rgba(255, 255, 255, 0.7), transparent 22%),
    radial-gradient(circle at 80% 4%, rgba(255, 255, 255, 0.45), transparent 18%);
  pointer-events: none;
}

.crew {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
  gap: clamp(8px, 2vw, 18px);
  min-height: 288px;
  filter: saturate(var(--sat, 1)) contrast(var(--contrast, 1)) blur(var(--blur, 0px));
  transform: rotate(var(--tilt, 0deg)) scale(var(--scale, 1));
  transition: transform 260ms ease, filter 260ms ease;
}

.person {
  position: relative;
  display: grid;
  justify-items: center;
  align-items: end;
  min-width: 0;
  transform: translateY(var(--bob, 0px)) rotate(var(--spin, 0deg));
  transition: transform 260ms ease;
}

.portrait-card {
  position: relative;
  width: min(100%, 270px);
  aspect-ratio: 0.82;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #fff9ee;
  box-shadow: 5px 5px 0 rgba(23, 21, 17, 0.84);
  overflow: hidden;
}

.portrait-card img,
.fallback-face,
.wreckage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.portrait-card img {
  object-fit: cover;
  object-position: 50% 12%;
  transition: opacity 260ms ease, filter 260ms ease, transform 260ms ease;
}

.portrait-normal {
  opacity: calc(1 - var(--wrecked, 0) * 0.72);
  filter: saturate(calc(1 + var(--wrecked, 0) * 0.25));
}

.portrait-wrecked {
  opacity: var(--wrecked, 0);
  filter: saturate(1.35) contrast(1.12);
  transform: scale(calc(1 + var(--wrecked, 0) * 0.04)) rotate(calc(var(--wrecked, 0) * -2deg));
}

.person img.is-missing {
  display: none;
}

.fallback-face {
  display: grid;
  place-items: center;
  font-size: clamp(4rem, 14vw, 9rem);
  font-weight: 950;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 36%, #ffe0bd 0 22%, transparent 23%),
    linear-gradient(180deg, #fff4dd 0 52%, #292f36 53% 100%);
}

.fallback-normal {
  opacity: 0;
}

.portrait-normal.is-missing ~ .fallback-normal {
  opacity: calc(1 - var(--wrecked, 0) * 0.82);
}

.fallback-wrecked {
  opacity: 0;
  color: #fff7eb;
  text-shadow: 3px 3px 0 #c4344d, -3px -2px 0 #1b998b;
  transform: rotate(calc(var(--wrecked, 0) * 7deg)) scale(calc(1 + var(--wrecked, 0) * 0.08));
  background:
    radial-gradient(circle at 37% 33%, #171511 0 4%, transparent 5%),
    radial-gradient(circle at 62% 34%, #171511 0 4%, transparent 5%),
    linear-gradient(180deg, #ffd166 0 24%, #ffe0bd 25% 54%, #292f36 55% 100%);
  transition: opacity 260ms ease, transform 260ms ease;
}

.portrait-wrecked.is-missing ~ .fallback-wrecked {
  opacity: calc(var(--wrecked, 0) * 0.95);
}

.wreckage {
  opacity: calc(var(--wrecked, 0) * 0.9);
  background:
    radial-gradient(circle at 18% 19%, rgba(255, 255, 255, 0.9) 0 4px, transparent 5px),
    radial-gradient(circle at 79% 25%, rgba(23, 21, 17, 0.9) 0 3px, transparent 4px),
    radial-gradient(circle at 28% 75%, rgba(232, 93, 117, 0.9) 0 7px, transparent 8px),
    linear-gradient(100deg, transparent 0 44%, rgba(255, 255, 255, 0.48) 45% 48%, transparent 49% 100%);
  mix-blend-mode: multiply;
  pointer-events: none;
}

.wreckage::before,
.wreckage::after {
  position: absolute;
  inset: auto;
  padding: 4px 7px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #fffdf8;
  box-shadow: 2px 2px 0 var(--ink);
  color: #c4344d;
  font-size: clamp(0.66rem, 1.8vw, 0.9rem);
  font-weight: 950;
}

.wreckage::before {
  content: "hik";
  top: 9px;
  right: 8px;
  transform: rotate(9deg);
}

.wreckage::after {
  content: "?!";
  left: 10px;
  bottom: 48px;
  transform: rotate(-12deg);
}

.person span {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  min-width: 78px;
  padding: 6px 10px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--panel);
  box-shadow: 3px 3px 0 var(--ink);
  font-weight: 900;
  text-align: center;
}

.chaos-caption {
  position: relative;
  z-index: 1;
  width: fit-content;
  max-width: 100%;
  margin: 18px auto 0;
  padding: 10px 14px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: 4px 4px 0 var(--ink);
  font-weight: 800;
  text-align: center;
}

.beer-panel,
.odds-panel {
  margin-top: 20px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.text-button {
  min-height: 42px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 3px 3px 0 var(--ink);
  color: var(--ink);
  font-weight: 950;
  cursor: pointer;
}

.icon-button {
  width: 44px;
  font-size: 1.4rem;
  line-height: 1;
}

.text-button {
  padding: 0 14px;
}

.icon-button:active,
.text-button:active,
.mug-button:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.mug-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(42px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.mug-button {
  position: relative;
  display: grid;
  place-items: end center;
  height: 98px;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.mug-icon {
  width: 60px;
  height: 78px;
  object-fit: contain;
  filter: drop-shadow(3px 3px 0 rgba(23, 21, 17, 0.9));
  transform: rotate(var(--mug-tilt, 0deg)) scale(var(--mug-scale, 1));
  transition: transform 170ms ease, filter 170ms ease;
}

.mug-button.is-full .mug-icon {
  --mug-scale: 1.08;
  filter: drop-shadow(4px 4px 0 rgba(23, 21, 17, 0.9)) saturate(1.18);
}

.mug-button:nth-child(3n) {
  --mug-tilt: 2deg;
}

.mug-button:nth-child(4n) {
  --mug-tilt: -2deg;
}

.mug-number {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem;
  font-weight: 900;
  color: var(--muted);
}

.compact {
  align-items: end;
}

.phase {
  padding: 8px 12px;
  font-size: 0.85rem;
  background: #b8f3ea;
}

.odds-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.odd-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(110px, 44%) 54px;
  align-items: center;
  gap: 12px;
}

.odd-label {
  font-weight: 900;
}

.meter {
  height: 18px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
  background: #f4eadb;
}

.meter span {
  display: block;
  width: var(--chance, 0%);
  height: 100%;
  border-right: 2px solid rgba(23, 21, 17, 0.42);
  background: linear-gradient(90deg, var(--teal), var(--gold), var(--rose));
  transition: width 260ms ease;
}

.odd-value {
  font-variant-numeric: tabular-nums;
  font-weight: 950;
  text-align: right;
}

body[data-chaos="1"] .person-floor {
  --bob: 3px;
  --spin: -1deg;
  --wrecked: 0.18;
}

body[data-chaos="2"] .person-ivo {
  --bob: 6px;
  --spin: 2deg;
  --wrecked: 0.32;
}

body[data-chaos="3"] .person-karin {
  --bob: 8px;
  --spin: -3deg;
  --wrecked: 0.48;
}

body[data-chaos="4"] .crew {
  --sat: 1.25;
  --contrast: 1.08;
  --tilt: -1.8deg;
}

body[data-chaos="4"] .person {
  --wrecked: 0.72;
}

body[data-chaos="5"] .crew {
  --sat: 1.55;
  --contrast: 1.18;
  --blur: 0.5px;
  --tilt: 2.5deg;
  --scale: 1.02;
}

body[data-chaos="5"] .person {
  --wrecked: 1;
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 560px);
    padding-top: 10px;
  }

  .topbar {
    align-items: end;
  }

  .score-pill {
    min-width: 82px;
    min-height: 62px;
  }

  .portrait-stage {
    min-height: 285px;
    padding-inline: 10px;
  }

  .crew {
    min-height: 220px;
    gap: 8px;
  }

  .portrait-card {
    width: 100%;
    max-height: 220px;
  }

  .person span {
    min-width: 58px;
    padding: 5px 7px;
    font-size: 0.78rem;
  }

  .mug-grid {
    grid-template-columns: repeat(6, minmax(40px, 1fr));
  }

  .odd-row {
    grid-template-columns: 1fr 48px;
  }

  .meter {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .odd-value {
    grid-column: 2;
    grid-row: 1;
  }
}

@media (max-width: 430px) {
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    gap: 10px;
  }

  .mug-grid {
    grid-template-columns: repeat(3, minmax(54px, 1fr));
  }
}
