:root {
  --ink: #111418;
  --muted: #4b5563;
  --surface: #fdfdf6;
  --surface-alt: #f0f2e6;
  --border: #111418;
  --sky: #5bc0eb;
  --green: #64c828;
  --green-dark: #429414;
  --yellow: #ffd43b;
  --yellow-dark: #d9a404;
  --blue: #1d9bf0;
  --red: #e63946;
  --teal: #0b8a62;
  --font-pixel: "Press Start 2P", monospace;
  --font-ui: "Chakra Petch", -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

input {
  user-select: text;
  -webkit-user-select: text;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--sky);
  font-family: var(--font-ui);
  color: var(--ink);
  touch-action: none;
}

/* Full-Viewport Zero-Stretch Stage (Spacious on Desktop, Edge-to-Edge on Mobile!) */
#game-shell {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: var(--sky);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* Crisp 8-Bit Top Controls */
#top-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 30;
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 0;
  border: 3px solid var(--ink);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.06s steps(2);
}

@media (max-width: 460px) {
  #top-controls {
    top: 10px;
    right: 10px;
    gap: 5px;
  }
  .icon-btn {
    width: 34px;
    height: 34px;
    border-width: 2.5px;
    box-shadow: 2px 2px 0 var(--ink);
  }
  .icon-btn.lang-btn {
    padding: 0 7px;
    font-size: 9.5px;
  }
}

.icon-btn.lang-btn {
  width: auto;
  padding: 0 10px;
  font-family: var(--font-pixel);
  font-size: 11px;
}

.icon-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.icon-btn.muted {
  background: #d9dce0;
  opacity: 0.65;
}

.ui-svg {
  width: 19px;
  height: 19px;
  display: block;
}

.inline-svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: block;
}

.heart-svg {
  width: 15px;
  height: 15px;
  color: var(--red);
  margin-top: 2px;
}

.mini-identicon {
  width: 22px;
  height: 22px;
  border: 2px solid var(--ink);
  display: inline-flex;
  flex-shrink: 0;
}

/* Airy Open-Sky Pixel Start Screen */
.start-screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: clamp(68px, 11vh, 110px) 24px clamp(96px, 14vh, 136px);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.16s linear;
}

.start-screen.visible {
  opacity: 1;
  pointer-events: auto;
}

.start-top {
  text-align: center;
}

.hero-title {
  font-family: var(--font-pixel);
  font-size: clamp(22px, 5vw, 38px);
  line-height: 1.3;
  color: #ffffff;
  text-shadow:
    3px 0 0 var(--ink), -3px 0 0 var(--ink),
    0 3px 0 var(--ink), 0 -3px 0 var(--ink),
    3px 3px 0 var(--ink), 5px 5px 0 rgba(17, 20, 24, 0.35);
  margin-bottom: 14px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.x-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: #ffffff;
  width: clamp(36px, 6vw, 48px);
  height: clamp(36px, 6vw, 48px);
  border: 3px solid #ffffff;
  outline: 3px solid var(--ink);
  box-shadow: 4px 4px 0 rgba(17, 20, 24, 0.45);
}

.x-logo-svg {
  width: 60%;
  height: 60%;
  display: block;
}

.hero-sub {
  display: inline-block;
  background: var(--ink);
  color: var(--yellow);
  border: 2px solid #ffffff;
  box-shadow: 3px 3px 0 var(--ink);
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  padding: 6px 14px;
}

.start-bottom {
  width: 100%;
  max-width: 296px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.best-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 3px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 700;
}

.tap-hint {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(253, 253, 246, 0.9);
  border: 2px solid var(--ink);
  padding: 4px 10px;
}

/* Authentic 8-Bit Tactile Pixel Buttons */
.pixel-btn {
  width: 100%;
  padding: 13px 14px;
  border-radius: 0;
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.06s steps(2);
}

.pixel-btn:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--ink);
}

.btn-hero {
  padding: 15px 18px;
  font-size: 17px;
}

.btn-green {
  background: var(--green);
  color: #ffffff;
  text-shadow: 2px 2px 0 var(--green-dark);
}

.btn-yellow {
  background: var(--yellow);
  color: var(--ink);
  font-size: 13.5px;
  padding: 10px 8px;
}

.btn-black {
  background: var(--ink);
  color: #ffffff;
  font-size: 13.5px;
  padding: 10px 8px;
}

.hidden {
  display: none !important;
}

/* Retro Pixel Overlays */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(17, 20, 24, 0.54);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s linear;
}

.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.pixel-card {
  width: 100%;
  max-width: 372px;
  background: var(--surface);
  border: 4px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
  border-radius: 0;
  padding: 18px 16px 16px;
  text-align: center;
}

