:root {
  color-scheme: light;
  --bg-a: #f6c878;
  --bg-b: #fff1cf;
  --panel: rgba(255, 248, 222, 0.96);
  --panel-border: #b66a2c;
  --text: #50301f;
  --coral: #e85d4f;
  --gold: #e5a62f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  font-family: "Avenir Next Rounded", "Noto Sans Thai", "Leelawadee UI", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 250, 222, 0.94), transparent 44%),
    linear-gradient(180deg, var(--bg-a), var(--bg-b));
  color: var(--text);
  overflow: hidden;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100svh;
  touch-action: none;
}

.game-shell {
  width: min(100vw, 460px);
  height: min(100svh, 900px);
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 10px;
  padding:
    max(8px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
}

@supports (height: 100dvh) {
  .game-shell {
    height: min(100dvh, 900px);
  }
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.hud-card {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 16px;
  padding: 8px 10px;
  display: grid;
  line-height: 1.1;
  justify-items: center;
}

.timer-card {
  background: rgba(255, 239, 203, 0.98);
}

.label {
  font-size: 0.78rem;
  font-weight: 700;
  opacity: 0.8;
}

.value {
  font-size: 1.4rem;
  font-weight: 900;
  color: #7b3429;
}

.battlefield {
  position: relative;
  border-radius: 24px;
  overflow: hidden;
  border: 3px solid rgba(255, 244, 208, 0.95);
  box-shadow: 0 14px 32px rgba(91, 47, 24, 0.35);
  background: #b96b35;
}

.star-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 8px;
}

.star-strip > * {
  justify-self: center;
}

.phase-badge {
  justify-self: start;
  border: 2px solid #b66a2c;
  border-radius: 999px;
  padding: 4px 12px;
  background: rgba(255, 247, 216, 0.96);
  color: #7b3429;
  font-size: 0.82rem;
  font-weight: 900;
  box-shadow: 0 4px 10px rgba(91, 47, 24, 0.16);
}

.top-actions {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.round-action {
  border: 2px solid #ad572c;
  border-radius: 999px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 1.05rem;
  font-weight: 900;
  color: #683323;
  cursor: pointer;
  box-shadow: 0 4px 9px rgba(91, 47, 24, 0.18);
}

.refresh-btn {
  background: linear-gradient(180deg, #fff4ca, #ecc46a);
  font-size: 1.45rem;
}

.audio-btn {
  background: linear-gradient(180deg, #ffd672, #e99a25);
}

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

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(19, 34, 66, 0.44);
  z-index: 2;
}

.overlay-card {
  width: min(90%, 330px);
  border-radius: 16px;
  padding: 16px 14px;
  background: rgba(255, 250, 234, 0.96);
  border: 2px solid rgba(216, 153, 47, 0.8);
  text-align: center;
}

.result-card {
  position: relative;
  width: min(90%, 350px);
  padding: 28px 18px 20px;
  border: 3px solid #d59a39;
  border-radius: 24px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 223, 139, 0.6), transparent 42%),
    rgba(255, 250, 234, 0.98);
  box-shadow: 0 18px 45px rgba(47, 24, 14, 0.38);
}

.result-badge {
  position: absolute;
  top: -31px;
  left: 50%;
  transform: translateX(-50%);
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 3px solid #d59a39;
  border-radius: 50%;
  background: #fff7dc;
  font-size: 1.8rem;
  box-shadow: 0 7px 14px rgba(78, 39, 18, 0.2);
}

.result-eyebrow {
  color: #b25936;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 17px;
}

.result-stat {
  display: grid;
  gap: 4px;
  padding: 10px 4px;
  border: 1px solid rgba(182, 106, 44, 0.34);
  border-radius: 13px;
  background: rgba(255, 239, 203, 0.8);
}

.result-stat span {
  color: #86513a;
  font-size: 0.68rem;
  font-weight: 800;
}

.result-stat strong {
  color: #7b3429;
  font-size: 1.15rem;
}

.overlay-card h1,
.overlay-card h2 {
  margin: 0 0 8px;
  color: #7b3429;
}

.overlay-card p {
  margin: 0 0 12px;
  font-weight: 800;
}

.overlay-card button {
  border: 0;
  background: linear-gradient(180deg, #f07858, #c9473e);
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
  border-radius: 999px;
  padding: 10px 20px;
  box-shadow: 0 8px 12px rgba(35, 96, 44, 0.3);
  cursor: pointer;
}

.hidden {
  display: none;
}

.controls {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.help {
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  opacity: 0.86;
}
