* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: #0b1026;
  color: #fff;
  font-family: "Arial Rounded MT Bold", "Nunito", "Baloo 2", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

/* The game is portrait. On a phone the frame is the whole screen; on a wide
   screen it is a centred 9:16 column. */
#frame {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  width: min(100vw, calc(100dvh * 0.5625));
  transform: translateX(-50%);
  overflow: hidden;
  background: #2f7fd6;
  /* everything in the HUD scales with the width of the picture */
  --u: calc(min(100vw, 100dvh * 0.5625) / 100);
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#hud {
  position: absolute;
  top: calc(2.4 * var(--u) + env(safe-area-inset-top));
  left: calc(3 * var(--u));
  right: calc(3 * var(--u));
  display: flex;
  align-items: flex-start;
  gap: calc(2 * var(--u));
  pointer-events: none;
  font-weight: 900;
}

#hud[hidden], [hidden] { display: none !important; }

#pause, #mute {
  pointer-events: auto;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
#pause { width: calc(11 * var(--u)); height: calc(11 * var(--u)); }
#pause img { width: 100%; height: 100%; display: block; filter: drop-shadow(0 calc(0.5 * var(--u)) 0 rgba(0, 0, 0, 0.25)); }

#powers { display: flex; flex-direction: column; gap: calc(1.2 * var(--u)); margin-top: calc(13 * var(--u)); margin-left: calc(-13 * var(--u)); }
.power { position: relative; width: calc(11 * var(--u)); }
.power img { width: 100%; display: block; }
.power i { position: absolute; left: 8%; right: 8%; bottom: calc(-0.6 * var(--u)); height: calc(1.3 * var(--u)); border-radius: 1em; background: rgba(11, 22, 50, 0.6); overflow: hidden; }
.power i::after { content: ""; position: absolute; inset: 0; width: var(--left, 100%); background: #ffd23f; }

#pills { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: calc(1.4 * var(--u)); }
.pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(2 * var(--u));
  min-width: calc(23 * var(--u));
  height: calc(7.4 * var(--u));
  padding: 0 calc(3 * var(--u)) 0 calc(1 * var(--u));
  border-radius: calc(2.4 * var(--u));
  background: #1d3566;
  box-shadow: inset 0 calc(-0.6 * var(--u)) 0 rgba(0, 0, 0, 0.25), 0 calc(0.5 * var(--u)) 0 rgba(0, 0, 0, 0.2);
  font-size: calc(4.4 * var(--u));
  font-variant-numeric: tabular-nums;
  text-shadow: 0 calc(0.4 * var(--u)) 0 rgba(0, 0, 0, 0.35);
}
.pill img { height: calc(6 * var(--u)); display: block; }

#lead {
  position: relative;
  width: calc(23 * var(--u));
  height: calc(3.4 * var(--u));
  border-radius: 1em;
  background: rgba(29, 53, 102, 0.85);
  overflow: hidden;
  font-size: calc(2.1 * var(--u));
  letter-spacing: 0.1em;
  text-align: center;
  line-height: calc(3.4 * var(--u));
}
#lead span { position: relative; }
#lead-fill { position: absolute; inset: 0; width: 80%; background: #37b24d; transition: width 0.15s linear, background 0.3s; }
#lead.low #lead-fill { background: #e03131; }
#lead.low span { animation: blink 0.5s steps(2, start) infinite; }

#combo {
  position: absolute;
  top: 24%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: calc(9 * var(--u));
  font-weight: 900;
  font-style: italic;
  color: #ffd23f;
  -webkit-text-stroke: calc(0.5 * var(--u)) #8a3b12;
  paint-order: stroke fill;
  text-shadow: 0 calc(0.9 * var(--u)) 0 rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
}
#combo.show { animation: pop 0.8s ease-out forwards; }

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: calc(2.4 * var(--u));
  padding: calc(18 * var(--u)) calc(6 * var(--u)) 0;
  text-align: center;
  background: linear-gradient(rgba(13, 28, 66, 0.5), rgba(13, 28, 66, 0.12) 55%, rgba(13, 28, 66, 0) 70%);
}

#title {
  margin: 0;
  font-size: calc(var(--size, 10.5) * var(--u)); /* set to fit the text */
  white-space: nowrap;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.01em;
  color: #ffd23f;
  -webkit-text-stroke: calc(0.9 * var(--u)) #8a3b12;
  paint-order: stroke fill;
  text-shadow: 0 calc(1.2 * var(--u)) 0 #5c2409;
}

#result, #how, #board {
  margin: 0;
  padding: calc(2.6 * var(--u)) calc(4 * var(--u));
  border-radius: calc(3 * var(--u));
  background: rgba(29, 53, 102, 0.92);
  box-shadow: inset 0 calc(-0.7 * var(--u)) 0 rgba(0, 0, 0, 0.25);
  font-size: calc(4 * var(--u));
  font-weight: 700;
}
#how { list-style: none; display: flex; flex-direction: column; gap: calc(1.8 * var(--u)); text-align: left; }
#how li { display: flex; align-items: center; gap: calc(3 * var(--u)); }
#how img { width: calc(9 * var(--u)); height: calc(8 * var(--u)); object-fit: contain; }
#result { font-size: calc(4.6 * var(--u)); line-height: 1.55; }
#result b { color: #ffd23f; }
#result .big { display: block; font-size: calc(9 * var(--u)); line-height: 1.2; color: #ffd23f; }
#result img { height: 1em; vertical-align: -0.12em; }

