/* ============================================================
   DropGrid — neon retro-arcade styling
   ============================================================ */
:root {
  --bg: #0b0e1a;
  --bg2: #131830;
  --panel: rgba(255, 255, 255, 0.06);
  --cyan: #2ee6ff;
  --magenta: #ff3df0;
  --yellow: #ffe93d;
  --green: #3dff8e;
  --text: #eaf2ff;
  --muted: #8b96b8;
  --radius: 14px;
}

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

html, body {
  height: 100%;
  /* Prevent pull-to-refresh / overscroll bounce during gameplay */
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background:
    radial-gradient(1200px 600px at 70% -10%, rgba(46, 230, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(255, 61, 240, 0.12), transparent 60%),
    var(--bg);
  /* Respect notches/home bars on phones */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app { height: 100dvh; display: flex; flex-direction: column; }

/* ---------- screens ---------- */
.screen {
  display: none;
  flex: 1;
  min-height: 0;
  align-items: center;
  justify-content: center;
}
.screen.active { display: flex; }
#screen-game.active {
  align-items: stretch;
  justify-content: stretch;
  overflow: hidden;
}

.menu-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(92vw, 460px);
  padding: 18px;
  text-align: center;
}

.logo {
  font-size: clamp(2.4rem, 9vw, 4rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--cyan);
  text-shadow: 0 0 18px rgba(46, 230, 255, 0.8), 0 0 60px rgba(46, 230, 255, 0.4);
}
.logo span {
  color: var(--magenta);
  text-shadow: 0 0 18px rgba(255, 61, 240, 0.8), 0 0 60px rgba(255, 61, 240, 0.4);
}
.tagline { color: var(--muted); margin-top: -8px; letter-spacing: 0.3em; font-size: 0.8rem; }

.screen-title {
  font-size: 1.8rem;
  letter-spacing: 0.1em;
  color: var(--yellow);
  text-shadow: 0 0 16px rgba(255, 233, 61, 0.6);
}

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  padding: 10px 18px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.08s, box-shadow 0.15s, border-color 0.15s;
  touch-action: manipulation; /* kills double-tap zoom on buttons */
}
.btn:active { transform: scale(0.95); }
.btn:hover { border-color: var(--cyan); box-shadow: 0 0 14px rgba(46, 230, 255, 0.35); }

.btn-big {
  width: 100%;
  font-size: 1.25rem;
  font-weight: 700;
  padding: 16px;
}
.btn-primary {
  background: linear-gradient(135deg, rgba(46, 230, 255, 0.25), rgba(255, 61, 240, 0.25));
  border-color: var(--cyan);
  box-shadow: 0 0 18px rgba(46, 230, 255, 0.3);
}
.btn-back { margin-top: 10px; }

.menu-toggles { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.toggle { display: flex; gap: 8px; align-items: center; color: var(--muted); cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--magenta); }

.hint { color: var(--muted); font-size: 0.78rem; line-height: 1.5; }
.developer-credit { color: var(--muted); font-size: 0.78rem; margin-top: 8px; }
.developer-credit a { color: var(--cyan); text-decoration: none; }
.developer-credit a:hover { color: var(--yellow); text-decoration: underline; }
.hidden { display: none !important; }

.coffee-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: min(92vw, 360px);
  min-height: 36px;
  padding: 8px 14px;
  color: var(--yellow);
  background: rgba(0, 0, 0, 0.52);
  border: 1px solid rgba(255, 233, 61, 0.45);
  border-radius: 999px;
  box-shadow: 0 0 18px rgba(255, 233, 61, 0.14);
  font-size: 0.86rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.08s, border-color 0.15s, box-shadow 0.15s;
}
.coffee-link:hover {
  border-color: var(--yellow);
  box-shadow: 0 0 22px rgba(255, 233, 61, 0.28);
}
.coffee-link:active { transform: scale(0.97); }
.coffee-link-game {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 6px 12px;
  font-size: 0.78rem;
}

/* ---------- versus lobby ---------- */
.vs-status { color: var(--muted); min-height: 1.4em; }
.vs-status.ok { color: var(--green); }
.vs-status.bad { color: var(--magenta); }
.join-row { display: flex; gap: 8px; width: 100%; }
.join-row input, .submit-row input {
  flex: 1;
  font: inherit;
  font-size: 1.2rem;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  padding: 10px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.submit-row input { text-transform: none; letter-spacing: normal; font-size: 1rem; }
.join-row input:focus, .submit-row input:focus { border-color: var(--cyan); }
.room-code { display: flex; flex-direction: column; align-items: center; gap: 10px; font-size: 1.1rem; }
.room-code strong { font-size: 2rem; color: var(--yellow); letter-spacing: 0.3em; }

/* ---------- game layout ---------- */
.game-layout {
  flex: 1;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 10px;
  gap: 8px;
  position: relative;
}

.game-top {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 12px;
  width: min(96vw, 620px);
  flex: 0 0 auto;
}
.side-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 4px 6px;
}
.side-label { font-size: 0.65rem; color: var(--muted); letter-spacing: 0.2em; }
.side-box canvas { width: clamp(56px, 9dvh, 84px); height: auto; }

