* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', sans-serif;
}

@media (max-width: 768px) {
  body::before {
    content: "Tappy Nerd is not available on phone.";
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw; height: 100vh;
    background: white;
    color: #000;
    font-family: 'Inter', sans-serif;
    font-size: 24px;
    font-weight: 600;
    text-align: center;
    z-index: 999999;
    padding: 20px;
    box-sizing: border-box;
  }
 
  body > *:not(script):not(style) {
    display: none !important;
  }
}

html, body {
  height: 100vh;
  overflow: hidden;
  background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 100%);
  color: #e8eaed;
}

#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
  background: rgba(10, 10, 10, 0.8);
  border-bottom: 1px solid rgba(0, 212, 170, 0.2);
}

#header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1240px;
  margin: 0 auto;
  padding: 1rem 0;
}

#buy-btn {
  background: linear-gradient(135deg, #00d4aa, #00ba88);
  color: #000;
  font-weight: 700;
  padding: 0.7rem 2rem;
  border-radius: 12px;
  text-decoration: none;
  font-size: 0.98rem;
  box-shadow: 0 4px 15px rgba(0, 212, 170, 0.4);
  transition: all 0.3s ease;
  margin-left: 0;
}

#buy-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 212, 170, 0.5);
}

#connect-wallet {
  background: rgba(42, 42, 62, 0.8);
  color: #e8eaed;
  border: 1px solid rgba(0, 212, 170, 0.3);
  padding: 0.6rem 1.8rem;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.95rem;
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
  text-align: center;
  min-width: 180px;
  width: 180px;
  margin-right: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  box-sizing: border-box;
}

#connect-wallet span {
  display: inline-block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1;
  text-align: center;
  flex-shrink: 0;
}

#connect-wallet:hover:not(.connected) {
  border-color: #00d4aa;
  box-shadow: 0 0 20px rgba(0, 212, 170, 0.3);
  transform: translateY(-1px);
}

#connect-wallet.connected:hover,
#connect-wallet.logout-mode {
  background: #f23645 !important;
  border-color: #f23645 !important;
  color: white !important;
  box-shadow: 0 0 20px rgba(242, 54, 69, 0.4) !important;
  width: 180px !important;
  min-width: 180px !important;
}

#game-canvas {
  display: block;
  width: 90vw;
  height: 50vh;
  max-width: 1240px;
  max-height: 600px;
  margin: 6rem auto 1rem;
  border-radius: 12px;
  border: 1px solid rgba(0, 212, 170, 0.2);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5),
              0 0 30px rgba(0, 212, 170, 0.1);
  background: #0f0f23;
  will-change: transform;
  transform: translateZ(0);
}

#footer-container {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  max-width: 1240px;
  margin: 0 auto 2rem;
}

#highscore, #chat {
  background: rgba(42, 42, 62, 0.6);
  border: 1px solid rgba(0, 212, 170, 0.2);
  border-radius: 12px;
  padding: 1.4rem;
  height: 325px;
  backdrop-filter: blur(12px);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.hs-header {
  text-align: center;
  font-weight: 600;
  font-size: 1.05rem;
  color: #e8eaed;
  margin-bottom: 1rem;
}

#timer {
  color: #00d4aa;
  font-weight: 500;
  margin-left: 0.3rem;
}

#hs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  color: #c0c8d0;
  flex: 1;
}

#hs-table td {
  padding: 0.5rem 0;
  text-align: left;
}

#hs-table td:nth-child(1) { width: 8%; color: #00d4aa; font-weight: 600; padding-right: 0.4rem; }
#hs-table td:nth-child(2) { width: 62%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#hs-table td:nth-child(3) { width: 30%; text-align: right; font-weight: 500; }
#hs-table .placeholder {
  color: rgba(136, 146, 160, 0.5);
  font-style: italic;
}

.chat-header {
  text-align: center;
  font-weight: 600;
  font-size: 1.05rem;
  color: #e8eaed;
  margin-bottom: 1rem;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 1rem;
  font-size: 0.92rem;
  color: #c0c8d0;
  line-height: 1.6;
}

#chat-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(0, 212, 170, 0.3);
  color: #e8eaed;
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 0.92rem;
  transition: border-radius .2s ease, border-color .2s ease;
  position: relative;
  z-index: 5;
  outline: none !important;
  box-shadow: none !important;
  -webkit-appearance: none;
}