.cause-pill {
  display: inline-block;
  background: #ffe3e3;
  color: #b91c1c;
  border: 2px solid var(--ink);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cause-pill.win {
  background: var(--yellow);
  color: var(--ink);
}

.dota-title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 5px;
  color: var(--ink);
}

.roast-copy {
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
  margin-bottom: 12px;
}

.score-bar {
  display: flex;
  align-items: stretch;
  background: var(--surface-alt);
  border: 3px solid var(--ink);
  margin-bottom: 10px;
}

.score-main {
  flex: 1;
  background: var(--ink);
  color: var(--yellow);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
}

.score-lbl {
  font-family: var(--font-pixel);
  font-size: 8.5px;
  opacity: 0.8;
}

.score-big {
  font-family: var(--font-pixel);
  font-size: 22px;
  line-height: 1.2;
}

.score-divider {
  width: 3px;
  background: var(--ink);
}

.score-meta {
  flex: 1.18;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.meta-row strong {
  color: var(--ink);
  font-weight: 700;
}

.meta-row .rank-txt {
  color: var(--teal);
  font-size: 11.5px;
}

/* Optional Opt-In Handle Box */
.optin-box {
  background: var(--surface-alt);
  border: 2px solid var(--ink);
  padding: 8px 10px;
  margin-bottom: 10px;
  text-align: left;
}

.optin-label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
}

.optin-row {
  display: flex;
  gap: 6px;
}

.optin-row input {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  border: 2px solid var(--ink);
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink);
  background: #ffffff;
}

.optin-save, .optin-skip {
  height: 32px;
  padding: 0 10px;
  border: 2px solid var(--ink);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.optin-save {
  background: var(--blue);
  color: #ffffff;
}

.optin-skip {
  background: #e5e7eb;
  color: var(--ink);
}

.mutuals-line {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  background: #fff9db;
  border: 2px solid var(--ink);
  padding: 7px 9px;
  margin-bottom: 12px;
  text-align: left;
}

.mutuals-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.mutual-tag {
  background: #ffffff;
  border: 1.5px solid var(--ink);
  padding: 1px 6px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ink);
}

.action-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Pixel Leaderboard Modal */
.lb-card {
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.lb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.lb-title {
  font-family: var(--font-ui);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.lb-close {
  width: 32px;
  height: 32px;
  border: 2px solid var(--ink);
  background: var(--surface-alt);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.lb-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.lb-tab {
  padding: 8px;
  border: 2px solid var(--ink);
  background: var(--surface-alt);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.flag-svg {
  width: 20px;
  height: 14px;
  border: 1.5px solid var(--ink);
  flex-shrink: 0;
  display: block;
}

.flag-mini {
  width: 16px;
  height: 11px;
  border: 1px solid var(--ink);
  display: inline-block;
  vertical-align: -1px;
  margin-right: 4px;
}

.lb-tab.active {
  background: var(--ink);
  color: var(--yellow);
}

.lb-stats {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
}

.lb-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 340px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  background: var(--surface-alt);
  border: 2px solid var(--ink);
  text-align: left;
}

.lb-row.me {
  background: #fff9db;
}

.lb-rank {
  width: 28px;
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  flex-shrink: 0;
}

.lb-row:nth-child(1) .lb-rank { color: #d97706; }
.lb-row:nth-child(2) .lb-rank { color: #475569; }
.lb-row:nth-child(3) .lb-rank { color: #b45309; }

.lb-avatar {
  width: 28px;
  height: 28px;
  border: 2px solid var(--ink);
  overflow: hidden;
  flex-shrink: 0;
}

.lb-info {
  flex: 1;
  min-width: 0;
}

.lb-handle {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-sub {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--muted);
}

.lb-score {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--ink);
  flex-shrink: 0;
}

.lb-me {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 2px dashed var(--ink);
}

.pixel-toast {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  background: var(--ink);
  color: var(--yellow);
  border: 2px solid #ffffff;
  box-shadow: 3px 3px 0 var(--ink);
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  max-width: 92%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.made-by-link {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.2px;
  color: rgba(17, 20, 24, 0.7);
  text-align: center;
  max-width: 340px;
}

.made-by-link a {
  color: var(--ink);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.made-by-link a:hover {
  color: var(--blue);
}

.start-credit {
  margin-top: 2px;
  background: rgba(253, 253, 246, 0.78);
  padding: 4px 10px;
}

.go-credit {
  margin-top: 10px;
  color: #6b7280;
}

.bot-card {
  max-width: 360px;
  border-color: var(--red);
}

.bot-pill {
  background: var(--red);
  color: #ffffff;
}
