/* DontTap Ninja — see design.md §4 for palette & layout rules */

:root {
  --bg: #f2f2f2;
  --check: #e4e4e4;
  --cell: #ffffff;
  --cell-border: #d9d9d9;
  --tile: #111111;
  --accent: #e02420;
  --gold: #f5b301;
  --ink: #111111;
  --trail: #6ec3ff;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--ink);
  background:
    repeating-conic-gradient(var(--check) 0% 25%, transparent 0% 50%)
    0 0 / 56px 56px,
    var(--bg);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; cursor: pointer; }

/* ============================== MENU ============================== */

.menu {
  position: relative;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: max(3dvh, 12px) calc(20px + env(safe-area-inset-right)) 0
    calc(20px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.menu-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.92;
  font-weight: 900;
  letter-spacing: 0.02em;
  /* sized so title+burst+buttons+footer sum ≤ ~92dvh at any height */
  font-size: clamp(52px, 14dvh, 110px);
  color: #111;
  text-shadow:
    -3px -3px 0 #fff, 3px -3px 0 #fff, -3px 3px 0 #fff, 3px 3px 0 #fff,
    0 3px 0 #fff, 0 -3px 0 #fff, 3px 0 0 #fff, -3px 0 0 #fff,
    0 8px 14px rgba(0, 0, 0, 0.22);
  animation: title-drop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}

.menu-title-line { display: block; }

.menu-title-bang {
  font-style: normal;
  color: var(--accent);
  font-size: 1.12em;
  vertical-align: -0.05em;
  margin-left: 0.06em;
  text-shadow:
    -3px -3px 0 #fff, 3px -3px 0 #fff, -3px 3px 0 #fff, 3px 3px 0 #fff,
    0 8px 14px rgba(224, 36, 32, 0.35);
  display: inline-block;
  animation: bang-pulse 1.6s ease-in-out infinite;
}

@keyframes title-drop {
  from { transform: translateY(-40px) scale(0.9); opacity: 0; }
}
@keyframes bang-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12) rotate(3deg); }
}

.burst-wrap {
  display: flex;
  justify-content: center;
  margin: max(1.5dvh, 6px) 0;
}

.burst {
  --p: polygon(50% 0%, 59% 12%, 74% 5%, 76% 20%, 92% 18%, 87% 33%, 100% 40%,
       89% 50%, 100% 60%, 87% 67%, 92% 82%, 76% 80%, 74% 95%, 59% 88%,
       50% 100%, 41% 88%, 26% 95%, 24% 80%, 8% 82%, 13% 67%, 0% 60%,
       11% 50%, 0% 40%, 13% 33%, 8% 18%, 24% 20%, 26% 5%, 41% 12%);
  position: relative;
  width: min(clamp(190px, 36dvh, 300px), 78vw);
  aspect-ratio: 10 / 7;
  display: grid;
  place-items: center;
  transform: rotate(-7deg);
  animation: burst-wobble 2.4s ease-in-out infinite;
  filter: drop-shadow(0 6px 10px rgba(224, 36, 32, 0.35));
}

.burst::before {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: var(--p);
  background: radial-gradient(circle at 50% 42%, #ef5a3a 0%, #e02420 55%, #b21510 100%);
}

.burst span {
  position: relative;
  color: #fff;
  font-weight: 800;
  font-size: clamp(20px, 4.6dvh, 30px);
  font-family: Georgia, "Times New Roman", serif;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
}

@keyframes burst-wobble {
  0%, 100% { transform: rotate(-7deg) scale(1); }
  50% { transform: rotate(-4deg) scale(1.04); }
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: max(1.6dvh, 10px);
  width: min(62%, 320px);
  margin-top: auto;
  margin-bottom: max(11dvh, 74px);
  position: relative;
  z-index: 2;
}

.menu-btn {
  border: 3px solid #111;
  border-radius: 14px;
  padding: max(1.3dvh, 9px) 8px;
  font-size: clamp(22px, 4dvh, 32px);
  font-weight: 600;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.menu-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25); }
.menu-btn--black { background: #111; color: #fff; }
.menu-btn--dark { background: #2e2e2e; color: #fff; }
.menu-btn--white { background: #fff; color: #111; }

.menu-ninja {
  position: absolute;
  right: -4%;
  bottom: max(4dvh, 22px);
  width: min(clamp(160px, 42dvh, 300px), 60vw);
  pointer-events: none;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.25));
  animation: ninja-bob 2.8s ease-in-out infinite;
  z-index: 1;
}
@keyframes ninja-bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-8px) rotate(-1.5deg); }
}

.menu-footer {
  position: absolute;
  left: calc(20px + env(safe-area-inset-left));
  right: calc(20px + env(safe-area-inset-right));
  bottom: max(2dvh, calc(10px + env(safe-area-inset-bottom)));
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 2;
}