.score-box { flex: 1; text-align: center; position: relative; }
.score-num {
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  font-weight: 900;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(46, 230, 255, 0.7);
  font-variant-numeric: tabular-nums;
}
.score-sub { display: flex; justify-content: center; gap: 16px; color: var(--muted); font-size: 0.8rem; }
.score-sub b { color: var(--text); }

.combo-pop {
  position: absolute;
  inset: auto 0 -1.4em 0;
  font-weight: 900;
  color: var(--yellow);
  text-shadow: 0 0 12px rgba(255, 233, 61, 0.8);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.combo-pop.show { opacity: 1; }

.board-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  touch-action: none; /* we handle all gestures ourselves */
}
#cv-board, #cv-fx {
  position: absolute;
  border-radius: 10px;
}
#cv-board {
  background: rgba(0, 0, 0, 0.45);
  box-shadow: 0 0 0 2px rgba(46, 230, 255, 0.25), 0 0 30px rgba(46, 230, 255, 0.15);
}
#cv-fx { pointer-events: none; }

.opp-panel {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 61, 240, 0.5);
  border-radius: 10px;
  padding: 4px;
  text-align: center;
  z-index: 5;
}
.opp-panel canvas { display: block; width: 60px; height: 120px; }
.opp-status { font-size: 0.6rem; color: var(--magenta); }

.net-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid var(--yellow);
  border-radius: 10px;
  padding: 6px 14px;
  font-size: 0.85rem;
  z-index: 6;
}

.pause-overlay, .countdown {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(11, 14, 26, 0.85);
  z-index: 10;
  border-radius: 10px;
}
.countdown {
  font-size: 6rem;
  font-weight: 900;
  color: var(--yellow);
  text-shadow: 0 0 30px rgba(255, 233, 61, 0.8);
  background: transparent;
  pointer-events: none;
}

.btn-pause {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 6;
  font-size: 1rem;
  background: var(--panel);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

/* ---------- touch controls ---------- */
.touch-controls {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: min(96vw, 520px);
}
.tbtn {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--text);
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  padding: 14px 0;
  cursor: pointer;
  touch-action: none;
}
.tbtn:active { background: rgba(46, 230, 255, 0.25); border-color: var(--cyan); }
.tbtn-wide { grid-column: span 5; font-size: 1.1rem; padding: 12px 0; letter-spacing: 0.2em; }

/* Hide touch buttons on devices with a fine pointer (mouse) and wide screens */
@media (pointer: fine) and (min-width: 900px) {
  .touch-controls { display: none; }
  .game-layout { padding: 14px; }
  .game-top {
    position: absolute;
    inset: 14px 0 auto 0;
    z-index: 4;
    width: min(96vw, 760px);
    margin: 0 auto;
    pointer-events: none;
  }
  .game-top .side-box { pointer-events: auto; }
}

/* ---------- game over / share ---------- */
#cv-card {
  width: min(92vw, 420px);
  height: auto;
  border-radius: var(--radius);
  box-shadow: 0 0 30px rgba(46, 230, 255, 0.25);
}
.submit-row { display: flex; gap: 8px; width: 100%; }
.share-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.end-row { display: flex; gap: 8px; width: 100%; flex-wrap: wrap; }
.end-row .btn-big { flex: 1; min-width: 130px; }

.coffee-link-featured {
  width: 100%;
  min-height: 48px;
  padding: 12px 22px;
  font-size: 1.05rem;
  background: linear-gradient(135deg, rgba(255, 233, 61, 0.18), rgba(46, 230, 255, 0.16)), rgba(0, 0, 0, 0.7);
  border-color: var(--yellow);
  box-shadow: 0 0 28px rgba(255, 233, 61, 0.32), 0 0 18px rgba(46, 230, 255, 0.16);
}

/* ---------- leaderboard ---------- */
.lb-list {
  width: 100%;
  max-height: 55dvh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 10px;
  font-variant-numeric: tabular-nums;
}
.lb-row {
  display: grid;
  grid-template-columns: 2.2em 1fr auto auto;
  gap: 10px;
  padding: 7px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  text-align: left;
  align-items: baseline;
}
.lb-row:nth-child(1) .lb-rank { color: var(--yellow); }
.lb-row:nth-child(2) .lb-rank { color: #cfd8ea; }
.lb-row:nth-child(3) .lb-rank { color: #d8a35a; }
.lb-rank { font-weight: 900; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 700; color: var(--cyan); }
.lb-date { color: var(--muted); font-size: 0.75rem; }

/* ---------- landscape phones: tighten vertical space ---------- */
@media (orientation: landscape) and (max-height: 480px) {
  .game-top { width: auto; position: absolute; left: 8px; top: 8px; flex-direction: column; z-index: 4; }
  .touch-controls {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 130px;
    grid-template-columns: 1fr 1fr;
  }
  .tbtn-wide { grid-column: span 2; }
  .coffee-link-game { position: absolute; left: 8px; bottom: calc(env(safe-area-inset-bottom) + 6px); z-index: 4; font-size: 0.72rem; min-height: 28px; padding: 5px 9px; }
}
