:root {
  color-scheme: dark;
  --ink: #17130e;
  --paper: #f1d394;
  --gold: #ffe349;
  --panel: rgba(12, 12, 12, 0.78);
  --line: rgba(255, 255, 255, 0.7);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #181410;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 520px;
  overflow: hidden;
  background: #211812;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  touch-action: none;
  user-select: none;
}

.hud {
  position: absolute;
  color: white;
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(5px);
  border-radius: 8px;
}

.left-hud-stack {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: clamp(12px, 2vh, 24px);
  width: clamp(154px, 16vw, 240px);
  pointer-events: none;
}

.left-hud-stack > .hud,
.left-hud-stack > .paper {
  position: static;
  width: 100%;
}

.hud-score {
  width: clamp(154px, 16vw, 240px);
  padding: 12px 16px 14px;
  overflow: hidden;
}

.label {
  display: block;
  font-weight: 800;
  font-size: clamp(14px, 1.6vw, 22px);
  line-height: 1.1;
}

.hud-score strong {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow: visible;
  white-space: nowrap;
  color: var(--gold);
  font-size: clamp(40px, 5vw, 76px);
  line-height: 0.95;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.hud-score b {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow: visible;
  white-space: nowrap;
  font-size: clamp(28px, 3vw, 46px);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.meter {
  display: block;
  height: 10px;
  margin: 8px 0 14px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.65);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.meter i,
.power-track i {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #1fc960, #efe72d, #ec2b22);
}

.hud-goats {
  top: max(16px, env(safe-area-inset-top));
  right: calc(max(16px, env(safe-area-inset-right)) + 80px);
  min-width: clamp(118px, 12vw, 180px);
  padding: 12px 20px;
  text-align: center;
}

.hud-goats strong {
  display: block;
  color: var(--gold);
  font-size: clamp(36px, 4vw, 62px);
  line-height: 0.95;
}

.hud-goats small {
  color: white;
  font-size: 0.55em;
  margin-left: 8px;
}

.miss-label {
  display: block;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.28);
  color: white;
  font-size: clamp(13px, 1.35vw, 18px);
  font-weight: 900;
}

.miss-label b {
  color: #ff6b5d;
  font-size: 1.18em;
}

.round-button {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  width: clamp(58px, 7vw, 94px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  color: white;
  background: rgba(20, 20, 20, 0.82);
  font-size: clamp(28px, 5vw, 56px);
  font-weight: 900;
  line-height: 1;
}

.sound-button {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: clamp(46px, 5.2vw, 64px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 5px;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  background: rgba(20, 20, 20, 0.82);
  box-shadow: 0 7px 20px rgba(0, 0, 0, 0.32);
}

.sound-button[aria-pressed="false"] {
  background: rgba(20, 20, 20, 0.58);
}

.sound-button img {
  display: block;
  width: 100%;
  height: 100%;
}

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

.paper,
.next-card,
.sign {
  position: absolute;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(255,255,255,0.25), transparent 24%),
    #e8c17a;
  border: 2px solid rgba(70, 42, 18, 0.35);
  box-shadow: 0 9px 22px rgba(0, 0, 0, 0.32);
}

.paper {
  width: clamp(150px, 14vw, 210px);
  padding: 14px 16px;
  transform: rotate(-1deg);
  clip-path: polygon(3% 4%, 96% 0, 100% 91%, 92% 100%, 5% 96%, 0 14%);
}

.paper p {
  margin: 6px 0;
  font-weight: 850;
  font-size: clamp(14px, 1.5vw, 21px);
}

.combo {
  width: clamp(130px, 13vw, 190px);
  padding: 14px 16px;
  text-align: center;
}

.combo strong {
  display: block;
  color: var(--gold);
  font-size: clamp(38px, 4vw, 62px);
  line-height: 0.95;
}

.combo small {
  color: white;
  font-size: 0.45em;
}

.combo hr {
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.35);
  margin: 11px 0;
}

.combo span:last-child {
  font-weight: 850;
  font-size: clamp(14px, 1.4vw, 21px);
}

.next-card {
  right: max(18px, env(safe-area-inset-right));
  bottom: clamp(82px, 11vh, 120px);
  width: clamp(150px, 18vw, 270px);
  padding: 12px;
  border-radius: 6px;
  clip-path: polygon(3% 3%, 95% 0, 100% 94%, 92% 100%, 4% 98%, 0 8%);
}

.next-card h2 {
  margin: 0 0 8px;
  text-align: center;
  font-size: clamp(18px, 2.1vw, 32px);
}

#nextGoat {
  display: block;
  width: 100%;
  height: auto;
  border: 2px solid rgba(65, 36, 15, 0.5);
  border-radius: 7px;
  background: rgba(58, 37, 20, 0.35);
}

