:root {
  --cream: #F6D9A6;
  --wheat: #EFC178;
  --clay: #E07A3C;
  --terra: #C4431F;
  --ink: #2B2119;
  --steel: #4C555C;
  --pine: #3F5342;
  --chalk: #FBF7EE;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--cream);
}

body {
  font-family: 'Barlow Semi Condensed', sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
}

#game canvas {
  display: block;
}

#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

#scoreWrap {
  position: absolute;
  left: max(8px, env(safe-area-inset-left));
  top: max(6px, env(safe-area-inset-top));
  width: clamp(116px, 17vw, 236px);
}

#scoreWrap img {
  width: 100%;
  display: block;
}

#score {
  position: absolute;
  inset: 13% 7% 14% 7%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Bebas Neue', sans-serif;
  font-weight: 400;
  font-size: clamp(30px, 5.3vw, 71px);
  line-height: 1;
  letter-spacing: 0.035em;
  color: var(--chalk);
  text-shadow: 0 2px 0 rgba(43, 33, 25, 0.58), 1px 0 0 rgba(43, 33, 25, 0.35);
  transform: translateY(3%);
}

#roundWrap {
  position: absolute;
  left: 50%;
  top: max(4px, env(safe-area-inset-top));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
}

#roundBadge {
  position: relative;
  width: clamp(46px, 6vw, 88px);
}

#roundBadge img {
  width: 100%;
  display: block;
}

#round {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(19px, 2.7vw, 38px);
  line-height: 1;
  color: var(--chalk);
  text-shadow: 0 2px 0 rgba(43, 33, 25, 0.55);
  transform: translateY(4%);
}

#roundBadge.pulse {
  animation: badgePulse 420ms steps(2, end) 1;
}

@keyframes badgePulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

#missRow {
  margin-top: 1px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.missLabel {
  font-size: clamp(7px, 1.02vw, 11px);
  font-weight: 700;
  letter-spacing: 0.17em;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(251, 247, 238, 0.45);
}

.pips {
  display: flex;
  gap: 3px;
}

.pip {
  width: clamp(7px, 0.85vw, 11px);
  height: clamp(7px, 0.85vw, 11px);
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: var(--chalk);
}

.pip.used {
  background: var(--terra);
}

#shellWrap {
  position: absolute;
  right: max(8px, env(safe-area-inset-right));
  top: max(6px, env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

#shells {
  display: flex;
  align-items: flex-end;
  gap: clamp(2px, 0.38vw, 5px);
}

#shells img {
  display: block;
  height: clamp(36px, min(8.2vh, 8.6vw), 66px);
  width: auto;
}

#reloadStamp {
  font-family: 'Alfa Slab One', serif;
  font-size: clamp(10px, 1.2vw, 15px);
  letter-spacing: 0.08em;
  color: var(--terra);
  text-shadow: 0 1px 0 var(--chalk);
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 120ms linear;
}

#reloadStamp.on {
  opacity: 1;
}

#utility {
  position: absolute;
  left: clamp(10px, 1.4vw, 20px);
  bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
}

#hint {
  font-size: clamp(8px, 1.06vw, 12px);
  font-weight: 700;
  letter-spacing: 0.11em;
  line-height: 1.35;
  color: var(--ink);
  background: var(--cream);
  border: 1.5px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  padding: 4px 7px;
  max-width: min(74vw, 620px);
}

#utilityButtons {
  display: flex;
  gap: 9px;
  pointer-events: auto;
}

.stamp {
  pointer-events: auto;
  display: inline-block;
  font-family: 'Alfa Slab One', serif;
  font-weight: 400;
  text-transform: uppercase;
  border: 0;
  border-radius: 1px;
  background: var(--terra);
  color: var(--chalk);
  font-size: clamp(16px, 2.1vw, 27px);
  letter-spacing: 0.03em;
  line-height: 1;
  padding: 0.66em 1.3em;
  box-shadow: 5px 6px 0 var(--ink);
  cursor: pointer;
  transform: translate(0, 0);
  -webkit-appearance: none;
  appearance: none;
}

.stamp:active {
  transform: translate(5px, 6px);
  box-shadow: 0 0 0 var(--ink);
}

.stamp.waiting {
  background: var(--steel);
  color: var(--chalk);
}

.stamp.small {
  font-size: clamp(9px, 1.02vw, 13px);
  padding: 0.55em 0.85em;
  box-shadow: 3px 3px 0 var(--ink);
}

.stamp.small:active {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 var(--ink);
}

#reticle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: clamp(38px, 4.7vw, 62px);
  height: clamp(38px, 4.7vw, 62px);
  transform: translate(-50%, -50%);
  z-index: 12;
  pointer-events: none;
  display: none;
}

#reticle.on {
  display: block;
}

