:root {
  color-scheme: dark;
  --felt: #0b5c45;
  --felt-deep: #063629;
  --rail: #28180d;
  --gold: #f8cf55;
  --ivory: #f4e7bd;
  --ink: #fff7dc;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 18%, #173b32 0, #06100d 64%);
  color: var(--ink);
  font-family: ui-rounded, "Avenir Next", "Trebuchet MS", sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

button {
  border: 0;
  color: #241708;
  background: linear-gradient(180deg, #ffe19a, #d6942e);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  font: 800 13px/1 ui-rounded, "Avenir Next", sans-serif;
  cursor: pointer;
}

#app {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

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

#hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  z-index: 5;
  width: min(92vw, 420px);
  height: 54px;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 1fr 1fr 68px;
  align-items: center;
  gap: 8px;
  padding: 7px;
  border: 1px solid rgba(255, 239, 171, 0.24);
  border-radius: 8px;
  background: rgba(4, 16, 13, 0.74);
  backdrop-filter: blur(12px);
}

.hud-item {
  height: 40px;
  display: grid;
  align-content: center;
  padding: 0 12px;
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
}

.hud-item span {
  color: rgba(255, 247, 220, 0.62);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hud-item strong {
  margin-top: 1px;
  color: #fff3bf;
  font-size: 21px;
  line-height: 1;
}

.hud-item.danger {
  background: linear-gradient(180deg, #ff1d1d, #a00000);
  box-shadow: 0 0 18px rgba(255, 20, 20, 0.68), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.hud-item.danger span,
.hud-item.danger strong {
  color: #fff;
  text-shadow: 0 2px 0 rgba(80, 0, 0, 0.45), 0 0 10px rgba(255, 255, 255, 0.65);
}

.hud-item.danger strong {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 6px;
  background: #e30000;
  font-size: 31px;
  color: #fff;
  animation: numberDangerBreath 0.46s ease-in-out infinite alternate;
}

.hud-item.danger strong::after {
  content: "";
  position: absolute;
}

@keyframes numberDangerBreath {
  from {
    transform: scale(1);
    background: #e30000;
    color: #fff;
  }
  to {
    transform: scale(1.28);
    background: #fff;
    color: #d00000;
    text-shadow: none;
  }
}

#resetBtn,
#againBtn {
  height: 40px;
  min-width: 62px;
  border-radius: 6px;
}

#toast {
  position: fixed;
  left: 50%;
  top: max(82px, calc(env(safe-area-inset-top) + 72px));
  z-index: 9;
  width: min(88vw, 390px);
  transform: translateX(-50%);
  padding: 13px 16px;
  border-radius: 8px;
  background: rgba(156, 0, 0, 0.94);
  color: #fff;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.36), 0 0 0 1px rgba(255, 255, 255, 0.22) inset;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.35;
  text-align: center;
  animation: toastIn 0.22s ease-out both;
}

#toast[hidden] {
  display: none;
}

#unsupportedMessage {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 36%, rgba(19, 74, 58, 0.9), rgba(1, 5, 4, 0.96) 66%);
  text-align: center;
}

#unsupportedMessage[hidden] {
  display: none;
}

#introPopup {
  position: fixed;
  inset: 0;
  z-index: 18;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(1, 5, 4, 0.72);
  backdrop-filter: blur(10px);
  text-align: center;
}

#introPopup[hidden] {
  display: none;
}

.intro-card {
  width: min(84vw, 330px);
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 18px 18px 20px;
  border-radius: 8px;
  background: rgba(5, 17, 14, 0.92);
  border: 1px solid rgba(255, 239, 171, 0.28);
  box-shadow: 0 22px 62px rgba(0, 0, 0, 0.52), 0 0 42px rgba(248, 207, 85, 0.14);
}

.intro-card img {
  width: min(100%, 300px);
  height: auto;
  display: block;
  border-radius: 8px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.36);
}

.intro-card p {
  margin: 0;
  color: #fff2b6;
  font-size: 18px;
  font-weight: 900;
  line-height: 1.35;
}

.intro-card button {
  width: 104px;
  height: 40px;
  border-radius: 6px;
}

.unsupported-card {
  width: min(86vw, 410px);
  padding: 24px 22px 26px;
  border: 1px solid rgba(255, 239, 171, 0.28);
  border-radius: 8px;
  background: rgba(5, 17, 14, 0.86);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.48), 0 0 34px rgba(248, 207, 85, 0.12);
}

.unsupported-card h1 {
  margin: 0 0 12px;
  color: #fff2b6;
  font-size: clamp(26px, 8vw, 42px);
  line-height: 1.08;
}

.unsupported-card p {
  margin: 0;
  color: rgba(255, 248, 222, 0.82);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.45;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate(-50%, -10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

#powerRing {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 4;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.power-core {
  position: absolute;
  width: 36px;
  height: 36px;
  left: -18px;
  top: -18px;
  border-radius: 50%;
  border: 2px solid rgba(235, 235, 235, 0.88);
  background: rgba(118, 124, 128, 0.28);
  box-shadow: 0 0 0 8px rgba(160, 166, 170, 0.15), 0 0 18px rgba(255, 255, 255, 0.34);
  animation: cancelBreath 0.72s ease-in-out infinite alternate;
}

#powerRing.cancel .power-core {
  background: rgba(220, 225, 228, 0.36);
  border-color: rgba(255, 255, 255, 0.98);
  box-shadow: 0 0 0 11px rgba(205, 210, 214, 0.2), 0 0 24px rgba(255, 255, 255, 0.48);
}

@keyframes cancelBreath {
  from {
    transform: scale(0.92);
    opacity: 0.72;
  }
  to {
    transform: scale(1.16);
    opacity: 1;
  }
}

.power-line {
  display: none;
  position: absolute;
  left: 0;
  top: -2px;
  width: var(--len, 0px);
  height: 4px;
  transform-origin: left center;
  transform: rotate(var(--ang, 0deg));
  border-radius: 99px;
  background: linear-gradient(90deg, rgba(255, 235, 153, 0.05), rgba(255, 204, 71, 0.98));
  box-shadow: 0 0 14px rgba(255, 214, 84, 0.65);
}

#result {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 24px;
  background: radial-gradient(circle at 50% 40%, rgba(14, 68, 52, 0.74), rgba(1, 5, 4, 0.92) 62%);
  text-align: center;
}

#result[hidden],
#powerRing[hidden] {
  display: none;
}

.result-mark {
  width: 112px;
  height: 112px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 26%, #fff8cd, #f2b13c 56%, #6a330d 100%);
  color: #281503;
  font-size: 48px;
  font-weight: 900;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.48), 0 0 38px rgba(245, 178, 55, 0.34);
}

#result h1 {
  margin: 0;
  color: #fff2b6;
  font-size: clamp(32px, 9vw, 54px);
  letter-spacing: 0;
}

#result p {
  min-height: 24px;
  margin: 0;
  color: rgba(255, 248, 222, 0.8);
  font-size: 16px;
}

.result-stats {
  display: grid;
  gap: 5px;
  min-height: 48px;
  color: #fff2b6;
  font-size: 16px;
  font-weight: 900;
  line-height: 1.35;
}

#result button + button {
  margin-left: 8px;
}

@media (orientation: landscape) and (max-height: 520px) {
  #hud {
    left: max(12px, env(safe-area-inset-left));
    top: 12px;
    width: 286px;
    transform: none;
  }
}