#go {
  margin: calc(1 * var(--u)) 0 0;
  padding: calc(2.4 * var(--u)) calc(6 * var(--u));
  border-radius: calc(3 * var(--u));
  background: #37b24d;
  box-shadow: inset 0 calc(-0.9 * var(--u)) 0 rgba(0, 0, 0, 0.25), 0 calc(0.8 * var(--u)) 0 rgba(0, 0, 0, 0.25);
  font-size: calc(5 * var(--u));
  font-weight: 900;
  letter-spacing: 0.04em;
  text-shadow: 0 calc(0.4 * var(--u)) 0 rgba(0, 0, 0, 0.3);
  animation: pulse 1.1s ease-in-out infinite;
}

#mute {
  position: absolute;
  top: calc(3 * var(--u) + env(safe-area-inset-top));
  left: 50%;
  margin-left: calc(-18.5 * var(--u));
  width: calc(11 * var(--u));
  height: calc(11 * var(--u));
  border-radius: calc(2.4 * var(--u));
  background: #1d3566;
  font-size: calc(5 * var(--u));
}

/* high scores */
#board { align-self: stretch; padding-top: calc(2 * var(--u)); padding-bottom: calc(2 * var(--u)); }
#board h2, #stats h2, #stats h3 { margin: 0 0 calc(1 * var(--u)); font-size: calc(3.4 * var(--u)); letter-spacing: 0.12em; color: #ffd23f; }
#stats h3 { margin-top: calc(3 * var(--u)); }
#board ol, #stats ol { margin: 0; padding: 0; list-style: none; counter-reset: place; text-align: left; font-size: calc(3.9 * var(--u)); font-weight: 700; }
#board li, #stats li { display: flex; gap: calc(2 * var(--u)); padding: calc(0.5 * var(--u)) calc(1.5 * var(--u)); border-radius: calc(1.4 * var(--u)); counter-increment: place; }
#board li::before, #stats li::before { content: counter(place) "."; width: 1.6em; text-align: right; opacity: 0.7; }
#board li span, #stats li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board li b, #stats li b { font-variant-numeric: tabular-nums; }
#board li.me, #stats li.me { background: rgba(255, 210, 63, 0.22); color: #ffe38a; }
#board li.empty, #stats li.empty { opacity: 0.7; counter-increment: none; }
#board li.empty::before, #stats li.empty::before { content: ""; width: 0; }
#board-me { margin: calc(1 * var(--u)) 0 0; font-size: calc(3.4 * var(--u)); font-weight: 700; opacity: 0.9; }

#namerow { display: flex; gap: calc(2 * var(--u)); align-self: stretch; }
#name {
  flex: 1;
  min-width: 0;
  height: calc(11 * var(--u));
  padding: 0 calc(3 * var(--u));
  border: calc(0.6 * var(--u)) solid #ffd23f;
  border-radius: calc(2.4 * var(--u));
  background: #fff;
  color: #1d3566;
  font: inherit;
  font-size: max(16px, calc(4.4 * var(--u))); /* 16px keeps iOS from zooming in */
  font-weight: 800;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}
#name-ok, #info, #stats-close {
  border: 0;
  border-radius: calc(2.4 * var(--u));
  background: #1d3566;
  color: #fff;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}
#name-ok { width: calc(18 * var(--u)); font-size: calc(4.6 * var(--u)); background: #37b24d; box-shadow: inset 0 calc(-0.8 * var(--u)) 0 rgba(0, 0, 0, 0.25); }
#name-ok.saved { background: #1d3566; }
#info {
  position: absolute;
  top: calc(3 * var(--u) + env(safe-area-inset-top));
  left: 50%;
  margin-left: calc(7.5 * var(--u));
  width: calc(11 * var(--u));
  height: calc(11 * var(--u));
  font-size: calc(6 * var(--u));
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
}

#stats {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(5 * var(--u));
  background: rgba(8, 16, 40, 0.72);
}
#stats-box {
  position: relative;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  touch-action: pan-y;
  padding: calc(5 * var(--u));
  border-radius: calc(4 * var(--u));
  background: #1d3566;
  box-shadow: 0 calc(1 * var(--u)) 0 rgba(0, 0, 0, 0.3);
  text-align: center;
}
#stats h2 { font-size: calc(5.4 * var(--u)); margin-bottom: calc(3 * var(--u)); }
#stats dl { display: grid; grid-template-columns: 1fr auto; gap: calc(1.2 * var(--u)) calc(4 * var(--u)); margin: 0; text-align: left; font-size: calc(4 * var(--u)); font-weight: 700; }
#stats dd { margin: 0; text-align: right; font-weight: 900; color: #ffd23f; font-variant-numeric: tabular-nums; }
#stats-close { position: absolute; top: calc(2 * var(--u)); right: calc(2 * var(--u)); width: calc(10 * var(--u)); height: calc(10 * var(--u)); font-size: calc(6 * var(--u)); background: rgba(255, 255, 255, 0.14); }
#st-note { margin: calc(3 * var(--u)) 0 0; font-size: calc(3 * var(--u)); opacity: 0.75; }

@keyframes blink { to { visibility: hidden; } }
@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes pop {
  0% { opacity: 0; transform: scale(1.6); }
  15% { opacity: 1; transform: scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-20px); }
}