.badge {
  position: absolute;
  right: 12px;
  bottom: 13px;
  width: clamp(36px, 4vw, 58px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 2px solid rgba(0, 0, 0, 0.7);
  border-radius: 50%;
  color: white;
  background: #cf1e22;
  font-weight: 950;
  font-size: clamp(20px, 2.5vw, 38px);
}

.power-wrap {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 300px));
  min-width: 320px;
  height: 54px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  color: white;
  background: rgba(18, 18, 18, 0.86);
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  box-shadow: 0 7px 20px rgba(0, 0, 0, 0.32);
  font-size: clamp(18px, 2vw, 28px);
  font-weight: 900;
}

.power-track {
  position: relative;
  flex: 1;
  height: 30px;
  overflow: hidden;
  border: 3px solid white;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.sign {
  left: calc(max(18px, env(safe-area-inset-left)) + clamp(154px, 16vw, 240px) + 18px);
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 66px);
  margin: 0;
  padding: 10px 14px;
  font-weight: 900;
  font-size: clamp(16px, 1.8vw, 26px);
  transform: rotate(1.5deg);
  clip-path: polygon(4% 0, 96% 4%, 100% 92%, 8% 100%, 0 86%);
}

.result {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.56);
}

.result[hidden] {
  display: none;
}

.result-card {
  width: min(520px, 92vw);
  padding: 28px;
  color: white;
  background: rgba(18, 16, 14, 0.92);
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.overline {
  margin: 0 0 4px;
  color: var(--gold);
  font-weight: 900;
  letter-spacing: 0;
}

.result-card h2 {
  margin: 0 0 20px;
  font-size: clamp(30px, 5vw, 54px);
}

.result-card dl {
  display: grid;
  gap: 10px;
  margin: 0 0 24px;
}

.result-card dl div {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 22px;
}

.result-card dd {
  margin: 0;
  color: var(--gold);
  font-weight: 950;
}

.result-actions {
  display: flex;
  gap: 12px;
}

.result-actions button {
  flex: 1;
  min-height: 48px;
  border: 0;
  border-radius: 7px;
  color: #18130d;
  background: var(--gold);
  font-weight: 950;
  font-size: 18px;
}

.result-actions button + button {
  color: white;
  background: rgba(255, 255, 255, 0.16);
}

@media (max-width: 760px) {
  .game-shell {
    min-height: 100dvh;
  }

  .left-hud-stack {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    bottom: auto;
    width: 118px;
  }

  .hud-score {
    width: 118px;
    padding: 8px 10px;
  }

  .hud-score strong {
    font-size: 34px;
  }

  .hud-score b {
    font-size: 22px;
  }

  .meter {
    height: 8px;
    margin: 6px 0 9px;
  }

  .hud-goats {
    top: max(8px, env(safe-area-inset-top));
    right: calc(max(8px, env(safe-area-inset-right)) + 56px);
    min-width: 92px;
    padding: 8px 10px;
  }

  .hud-goats strong {
    font-size: 30px;
  }

  .miss-label {
    margin-top: 4px;
    padding-top: 4px;
    font-size: 12px;
  }

  .round-button {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    width: 48px;
    font-size: 28px;
  }

  .sound-button {
    left: max(8px, env(safe-area-inset-left));
    bottom: calc(max(10px, env(safe-area-inset-bottom)) + 54px);
    width: 42px;
    padding: 4px;
  }

  .paper,
  .combo {
    display: none;
  }

  .next-card {
    right: max(8px, env(safe-area-inset-right));
    bottom: calc(max(12px, env(safe-area-inset-bottom)) + 58px);
    width: 112px;
    padding: 8px;
  }

  .next-card h2 {
    margin-bottom: 5px;
    font-size: 15px;
  }

  .badge {
    right: 8px;
    bottom: 9px;
    width: 30px;
    font-size: 17px;
  }

  .power-wrap {
    bottom: max(10px, env(safe-area-inset-bottom));
    width: calc(100vw - 16px);
    min-width: 0;
    height: 46px;
    gap: 8px;
    padding: 7px 10px;
    font-size: 16px;
  }

  .power-track {
    height: 24px;
    border-width: 2px;
  }

  .sign {
    display: none;
  }

  .result-card {
    padding: 20px;
  }

  .result-card dl div {
    font-size: 18px;
  }

  .result-actions {
    flex-direction: column;
  }
}

@media (max-width: 390px) {
  .left-hud-stack {
    width: 108px;
  }

  .hud-score {
    width: 108px;
  }

  .hud-score strong {
    font-size: 30px;
  }

  .hud-score b {
    font-size: 19px;
  }

  .hud-goats {
    min-width: 84px;
    right: calc(max(6px, env(safe-area-inset-right)) + 50px);
    padding: 7px 8px;
  }

  .hud-goats strong {
    font-size: 26px;
  }

  .round-button {
    width: 44px;
  }

  .sound-button {
    width: 40px;
  }

  .next-card {
    width: 100px;
  }
}