#chat-input::placeholder {
  color: #8892a0;
}

#chat-input:focus {
  border-color: #00d4aa;
  outline: none !important;
  box-shadow: 0 0 0 2px rgba(0, 212, 170, 0.3) !important;
}

#chat-input.reply-active {
  border-radius: 0 0 8px 8px;
  border-top: none;
}

@media (max-width: 768px) {
  #header-content { padding: 1rem; flex-direction: column; gap: 1rem; }
  #buy-btn, #connect-wallet { width: 80%; text-align: center; }
  #footer-container { flex-direction: column; gap: 1rem; padding: 0 1rem; }
  #highscore, #chat { height: auto; min-height: 280px; }
}

#how-link {
  cursor: pointer;
  font: 600 14px Inter;
  color: #8892a0;
  margin: 0 20px;
  user-select: none;
  white-space: nowrap;
}

#how-link:hover { text-decoration: underline; }

.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  z-index: 20000;
  align-items: center;
  justify-content: center;
}

.modal.show { display: flex; }
.modal-backdrop {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(2px);
}

.modal-content {
  background: #0f0f23;
  color: #fff;
  max-width: 560px;
  width: 90%;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  position: relative;
  animation: pop 0.25s ease-out;
}

.modal-content h2 {
  margin: 0 0 16px;
  font-size: 22px;
  color: #00d4aa;
}

.modal-content p {
  margin: 16px 0;
  line-height: 1.5;
  font-size: 14px;
}

@keyframes pop {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

#previous-winner {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  font-size: 14px;
  color: #aaa;
  white-space: nowrap;
  pointer-events: none;
}

#wallet-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

#chat-messages > div {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.5rem;
  padding-right: 12px;
  overflow-wrap: break-word;
  word-break: break-word;
}

.chat-message > .content-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: 8px;
}

#chat-messages::-webkit-scrollbar {
  width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 212, 170, 0.4);
  border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 212, 170, 0.6);
}

#chat-messages {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 212, 170, 0.4) transparent;
}

#chat {
  position: relative;
  display: flex;
  flex-direction: column;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 100%;
}

.chat-message.instant {
  animation-duration: 0.32s !important;
}

.hs-row {
  animation: fadeIn 0.38s ease-out forwards;
  opacity: 0;
}

.hs-placeholder {
  opacity: 0.5 !important;
  animation: none !important;
}

#wallet-wrapper {
  position: relative;
  display: inline-block;
}

#wallet-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  width: 100%;
  background: rgba(30, 30, 45, 0.96);
  border: 1px solid rgba(0, 212, 170, 0.35);
  border-top: none;
  border-radius: 0 0 10px 10px;
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 25px rgba(0,0,0,0.45);
  overflow: hidden;
  z-index: 1000;
}

#wallet-wrapper.connected:hover #wallet-dropdown {
  display: block;
}

.dropdown-item {
  padding: 0.75rem 0;
  text-align: center;
  color: #e8eaed;
  font-size: 0.94rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.dropdown-item:hover {
  background: rgba(0, 212, 170, 0.22);
}

#logout:hover {
  color: #f23645;
}

#connect-wallet:hover,
#connect-wallet.connected:hover {
  background: rgba(42, 42, 62, 0.8) !important;
  border-color: rgba(0, 212, 170, 0.3) !important;
  color: #e8eaed !important;
  box-shadow: 0 0 20px rgba(0, 212, 170, 0.3) !important;
}

#username-modal .modal-content {
  text-align: center;
}

#username-input {
  font-family: 'Inter', sans-serif;
}

#username-input::placeholder {
  color: #8892a0;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border 0.2s ease;
}

.color-swatch:hover {
  border: 3px solid #fff;
}

.color-swatch.selected {
  border: 3px solid #fff;
  box-shadow: 0 0 12px rgba(255,255,255,0.5);
}

#username-modal .modal-content > * { box-sizing:border-box; }

#color-picker { width:100%; }

.color-rect {
  height:38px;
  border-radius:6px;
  cursor:pointer;
  border:3px solid transparent;
  transition:border .2s ease, transform .15s ease;
}

.color-rect:hover { border:3px solid #fff; transform:scale(1.05); }

.color-rect.selected {
  border:3px solid #fff;
  box-shadow:0 0 14px rgba(255,255,255,.6);
  transform:scale(1.05);
}

#set-username-btn.disabled {
  background:#555 !important;
  color:#999 !important;
  cursor:not-allowed;
  pointer-events:none;
}

