* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #d6e9f5;
  font-family: "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* the canvas takes every finger itself: no scrolling, no zooming */
canvas { display: block; touch-action: none; cursor: grab; }

/* ---------- HUD ---------- */

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

#scoreBox {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
  min-width: 170px;
  padding: 10px 16px 12px;
  border-radius: 16px;
  background: rgba(30, 45, 80, 0.7);
  backdrop-filter: blur(4px);
}

#scoreBox .line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 2px;
}

#scoreBox .line b { font-size: 30px; line-height: 1.1; color: #ffd94a; }
#scoreBox .line.turn span::before { content: "▶ "; color: #ffd94a; }
#scoreBox .line b.bump { animation: bump 0.45s; }

@keyframes bump {
  40% { transform: scale(1.4); }
}

#clock {
  margin-top: 4px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
}

#clock.low { color: #ff8a80; }

#goal {
  font-size: 11px;
  letter-spacing: 1.5px;
  opacity: 0.85;
}

#topRight {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: max(20px, env(safe-area-inset-right));
  display: flex;
  gap: 10px;
  align-items: center;
}

#topRight button {
  pointer-events: auto;
  cursor: pointer;
  font: inherit;
  border-radius: 999px;
  touch-action: manipulation;
  border: 2px solid rgba(255, 255, 255, 0.8);
  background: rgba(30, 45, 80, 0.6);
  color: #fff;
  font-size: 12px;
  letter-spacing: 2px;
  padding: 8px 12px;
  min-height: 44px;
  backdrop-filter: blur(4px);
}

#soundBtn[aria-pressed="true"] { background: rgba(255, 255, 255, 0.92); color: #1e2d50; }

@media (hover: hover) {
  #topRight button:hover { border-color: #fff; }
}

#message {
  position: absolute;
  top: 26%;
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 720px);
  text-align: center;
  text-shadow: 0 4px 0 #b0500a, 0 6px 20px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.25s;
}

#message.on { opacity: 1; animation: pop 0.5s; }

@keyframes pop {
  0% { transform: translateX(-50%) scale(0.4); }
  60% { transform: translateX(-50%) scale(1.15); }
}

#msgBig {
  font-size: 68px;
  font-weight: 800;
  color: #ffe14a;
  letter-spacing: 2px;
}

#msgSmall {
  margin-top: 2px;
  font-size: 28px;
  font-weight: 700;
}

#hint {
  position: absolute;
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 8px));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 40px);
  padding: 7px 16px;
  font-size: 14px;
  letter-spacing: 1.2px;
  text-align: center;
  border-radius: 999px;
  background: rgba(30, 45, 80, 0.7);
  backdrop-filter: blur(4px);
}

#hint:empty { display: none; }

/* ---------- cards: start, who to play, match over ---------- */

.card {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px;
  overflow-y: auto;
  background: radial-gradient(circle at 50% 40%, rgba(255, 150, 70, 0.9), rgba(120, 50, 20, 0.95));
  backdrop-filter: blur(3px);
}

.card.hidden, .hidden { display: none !important; }

.card h1 {
  margin: 0;
  font-size: 72px;
  letter-spacing: 5px;
  line-height: 1.05;
  color: #ffd94a;
  text-shadow: 0 5px 0 #8a3a0a;
}

.card h2 {
  margin: 0 0 18px;
  font-size: 26px;
  letter-spacing: 3px;
}

.card .tag {
  margin: 12px 0 22px;
  font-size: 20px;
  letter-spacing: 1px;
}

.gold { color: #ffd94a; }

.card .keys {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  font-size: 15px;
  line-height: 2.1;
}

.card .keys b {
  display: inline-block;
  padding: 1px 8px;
  margin-right: 6px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 5px;
  font-size: 12px;
  letter-spacing: 1px;
}

.card .note {
  max-width: 480px;
  font-size: 14px;
  line-height: 1.65;
  opacity: 0.92;
  margin: 0 0 26px;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
}

button.big {
  cursor: pointer;
  border: none;
  background: #ffd94a;
  color: #6a3a00;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 3px;
  padding: 15px 32px;
  border-radius: 999px;
  box-shadow: 0 6px 0 #c99a10;
  touch-action: manipulation;
}

button.big.plain { background: #fff; color: #7a3a10; box-shadow: 0 6px 0 #d8b9a0; }

button.small {
  margin-top: 22px;
  border: none;
  background: none;
  color: #fff;
  font: inherit;
  font-size: 14px;
  letter-spacing: 1px;
  text-decoration: underline;
  cursor: pointer;
  padding: 10px 16px;
  touch-action: manipulation;
}

#ladderList {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(100%, 420px);
}

#ladderList button {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border: none;
  border-radius: 16px;
  background: #fff8e4;
  color: #3a2a10;
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.2);
}

#ladderList button:disabled { opacity: 0.5; cursor: default; }
#ladderList .face { font-size: 34px; }
#ladderList .who { flex: 1; }
#ladderList .name { font-size: 18px; font-weight: 800; letter-spacing: 1px; }
#ladderList .what { font-size: 12px; opacity: 0.75; }
#ladderList .state { font-size: 22px; }
#ladderList button.next { background: #ffd94a; }

/* ---------- small screens ---------- */

@media (max-width: 520px) {
  #topRight { flex-direction: column; align-items: flex-end; gap: 8px; }
}

@media (max-width: 700px) {
  .card h1 { font-size: 46px; }
  #msgBig { font-size: 46px; }
  #msgSmall { font-size: 20px; }
  #scoreBox { min-width: 140px; padding: 8px 12px; }
  #scoreBox .line b { font-size: 24px; }
  #topRight button { font-size: 10px; padding: 6px 10px; }
}