.icon-btn {
  width: 46px;
  height: 46px;
  border: 3px solid #111;
  border-radius: 12px;
  background: #fff;
  font-size: 22px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25); }

.menu-url {
  margin-left: auto;
  font-weight: 700;
  opacity: 0.45;
  letter-spacing: 0.04em;
}

/* ============================== GAME ============================== */

.stage {
  position: fixed;
  inset: 0;
  touch-action: none;
  cursor: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.countdown-num {
  font-size: clamp(90px, 24dvh, 180px);
  font-weight: 900;
  color: #111;
  text-shadow:
    -4px -4px 0 #fff, 4px -4px 0 #fff, -4px 4px 0 #fff, 4px 4px 0 #fff,
    0 10px 18px rgba(0, 0, 0, 0.25);
  animation: count-pop 0.65s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}

.countdown--go .countdown-num {
  color: var(--accent);
  animation: go-flash 0.5s ease-out both;
}

@keyframes count-pop {
  from { transform: scale(1.8); opacity: 0; }
  40% { transform: scale(1); opacity: 1; }
}
@keyframes go-flash {
  from { transform: scale(0.6); opacity: 0; }
  30% { transform: scale(1.15); opacity: 1; }
  to { transform: scale(1); opacity: 0; }
}

/* ============================ OVERLAYS ============================ */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(17, 17, 17, 0.45);
  backdrop-filter: blur(3px);
  z-index: 10;
}

.panel {
  width: min(420px, 94vw);
  max-height: 92dvh;
  overflow-y: auto;
  background: #fff;
  border: 4px solid #111;
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.3);
  text-align: center;
  animation: panel-pop 0.25s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
@keyframes panel-pop {
  from { transform: scale(0.85) translateY(20px); opacity: 0; }
}

.panel h2 { font-size: 26px; font-weight: 900; margin-bottom: 8px; }

.go-score {
  font-size: clamp(56px, 12dvh, 84px);
  font-weight: 900;
  line-height: 1;
  color: var(--accent);
}
.go-sub { font-weight: 600; opacity: 0.7; margin: 6px 0 12px; min-height: 1.2em; }
.go-sub .record { color: var(--gold); }

.go-name input {
  width: 70%;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  text-align: center;
  border: 3px solid #111;
  border-radius: 12px;
  margin-bottom: 14px;
}

.panel-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  border: 3px solid #111;
  border-radius: 12px;
  padding: 10px 18px;
  font-weight: 800;
  font-size: 17px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
  text-decoration: none;
  display: inline-block;
  color: #111;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25); }
