:root {
  --ink: #080808;
  --paper: #fffef7;
  --green: #74e49a;
  --purple: #9187e3;
  --blue: #0900e4;
  --shadow: 0 8px 0 rgba(0,0,0,.92);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-height: 100svh;
  color: var(--ink);
  font-family: Arial Black, Impact, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background-color: var(--green);
  background-image: url('/assets/background.png');
  background-repeat: repeat;
  background-size: 960px 540px;
  overflow-x: hidden;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 1080px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 98px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.logo {
  grid-column: 2;
  width: min(390px, 64vw);
  max-height: 105px;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
  filter: drop-shadow(0 5px 0 rgba(0,0,0,.12));
}

.icon-button {
  grid-column: 3;
  justify-self: end;
  width: 48px;
  height: 48px;
  border: 4px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.icon-button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

.game {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.score-wrap {
  text-align: center;
  margin-top: 4px;
  margin-bottom: -4px;
  position: relative;
  z-index: 2;
}

.score {
  font-size: clamp(44px, 8vw, 86px);
  line-height: .9;
  letter-spacing: -0.05em;
  text-shadow: 3px 3px 0 rgba(255,255,255,.8);
}

.score-label {
  font-size: clamp(13px, 2vw, 18px);
  letter-spacing: .18em;
  margin-top: 6px;
}

.degen-button {
  position: relative;
  display: grid;
  place-items: center;
  width: min(500px, 82vw);
  height: min(46svh, 500px);
  min-height: 260px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  outline: none;
}

.degen-button:focus-visible::after {
  content: "";
  position: absolute;
  inset: 8%;
  border: 5px dashed var(--blue);
  border-radius: 32px;
}

.degen-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: 50% 78%;
  transition: transform 70ms ease;
  filter: drop-shadow(0 9px 0 rgba(0,0,0,.12));
}

.degen-button.is-down .degen-image { transform: scale(.985) translateY(5px); }

.pop-burst {
  position: absolute;
  top: 28%;
  right: 19%;
  font-size: clamp(28px, 5vw, 52px);
  color: var(--paper);
  -webkit-text-stroke: 4px var(--ink);
  paint-order: stroke fill;
  opacity: 0;
  transform: translateY(12px) rotate(8deg) scale(.6);
  pointer-events: none;
}

.pop-burst.animate { animation: popBurst 380ms ease-out; }

@keyframes popBurst {
  0% { opacity: 0; transform: translateY(16px) rotate(8deg) scale(.5); }
  25% { opacity: 1; transform: translateY(0) rotate(-4deg) scale(1.12); }
  100% { opacity: 0; transform: translateY(-48px) rotate(-9deg) scale(.9); }
}

.hint {
  margin: -4px 0 14px;
  font-size: 14px;
  letter-spacing: .16em;
  opacity: .72;
}

.actions {
  display: contents;
}

/* Leaderboard - top left */
#leaderboardButton {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 10;
}

/* X + OpenSea - small icons bottom right */
.actions a.action-button {
  position: fixed;
  bottom: 20px;
  z-index: 10;

  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  border-radius: 50%;

  font-size: 0;
}

.actions a.action-button .action-mark {
  font-size: 20px;
}

.actions a[href*="x.com"] {
  right: 76px;
}

.actions a[href*="opensea.io"] {
  right: 20px;
}

.action-button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 17px;
  border: 4px solid var(--ink);
  border-radius: 15px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 5px 0 var(--ink);
  text-decoration: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.action-button:hover { transform: translateY(-1px); }
.action-button:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.action-primary { background: #ffe968; }
.action-mark { font-size: 18px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  padding: 20px;
  background: rgba(0,0,0,.56);
  display: grid;
  place-items: center;
  backdrop-filter: blur(5px);
}
.modal-backdrop[hidden] { display: none; }

.modal {
  width: min(560px, 100%);
  max-height: min(760px, 92svh);
  overflow: auto;
  background: var(--paper);
  border: 5px solid var(--ink);
  border-radius: 24px;
  box-shadow: 0 12px 0 var(--ink);
  padding: 22px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 4px solid var(--ink);
  padding-bottom: 15px;
}

.eyebrow { font-size: 11px; letter-spacing: .2em; opacity: .62; }
.modal h1 { margin: 2px 0 0; font-size: clamp(30px, 7vw, 48px); line-height: .9; letter-spacing: -.04em; }

.close-button {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  font-size: 30px;
  line-height: 30px;
}

.connection-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 14px 0 8px;
}

.badge {
  display: inline-block;
  padding: 5px 9px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: .12em;
  background: #eee;
}
.badge.live { background: #b7ffbf; }
.badge.local { background: #ffe6a6; }
.badge.error { background: #ffb3b3; }

.text-button {
  border: 0;
  background: transparent;
  cursor: pointer;
  text-decoration: underline;
  font-size: 12px;
}

.leaderboard-list {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: rank;
}

.leaderboard-item {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 7px 6px;
  border-bottom: 2px solid rgba(0,0,0,.12);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 800;
}

.rank { font-family: Arial Black, Impact, sans-serif; font-size: 18px; }
.player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-score { font-variant-numeric: tabular-nums; }

.empty-state {
  margin: 18px 0;
  padding: 20px;
  border: 3px dashed rgba(0,0,0,.35);
  border-radius: 14px;
  text-align: center;
  font-family: system-ui, sans-serif;
  font-weight: 700;
}

.score-form {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 4px solid var(--ink);
}
.score-form label { display: block; margin-bottom: 8px; font-size: 13px; letter-spacing: .05em; }
.submit-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.submit-row input {
  min-width: 0;
  height: 48px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 0 13px;
  background: #fff;
  font-family: system-ui, sans-serif;
  font-weight: 800;
}
.submit-row button {
  height: 48px;
  padding: 0 16px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #ffe968;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
}
.submit-row button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.submit-row button:disabled { opacity: .55; cursor: wait; }
.form-help, .form-status { margin-top: 7px; font-family: system-ui, sans-serif; font-size: 11px; font-weight: 700; }
.form-help { opacity: .55; }
.form-status { min-height: 16px; }
.form-status.success { color: #08701d; }
.form-status.error { color: #a40000; }

body.modal-open { overflow: hidden; }

@media (max-width: 560px) {
  .app-shell { padding-left: 10px; padding-right: 10px; }
  .topbar { min-height: 78px; }
  .logo { width: min(310px, 69vw); max-height: 82px; }
  .icon-button { width: 42px; height: 42px; border-width: 3px; box-shadow: 0 3px 0 var(--ink); }
  .degen-button { width: 96vw; height: min(54svh, 520px); min-height: 300px; }
  .action-button { min-height: 44px; padding: 8px 12px; border-width: 3px; border-radius: 12px; box-shadow: 0 4px 0 var(--ink); font-size: 12px; }
  .modal-backdrop { padding: 10px; align-items: end; }
  .modal { width: 100%; max-height: 88svh; border-radius: 22px 22px 8px 8px; border-width: 4px; box-shadow: 0 8px 0 var(--ink); }
  .submit-row { grid-template-columns: 1fr; }
  .submit-row button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

/* ===== OKDEGEN FINAL CONTROL LAYOUT ===== */

/* Move character slightly right so it lines up with POPS counter */
.degen-button {
  position: relative;
  left: 24px;
}

/* Leaderboard stays top left */
#leaderboardButton {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 20;
}

/* Volume + X + OpenSea row underneath leaderboard */
.small-controls {
  position: fixed;
  top: 82px;
  left: 20px;
  z-index: 20;

  display: flex;
  align-items: center;
  gap: 8px;
}

/* Small round icon buttons */
.small-icon-button {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;

  padding: 0;
  margin: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  border: 3px solid #080808;
  border-radius: 50%;
  background: #fffef7;
  color: #080808;
  box-shadow: 0 4px 0 #080808;

  text-decoration: none;
  cursor: pointer;
  line-height: 1;
}

/* Center volume icon */
.small-icon-button #muteIcon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}

/* Center image icons */
.small-icon-button img {
  display: block;
  width: 21px;
  height: 21px;
  object-fit: contain;
  margin: 0;
}

/* Slightly larger OpenSea icon */
.small-icon-button[href*="opensea.io"] img {
  width: 24px;
  height: 24px;
}

/* Remove old bottom-right positioning */
.actions a.action-button {
  position: static;
}

/* Mobile adjustment */
@media (max-width: 560px) {
  .degen-button {
    left: 12px;
  }

  #leaderboardButton {
    top: 12px;
    left: 12px;
  }

  .small-controls {
    top: 70px;
    left: 12px;
  }

  .small-icon-button {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
  }
}

/* ===== MOBILE VERSION ===== */

@media (max-width: 700px) {

  body {
    overflow-x: hidden;
  }

  .app-shell {
    width: 100%;
    min-height: 100dvh;
    padding: 8px 8px 18px;
  }

  /* Smaller centered logo */
  .topbar {
    min-height: 64px;
  }

  .logo {
    width: min(220px, 55vw);
    max-height: 64px;
  }

  /* Leaderboard top-left */
  #leaderboardButton {
    top: 10px;
    left: 10px;

    min-height: 40px;
    padding: 7px 10px;

    font-size: 11px;
    border-width: 3px;
    box-shadow: 0 3px 0 #080808;
  }

  /* Volume / X / OpenSea */
  .small-controls {
    top: 59px;
    left: 10px;
    gap: 6px;
  }

  .small-icon-button {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;

    border-width: 3px;
    box-shadow: 0 3px 0 #080808;
  }

  .small-icon-button img {
    width: 18px;
    height: 18px;
  }

  .small-icon-button[href*="opensea.io"] img {
    width: 20px;
    height: 20px;
  }

  .small-icon-button #muteIcon {
    font-size: 16px;
  }

  /* Give controls some breathing room */
  .game {
    justify-content: flex-start;
    padding-top: 45px;
  }

  /* Score */
  .score-wrap {
    margin-top: 0;
    margin-bottom: 0;
  }

  .score {
    font-size: clamp(42px, 12vw, 64px);
  }

  .score-label {
    font-size: 12px;
    margin-top: 4px;
  }

  /* Character centered properly on phone */
  .degen-button {
    left: 0;
    width: 96vw;
    height: min(54dvh, 500px);
    min-height: 280px;
    margin: 0 auto;
  }

  .degen-image {
    object-position: center bottom;
  }

  /* Leaderboard popup */
  .modal-backdrop {
    padding: 8px;
  }

  .modal {
    width: 100%;
    max-height: 88dvh;
    padding: 16px;
  }
}

/* ===== MOBILE CLEANUP V2 ===== */

@media (max-width: 700px) {

  /* Reserve space at the top for the controls */
  .topbar {
    min-height: 165px;
    padding-top: 105px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
  }

  /* Logo sits below the controls instead of behind them */
  .logo {
    width: min(260px, 62vw);
    max-height: 70px;
    margin: 0 auto;
  }

  /* Leaderboard */
  #leaderboardButton {
    top: 12px;
    left: 12px;
    min-height: 42px;
    padding: 8px 12px;
    font-size: 12px;
  }

  /* Sound / X / OpenSea directly underneath */
  .small-controls {
    top: 66px;
    left: 12px;
    gap: 7px;
  }

  .small-icon-button {
    width: 39px;
    height: 39px;
    min-width: 39px;
    min-height: 39px;
  }

  .small-icon-button img {
    width: 19px;
    height: 19px;
  }

  .small-icon-button[href*="opensea.io"] img {
    width: 22px;
    height: 22px;
  }

  /* Pull score closer to logo */
  .game {
    padding-top: 0;
    justify-content: flex-start;
  }

  .score-wrap {
    margin-top: 4px;
    margin-bottom: 8px;
  }

  /* Make character fit a phone screen better */
  .degen-button {
    left: 0;
    width: 90vw;
    height: min(48dvh, 470px);
    min-height: 300px;
    margin: 0 auto;
  }

  .degen-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center top;
  }
}

/* ===== MOBILE CHARACTER POSITION FINAL ===== */

@media (max-width: 700px) {

  .degen-button {
    /* slightly smaller */
    width: 82vw;
    height: min(44dvh, 430px);
    min-height: 270px;

    /* center under POPS, accounting for the hand */
    left: 18px;

    /* move character lower */
    margin-top: 24px;
    transform: translateY(45px);
  }

  .degen-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center bottom;
  }
}