#reticle img {
  width: 100%;
  height: 100%;
  display: block;
}

#fx {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  overflow: hidden;
}

.hitfloat,
.missfloat {
  position: absolute;
  font-family: 'Bebas Neue', sans-serif;
  line-height: 1;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  animation: floatUp 820ms ease-out forwards;
}

.hitfloat {
  font-size: clamp(22px, 2.8vw, 38px);
  color: var(--chalk);
  text-shadow: 2px 2px 0 var(--terra), 0 0 0 var(--ink);
  letter-spacing: 0.03em;
}

.missfloat {
  font-family: 'Alfa Slab One', serif;
  font-size: clamp(12px, 1.5vw, 20px);
  color: var(--terra);
  text-shadow: 2px 2px 0 var(--ink);
  letter-spacing: 0.04em;
}

@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.86); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -175%) scale(1.04); }
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  pointer-events: none;
}

.overlay.hidden {
  display: none;
}

.menu-inner {
  position: absolute;
  left: 50%;
  top: 58.5%;
  transform: translate(-50%, -50%);
  width: min(560px, 92vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(9px, 1.6vh, 17px);
  text-align: center;
  pointer-events: auto;
}

.eyebrow {
  margin: 0;
  font-size: clamp(9px, 1.25vw, 14px);
  font-weight: 700;
  letter-spacing: 0.17em;
  line-height: 1.35;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(251, 247, 238, 0.5);
  max-width: 34ch;
}

.bestline,
.tinystuff {
  margin: 0;
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(14px, 1.7vw, 22px);
  letter-spacing: 0.08em;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(251, 247, 238, 0.5);
}

.tinystuff {
  font-family: 'Barlow Semi Condensed', sans-serif;
  font-size: clamp(8px, 1.02vw, 11px);
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--chalk);
  text-shadow: 0 1px 0 var(--ink), 0 0 5px rgba(43, 33, 25, 0.5);
}

.stamp.ghost {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--ink), 4px 5px 0 rgba(43, 33, 25, 0.28);
}

.stamp.ghost:active {
  transform: translate(4px, 5px);
  box-shadow: inset 0 0 0 2px var(--ink), 0 0 0 rgba(43, 33, 25, 0.28);
}

#pauseOverlay .menu-inner {
  gap: clamp(8px, 1.3vh, 14px);
  top: 50%;
}

#overOverlay {
  pointer-events: auto;
}

.scorecard {
  width: min(460px, 92vw);
  background: var(--cream);
  border: 2px solid var(--ink);
  box-shadow: 9px 10px 0 var(--ink);
  padding: clamp(16px, 2.6vw, 28px) clamp(16px, 3vw, 32px);
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.4vh, 14px);
  text-align: left;
  max-height: 86vh;
  overflow: auto;
}

.scorecard .eyebrow {
  max-width: none;
  text-align: center;
}

.finalRow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 6px;
}

.label {
  font-size: clamp(9px, 1.1vw, 12px);
  font-weight: 700;
  letter-spacing: 0.18em;
}

.bigfig {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(40px, 5.2vw, 64px);
  line-height: 0.9;
  letter-spacing: 0.03em;
  color: var(--terra);
}

.finalSmall {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: clamp(9px, 1.06vw, 12px);
  font-weight: 700;
  letter-spacing: 0.12em;
}

.finalSmall b {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.5em;
  letter-spacing: 0.05em;
  font-weight: 400;
}

.board-title {
  font-size: clamp(9px, 1.06vw, 12px);
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--terra);
  border-top: 2px solid var(--ink);
  padding-top: 7px;
}

#board {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#board li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: clamp(11px, 1.2vw, 14px);
  font-weight: 600;
  letter-spacing: 0.04em;
}

#board .rank {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.35em;
  color: var(--terra);
  min-width: 1.5em;
}

#board .who {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#board a {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--steel);
}

#board .val {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.4em;
  letter-spacing: 0.05em;
}

#board li.mine .who {
  color: var(--terra);
}

.over-actions {
  display: flex;
  justify-content: center;
  padding-top: 2px;
}

.hidden {
  display: none !important;
}

#grain {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0.075;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.6'/%3E%3C/svg%3E");
  background-size: 160px 160px;
}

@media (max-aspect-ratio: 1/1) {
  .menu-inner {
    top: 42%;
  }

  .tinystuff {
    display: none;
  }

  #hint {
    max-width: 76vw;
  }

  .scorecard {
    max-height: 80vh;
  }
}

@media (max-height: 540px) and (min-aspect-ratio: 4/3) {
  .menu-inner {
    top: 61%;
    gap: 7px;
  }

  .eyebrow {
    font-size: 9px;
  }

  .tinystuff {
    display: none;
  }
}