.btn--black { background: #111; color: #fff; }
.btn--red { background: var(--accent); color: #fff; }
.btn--white { background: #fff; color: #111; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

.share-status { margin-top: 16px; }
.share-status-bar {
  height: 10px;
  border: 2px solid #111;
  border-radius: 6px;
  overflow: hidden;
  background: #eee;
}
#go-share-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}
#go-share-msg { font-weight: 600; font-size: 14px; margin-top: 6px; opacity: 0.75; }
.share-link { display: flex; gap: 8px; margin-top: 10px; }
.share-link input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  border: 3px solid #111;
  border-radius: 10px;
}

/* ========================= RANKS / AUTH / AC ====================== */

.rank-card {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 12px;
  padding: 10px 14px;
  border: 3px solid var(--tier, #111);
  border-radius: 16px;
  background: linear-gradient(120deg, #fff 60%, color-mix(in srgb, var(--tier, #111) 18%, #fff));
  text-align: left;
}
.rank-info { flex: 1; min-width: 0; }
.rank-label { font-size: 12px; font-weight: 700; opacity: 0.55; }
.rank-tier { font-size: 22px; font-weight: 900; letter-spacing: 0.04em; color: var(--tier, #111); }
.rank-next { font-size: 11px; font-weight: 600; opacity: 0.55; }
.rank-claim { padding: 8px 16px; }
.rank-claimed { font-weight: 800; font-size: 13px; color: #1e8a44; text-align: right; }

.auth-tabs { margin-bottom: 14px; }
.auth-switch {
  display: block;
  margin: 6px auto 0;
  background: none;
  border: none;
  font: inherit;
  font-weight: 800;
  color: #111;
  text-decoration: underline;
  cursor: pointer;
}
.auth-sub { font-weight: 600; opacity: 0.7; margin-bottom: 12px; }
.auth-err { color: var(--accent); font-weight: 700; font-size: 14px; margin: 6px 0; }
.auth-dev {
  background: #fff6dd;
  border: 2px dashed #c28d1a;
  border-radius: 10px;
  padding: 8px;
  font-size: 14px;
  margin-bottom: 10px;
}
.auth-code { font-size: 26px !important; letter-spacing: 0.35em; font-weight: 900 !important; }

.profile-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 3px solid #111;
  border-radius: 12px;
  background: #fff;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
  max-width: 40vw;
}
.profile-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-chip--in { background: #111; color: #fff; }
.profile-chip:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25); }

/* leaderboard ghosts & profile */
.ghost { opacity: 0.55; font-weight: 600; }
.board-name {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 800;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
  cursor: pointer;
}

/* immersive full-page profile */
.profile-page {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow-y: auto;
  background:
    radial-gradient(ellipse 120% 55% at 50% -8%, color-mix(in srgb, var(--tier, #888) 34%, transparent), transparent 70%),
    repeating-conic-gradient(var(--check) 0% 25%, transparent 0% 50%) 0 0 / 56px 56px,
    var(--bg);
  padding: 0 20px calc(48px + env(safe-area-inset-bottom));
}
.pp-bar {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(14px + env(safe-area-inset-top)) 0 8px;
  z-index: 2;
}
.pp-signout { padding: 8px 14px; font-size: 14px; }
.pp-hero { text-align: center; margin-top: 2dvh; }
.pp-badge {
  display: inline-block;
  filter: drop-shadow(0 10px 22px color-mix(in srgb, var(--tier, #888) 55%, transparent));
  animation: pp-drop 0.5s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
@keyframes pp-drop { from { transform: translateY(-26px) scale(0.8); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .pp-badge { animation: none; } }
.pp-tier-name {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.28em;
  color: var(--tier, #888);
  margin-top: 6px;
  text-shadow: 0 1px 0 #fff;
}
.pp-name {
  font-size: clamp(34px, 8vw, 52px);
  font-weight: 900;
  margin: 4px 0 0;
  line-height: 1.05;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  text-shadow: -2px -2px 0 #fff, 2px -2px 0 #fff, -2px 2px 0 #fff, 2px 2px 0 #fff;
}
.pp-meta { font-weight: 700; opacity: 0.55; margin-top: 6px; }
.pp-err { color: var(--accent); font-weight: 800; margin-top: 30px; }
.pp-rename { max-width: 340px; margin: 8px auto 0; }

.pp-section { max-width: 640px; margin: 40px auto 0; }
.pp-h2 {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.5;
  margin: 0 0 12px;
}
.pp-ranks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.pp-rank-card {
  background: #fff;
  border: 3px solid var(--tier, #d9d9d9);
  border-radius: 18px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
  padding: 18px 12px 14px;
  text-align: center;
}
.pp-rank-mode {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.5;
  margin-top: 8px;
}
.pp-rank-tier { font-size: 19px; font-weight: 900; letter-spacing: 0.05em; color: var(--tier, #888); }
.pp-rank-best { font-size: 15px; font-weight: 800; margin-top: 6px; }
.pp-rank-avg { font-size: 12.5px; font-weight: 700; color: #b57f00; }
.pp-rank-next { font-size: 11.5px; font-weight: 600; opacity: 0.5; margin-top: 4px; }
.pp-unranked { color: #9a9a9a; }

.pp-tabs { justify-content: flex-start; }
.pp-chart-card {
  background: #fff;
  border: 3px solid #111;
  border-radius: 18px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
  padding: 12px;
  margin-top: 10px;
}
.pp-chart-card .stats-chart { border: none; margin: 0; height: 170px; }

.profile-panel { text-align: left; }
.profile-head { display: flex; align-items: center; gap: 12px; }
.profile-name { margin: 0; font-size: 24px; display: flex; align-items: center; gap: 8px; }
.rename-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  opacity: 0.6;
}
.rename-btn:hover { opacity: 1; }
.rename-form { display: flex; gap: 6px; align-items: center; }
.rename-form input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  font: inherit;
  font-weight: 800;
  border: 3px solid #111;
  border-radius: 10px;
}
.rename-form .btn { padding: 7px 12px; font-size: 14px; }
.profile-meta { font-size: 13px; font-weight: 600; opacity: 0.55; }
.profile-bests {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0 6px;
}
.pb-cell {
  flex: 1 1 110px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 2px solid var(--cell-border, #d9d9d9);
  border-radius: 12px;
  padding: 8px 10px;
}
.pb-mode { font-size: 11px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.55; }
.pb-score { font-size: 19px; font-weight: 900; line-height: 1.1; }
.pb-avg { font-size: 11px; font-weight: 700; color: #b57f00; }
.perf-empty { text-align: center; font-weight: 600; opacity: 0.5; padding: 22px 0; font-size: 14px; }
.profile-panel .board-tabs { justify-content: flex-start; margin: 10px 0 4px; }
.profile-panel .panel-actions { justify-content: flex-end; margin-top: 12px; }

.ac-overlay { z-index: 40; }
.ac-box {
  width: min(480px, 96vw);
  background: #fff;
  border: 4px solid #111;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.3);
}
.ac-head { padding: 12px 16px; font-size: 14px; border-bottom: 3px solid #111; }
.ac-canvas {
  display: block;
  width: 100%;
  height: min(60dvh, 460px);
  touch-action: none;
  cursor: crosshair;
}

.stats-chart {
  display: block;
  width: 100%;
  height: 130px;
  margin: 4px 0 10px;
  border: 2px solid #eee;
  border-radius: 12px;
}

.mini-board { margin-top: 14px; text-align: left; }
.mini-board table, .share-board table { width: 100%; border-collapse: collapse; }
.mini-board td, .share-board td { padding: 6px 8px; font-weight: 600; border-bottom: 1px solid #eee; }
.mini-board td:last-child, .share-board td:last-child { text-align: right; font-weight: 900; }
.mini-board tr.me td, .share-board tr.me td { background: #fff6dd; color: #a06e00; }
.mini-board .empty { text-align: center; opacity: 0.5; font-weight: 600; padding: 12px; }

.board-tabs { display: flex; gap: 6px; justify-content: center; margin-top: 4px; }
.board-tabs button, .set-opts button {
  border: 2px solid #111;
  border-radius: 10px;
  background: #fff;
  padding: 6px 12px;
  font-weight: 700;
}
.board-tabs button.active, .set-opts button.active { background: #111; color: #fff; }
.board-reset { margin-top: 10px; font-size: 13px; font-weight: 600; opacity: 0.55; }

.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 14px 0;
  font-weight: 700;
}
.set-opts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.set-locked { font-size: 13px; font-weight: 700; opacity: 0.55; }
.set-hint { font-size: 12px; font-weight: 600; opacity: 0.5; text-align: right; margin: -8px 0 10px; }

/* =========================== SHARE PAGE =========================== */

.share-page { overflow: auto; }

.share {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  text-align: center;
}

.share-brand {
  font-size: 40px;
  font-weight: 900;
  color: #111;
  text-decoration: none;
  text-shadow: -2px -2px 0 #fff, 2px -2px 0 #fff, -2px 2px 0 #fff, 2px 2px 0 #fff;
}
.share-brand em { font-style: normal; color: var(--accent); }

.share-card {
  margin-top: 18px;
  background: #fff;
  border: 4px solid #111;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.25);
}

.share-video {
  display: block;
  width: 100%;
  max-height: 70dvh;
  object-fit: contain;
  background: #111;
}
.share-video--empty {
  display: grid;
  place-items: center;
  aspect-ratio: 9 / 12;
  font-size: 80px;
}

.share-meta { padding: 18px; }
.share-score { font-size: 64px; font-weight: 900; color: var(--accent); line-height: 1; }
.share-sub { font-weight: 700; margin: 6px 0 2px; }
.share-day { font-size: 13px; font-weight: 600; opacity: 0.5; margin-bottom: 14px; }

.share-board {
  margin-top: 22px;
  background: #fff;
  border: 4px solid #111;
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.2);
}
.share-board h2 { font-size: 18px; font-weight: 900; margin-bottom: 8px; }

/* ========================== SMALL SCREENS ========================= */

/* portrait phones with modest height (≤760px): shrink the hero content so
   title + burst + three buttons + footer always fit without overlap */
@media (orientation: portrait) and (max-height: 760px) {
  .menu-title { font-size: clamp(44px, 12dvh, 90px); }
  .burst { width: clamp(150px, 30dvh, 230px); }
  .burst span { font-size: clamp(15px, 3.2dvh, 22px); }
  .menu-btn { font-size: clamp(20px, 3.6dvh, 28px); padding: max(1.2dvh, 8px) 8px; }
  .menu-buttons { gap: max(1.2dvh, 8px); margin-bottom: max(10dvh, 70px); }
  .menu-ninja { width: clamp(140px, 40dvh, 240px); bottom: max(3dvh, 16px); }
}

@media (max-height: 720px) and (orientation: landscape) {
  .menu-title { font-size: clamp(40px, 11dvh, 80px); }
  .burst { width: clamp(160px, 30dvh, 240px); }
  .burst span { font-size: clamp(16px, 3.4dvh, 22px); }
  .menu-btn { font-size: clamp(20px, 3.8dvh, 28px); }
  .menu-ninja { width: clamp(150px, 46dvh, 300px); }
}

@media (max-height: 620px) {
  .burst-wrap { display: none; }
  .menu-title { font-size: clamp(44px, 13dvh, 80px); }
}

@media (max-width: 480px) {
  .menu-buttons { width: 74%; }
  .menu-ninja { width: min(clamp(140px, 36dvh, 220px), 52vw); right: -8%; }
  .menu-url { display: none; }
}
