/* Tap Tower — style.css
   The game itself is drawn on <canvas>; this file styles the HUD and overlays. */

:root {
  --fg: #ffffff;
  --panel: rgba(12, 16, 32, 0.62);
  --accent: #ffd34d;
  --btn: rgba(255, 255, 255, 0.14);
  --btn-hover: rgba(255, 255, 255, 0.24);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0d1222;
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* No pinch-zoom, scroll bounce, text selection or tap highlight while playing */
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

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

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: calc(12px + var(--safe-top)) 16px 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  pointer-events: none;
}
#hud-mode {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  opacity: 0.85;
  padding-top: 8px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
#score {
  font-size: clamp(56px, 16vw, 84px);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 3px 12px rgba(0,0,0,0.35);
  font-variant-numeric: tabular-nums;
}
#score.pop { animation: pop 0.22s ease-out; }
@keyframes pop {
  0%   { transform: scale(1.25); }
  100% { transform: scale(1); }
}
.icon-btn {
  justify-self: end;
  pointer-events: auto;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--btn);
  color: var(--fg);
  font-size: 20px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--btn-hover); }

/* ---------- Overlay ---------- */
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease-out;
}
#overlay.show { opacity: 1; pointer-events: auto; cursor: pointer; }

.panel {
  width: 100%;
  max-width: 360px;
  padding: 24px 20px 18px;
  border-radius: 24px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transform: translateY(8px);
  transition: transform 0.2s ease-out;
  max-height: 100%;
  overflow-y: auto;
  touch-action: pan-y;          /* the panel may scroll on short screens */
  overscroll-behavior: contain;
}
#overlay.show .panel { transform: translateY(0); }

.logo {
  margin: 0;
  font-size: 54px;
  line-height: 0.9;
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(180deg, #fff 30%, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

#newbest {
  color: var(--accent);
  font-weight: 900;
  letter-spacing: 0.12em;
  animation: pulse 0.8s ease-in-out infinite alternate;
}
@keyframes pulse { to { transform: scale(1.1); } }

.big { font-size: 88px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.label { text-transform: uppercase; letter-spacing: 0.2em; font-size: 12px; opacity: 0.75; }
.stats { margin-top: 8px; font-size: 15px; opacity: 0.9; }

.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: rgba(0,0,0,0.25);
}
.mode-btn, .mode-tab {
  border: 0;
  padding: 10px 6px;
  border-radius: 10px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  opacity: 0.7;
}
.mode-btn.active, .mode-tab.active { background: var(--fg); color: #111; opacity: 1; }

/* "Beat my score" banner and daily streak */
.challenge {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--accent);
  color: #1a1400;
  font-weight: 800;
  font-size: 16px;
}
.streak { font-weight: 800; font-size: 15px; color: var(--accent); }

/* Leaderboard nickname entry */
.submit-row { display: flex; gap: 8px; }
.submit-row input {
  flex: 1;
  min-width: 0;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(0,0,0,0.25);
  color: var(--fg);
  font: inherit;
  font-size: 16px;              /* 16px stops iPhone zooming in on focus */
  user-select: text;
  -webkit-user-select: text;
}
.submit-row input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.submit-status { font-size: 14px; font-weight: 700; color: #9ff0b0; }
.submit-status.error { color: #ffb4a8; }

.row-flex { display: flex; gap: 8px; }
.row-flex > * { flex: 1; }

/* Leaderboard panel */
.lb {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  background: rgba(5, 8, 18, 0.6);
}
.lb-card {
  width: 100%;
  max-width: 380px;
  max-height: 100%;
  overflow-y: auto;
  touch-action: pan-y;
  padding: 18px 18px 14px;
  border-radius: 24px;
  background: #182038;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.lb-head { display: flex; align-items: center; justify-content: space-between; }
.lb-head h2 { margin: 0; font-size: 22px; font-weight: 900; }
.lb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.lb-list li {
  display: grid;
  grid-template-columns: 2em 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,0.06);
  font-variant-numeric: tabular-nums;
}
.lb-list li:nth-child(1) .rank { color: #ffd34d; }
.lb-list li:nth-child(2) .rank { color: #d9e2f2; }
.lb-list li:nth-child(3) .rank { color: #f0a868; }
.lb-list li.me { outline: 2px solid var(--accent); }
.lb-list .rank { font-weight: 900; text-align: center; }
.lb-list .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.lb-list .pts { font-weight: 900; }
.lb-status { font-size: 14px; opacity: 0.8; text-align: center; min-height: 1em; }

button:focus-visible, .mode-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bests { font-size: 14px; opacity: 0.85; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row[hidden] { display: none; }

.btn {
  border: 0;
  padding: 12px 10px;
  border-radius: 12px;
  background: var(--btn);
  color: var(--fg);
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.btn:hover { background: var(--btn-hover); }
.btn.primary { background: var(--accent); color: #1a1400; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border: 1px solid rgba(255,255,255,0.25); font-size: 14px; }
.btn:disabled { opacity: 0.6; cursor: default; }

.tap {
  margin-top: 4px;
  font-size: 20px;
  font-weight: 800;
  animation: blink 1.1s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0.35; } }
.keys { font-size: 12px; opacity: 0.55; }

/* ---------- Toast ---------- */
#toast {
  position: absolute;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(0,0,0,0.75);
  font-weight: 700;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Share-image preview (used where downloads are blocked) ---------- */
#img-preview {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  background: rgba(5, 8, 18, 0.92);
  text-align: center;
  user-select: auto;
  -webkit-user-select: auto;
  -webkit-touch-callout: default;
  touch-action: auto;
}
#img-preview img { max-width: 100%; max-height: 72vh; border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,0.5); }
#img-preview p { margin: 0; font-size: 14px; opacity: 0.85; }

/* Short landscape phones: tighten the panel */
@media (max-height: 560px) {
  .panel { gap: 8px; padding: 14px 16px 12px; }
  .logo { font-size: 36px; }
  .big { font-size: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  .tap, #newbest, #score.pop { animation: none; }
}