#username-modal .color-picker.disabled {
  opacity: 0.4;
  pointer-events: none;
}

#username-modal .username-display {
  background: #2a2a3e !important;
  color: #ccc !important;
  border: 1px solid #444 !important;
  cursor: default !important;
  user-select: text;
  -webkit-user-select: text;
  pointer-events: none;
  caret-color: transparent !important;
}

#username-input.username-set {
  background: #2a2a3e !important;
  border: 1px solid #444 !important;
  cursor: text !important;
  pointer-events: auto !important;
  user-select: text !important;
  -webkit-user-select: text !important;
  caret-color: transparent !important;
  outline: none !important;
  color: #8892a0 !important;
  opacity: 0.75 !important;
  font-style: italic !important;
}

.admin-prefix {
  color: #ff0000;
  font-weight: 600;
  opacity: 0.75;
  margin-right: 4px;
  vertical-align: middle;
  line-height: 1;
  display: inline-block;
}

.time {
  color: #8892a0;
  font-size: 0.78rem;
  white-space: nowrap;
  margin: 0;
  flex-shrink: 0;
}

.reply-bubble strong {
  color: #00d4aa;
  font-weight: 600;
}

.reply-link {
  margin: 0;
  color: #8892a0;
  font-size: .75rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity .2s;
  white-space: nowrap;
}

.reply-link.visible { opacity: .7; }

.reply-link.visible:hover { opacity: 1; }

.reply-bubble,
#reply-preview {
  display: none;
  background: rgba(20, 20, 40, 0.85);
  border-radius: 8px 8px 0 0;
  margin: 0;
  padding: 6px 36px 6px 12px;
  color: #fff;
  font-size: 0.85rem;
  line-height: 1.4;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  position: relative;
  border: none !important;
  outline: none !important;
}

#reply-preview.show {
  display: block;
}

#reply-preview {
  background: rgba(20, 20, 40, 0.85);
  border-radius: 8px 8px 0 0;
  margin: 0 0 4px 0;
  padding: 6px 12px;
  color: #fff;
  font-size: 0.85rem;
  line-height: 1.4;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  position: relative;
}

#reply-preview .close-reply {
  right: 8px;
}

#reply-preview.show {
  display: block;
}

#reply-preview .close-reply {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  z-index: 6;
  pointer-events: auto;
}

#reply-preview .close-reply:hover {
  background: rgba(255, 255, 255, 0.15);
}

#chat-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(0, 212, 170, 0.3);
  color: #e8eaed;
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 0.92rem;
  transition: border-radius .2s ease;
  position: relative;
  z-index: 5;
  outline: none !important;
  box-shadow: none !important;
  -webkit-appearance: none;
  resize: none;
}

#chat-input::placeholder {
  color: #8892a0;
}

#chat-input:focus,
#chat-input:active {
  outline: none !important;
  box-shadow: none !important;
  border-color: rgba(0, 212, 170, 0.3) !important;
}

#chat-input.reply-active {
  border-radius: 0 0 8px 8px;
  border-top: none !important;
  margin-top: -1px;
  position: relative;
  z-index: 4;
}

#reply-preview::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(0, 212, 170, 0.15);
  pointer-events: none;
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

#chat {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.content-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.msg-left {
  flex: 1;
  min-width: 0;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: break-word;
  display: inline;
  line-height: 1.5;
}

.msg-text {
  display: inline;
  white-space: normal;
  color: #c0c8d0;
}

.chat-message,
#chat,
.content-row,
.msg-left,
.reply-bubble,
#reply-preview {
  min-width: 0;
  flex-shrink: 1;
}

.chat-message > div {
  max-width: 100%;
}

#global-best {
  text-align: center;
  font-size: 0.85rem;
  color: #8892a0;
  margin-top: 4px;
}

#best-display .username {
  font-weight: 600;
}

#left-links {
  display: flex;
  align-items: center;
  gap: 1.2rem;
}

#community-link {
  cursor: pointer;
  font: 600 14px Inter;
  color: #8892a0;
  margin: 0 20px;
  user-select: none;
  white-space: nowrap;
  text-decoration: none;
  transition: color 0.2s ease;
}
#community-link:hover {
  text-decoration: underline;
}