:root {
  font-family: 'Exo 2', system-ui, sans-serif;
  line-height: 1.5;
  font-weight: 400;
  color-scheme: dark;
  color: rgba(255, 255, 255, 0.9);
  background-color: #1a1a1a;
  --primary-color: #ff0055;
  --accent-color: #00e5ff;
  --panel-bg: rgba(20, 20, 20, 0.85);
  --panel-border: 2px solid #333;
}

body {
  margin: 0;
  display: flex;
  place-items: center;
  min-width: 320px;
  min-height: 100vh;
  background: radial-gradient(circle at center, #2a2a2a 0%, #111 100%);
}

#app-container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  height: 90vh;
}

#game-header {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  margin-bottom: 20px;
}

#game-header h1 {
  font-family: 'Russo One', sans-serif;
  font-size: 2.5em;
  line-height: 1.1;
  text-transform: uppercase;
  letter-spacing: 2px;
  background: linear-gradient(to bottom, #fff, #aaa);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 0 rgba(0,0,0,0.5));
  margin: 0;
}

.wallet-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 229, 255, 0.1);
  border: 1px solid var(--accent-color);
  color: var(--accent-color);
  font-family: 'Russo One', sans-serif;
  padding: 0.5em 1.2em;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  font-size: 0.9em;
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.2);
}

.wallet-btn:hover {
  background: rgba(0, 229, 255, 0.2);
  box-shadow: 0 0 15px rgba(0, 229, 255, 0.4);
}

/* Wallet Tooltip */
.wallet-btn-wrapper {
  position: relative;
  display: inline-block;
}

.wallet-tooltip {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.8rem;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
  z-index: 1000;
  border: 1px solid var(--accent-color);
  margin-top: 10px;
  font-family: 'Exo 2', sans-serif;
  font-weight: 500;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

.wallet-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  margin-left: -6px;
  border-width: 6px;
  border-style: solid;
  border-color: transparent transparent var(--accent-color) transparent;
}

.wallet-btn-wrapper:hover .wallet-tooltip {
  opacity: 1;
  visibility: visible;
}

h2, h3, h4 {
  font-family: 'Russo One', sans-serif;
  text-transform: uppercase;
  margin-top: 0;
  font-size: 1.2em;
}

#content-wrapper {
  display: flex;
  flex: 1;
  gap: 20px;
  height: 100%;
  width: 100%;
  min-height: 800px;
  max-height: 900px;
  min-width: 800px;
}

#game-area {
  flex: 3;
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 4px solid #333;
  box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

#sidebar {
  flex: 1;
  background: var(--panel-bg);
  padding: 20px;
  border-radius: 12px;
  text-align: left;
  border: 2px solid #444;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
}

.sidebar-panel {
  flex: 1;
  overflow-y: auto;
}

/* Sidebar Tabs */
#sidebar-tabs {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  flex-shrink: 0;
}
.sidebar-tab {
  flex: 1;
  font-family: 'Russo One', sans-serif;
  font-size: 0.7em;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 4px;
  border: 1px solid #555;
  border-radius: 6px;
  background: rgba(255,255,255,0.04);
  color: #888;
  cursor: pointer;
  transition: all 0.2s;
}
.sidebar-tab:hover {
  background: rgba(255,255,255,0.08);
  color: #ccc;
}
.sidebar-tab.active {
  background: rgba(0, 229, 255, 0.12);
  border-color: var(--accent-color);
  color: var(--accent-color);
}

/* Achievement Items */
.achievement-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid #333;
  border-radius: 4px;
  margin-bottom: 4px;
  transition: opacity 0.2s;
}
.achievement-item:last-child {
  border-bottom: none;
  margin-bottom: 0;
}
.achievement-item.locked {
  opacity: 0.35;
}
.achievement-item.unlocked {
  opacity: 1;
}
.achievement-icon {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid #555;
}
.achievement-item.unlocked .achievement-icon {
  border-color: var(--accent-color);
  box-shadow: 0 0 6px rgba(0, 229, 255, 0.3);
}
.achievement-info {
  flex: 1;
  min-width: 0;
}
.achievement-name {
  font-family: 'Russo One', sans-serif;
  font-size: 0.85em;
  color: #ccc;
}
.achievement-item.unlocked .achievement-name {
  color: #fff;
}
.achievement-desc {
  font-size: 0.75em;
  color: #777;
  margin-top: 2px;
}

#game-canvas-container {
  width: 100%;
  height: 100%;
}

#screens-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(5px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  padding: 20px;
  box-sizing: border-box;
  /* max-height: 500px; */
}

/* Custom override for start screen to show intro scene */
#start-screen {
    background: rgba(0, 0, 0, 0.4);
}

.screen.hidden {
  display: none;
}

.screen.active {
  display: flex;
}

.primary-btn {
  font-family: 'Russo One', sans-serif;
  border: none;
  padding: 0.8em 2em;
  font-size: 1.2em;
  background: linear-gradient(to bottom, #ff4444, #cc0000);
  cursor: pointer;
  transition: all 0.1s;
  color: white;
  margin-top: 30px;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-radius: 8px;
  box-shadow: 0 6px 0 #990000, 0 10px 10px rgba(0,0,0,0.3);
  text-shadow: 0 2px 0 rgba(0,0,0,0.3);
  position: relative;
  top: 0;
}

.primary-btn:hover {
  background: linear-gradient(to bottom, #ff6666, #dd0000);
  transform: translateY(-2px);
  box-shadow: 0 8px 0 #990000, 0 15px 20px rgba(0,0,0,0.4);
}

.primary-btn:active {
  top: 6px;
  box-shadow: 0 0 0 #990000, 0 0 5px rgba(0,0,0,0.4);
  transform: translateY(0);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
}

.stats-control {
  margin: 0;
  font-size: 1.2em;
  background: rgba(255,255,255,0.05);
  padding: 10px 20px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1);
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stats-control label {
    display: flex;
    align-items: center;
    width: 100%;
    justify-content: space-between;
}

.stat-name {
  position: relative;
  cursor: help;
  border-bottom: 1px dotted #888;
  white-space: nowrap;
}

.stat-tooltip {
  position: absolute;
  bottom: 100%;
  left: 0;
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.7rem;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
  z-index: 1000;
  border: 1px solid var(--accent-color);
  margin-bottom: 8px;
  font-family: 'Exo 2', sans-serif;
  font-weight: 500;
  text-transform: none;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

.stat-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 20px;
  border-width: 6px;
  border-style: solid;
  border-color: var(--accent-color) transparent transparent transparent;
}

.stat-name:hover .stat-tooltip {
  opacity: 1;
  visibility: visible;
}

.stats-control input {
  margin: 0 15px;
  flex: 1;
}

/* Range Input Styling */
input[type=range] {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: var(--accent-color);
  cursor: pointer;
  margin-top: -8px;
  box-shadow: 0 0 10px var(--accent-color);
}
input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  cursor: pointer;
  background: #555;
  border-radius: 2px;
}

.leaderboard-item {
  padding: 12px;
  border-bottom: 1px solid #444;
  background: rgba(0,0,0,0.2);
  margin-bottom: 4px;
  border-radius: 4px;
}
.leaderboard-item:last-child {
  border-bottom: none;
  margin-bottom: 0;
}
.leaderboard-item .rank {
  font-family: 'Russo One', sans-serif;
  color: var(--accent-color);
  margin-right: 10px;
  font-size: 1.2em;
}
.leaderboard-item .name {
    font-weight: bold;
}

/* Ensure mouse events target the item container, not children, to prevent flicker/stuck tooltips */
.leaderboard-item > * {
    pointer-events: none;
}

/* Items Drag and Drop */
.items-section {
    margin-top: 20px;
    background: rgba(0, 0, 0, 0.4);
    padding: 20px;
    border-radius: 12px;
    width: 100%;
    max-width: 700px;
    border: 1px solid #444;
}

.items-pool {
    display: flex;
    gap: 15px;
    justify-content: center;
    /* min-height: 70px; */
    margin-bottom: 25px;
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 8px;
    border: 1px dashed #555;
}

.slots-row {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 8px;
    margin-top: 15px;
}

.slot {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #555;
    border-radius: 6px;
    min-height: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 4px;
    position: relative;
    font-size: 0.7em;
    color: #888;
    text-align: center;
    transition: all 0.2s;
}

.slot.drag-over {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-color);
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.3);
}

@keyframes rotateYSlow {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(360deg); }
}

.item img {
    animation: rotateYSlow 6s linear infinite;
}

.item {
    perspective: 1000px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    font-family: 'Russo One', sans-serif;
    font-size: 1.4em;
    user-select: none;
    box-shadow: 0 4px 6px rgba(0,0,0,0.5), inset 0 -4px 4px rgba(0,0,0,0.2), inset 0 2px 4px rgba(255,255,255,0.4);
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    z-index: 100;
    transition: transform 0.1s;
    position: relative; /* Needed for absolute positioning of tooltip */
}

.item:hover {
    transform: scale(1.1);
    z-index: 101; /* Ensure hovered item is above others */
}

.item-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
    z-index: 1000;
    border: 1px solid var(--accent-color);
    margin-bottom: 10px;
    font-family: 'Exo 2', sans-serif;
    font-weight: 500;
    text-shadow: none;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

/* Arrow for Tooltip */
.item-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border-width: 6px;
    border-style: solid;
    border-color: var(--accent-color) transparent transparent transparent;
}

.item:hover .item-tooltip {
    opacity: 1;
    visibility: visible;
}

.item:active {
    cursor: grabbing;
    transform: scale(1.0);
}

.item.dragging {
    opacity: 0.5;
}

/* Item Colors - Complementary to Icon Colors */
.item-mushroom { background: linear-gradient(135deg, #2ecc71, #27ae60); } /* Green (Complementary to Red Mushroom) */
.item-banana { background: linear-gradient(135deg, #9b59b6, #8e44ad); } /* Purple (Complementary to Yellow Banana) */
.item-red-shell { background: linear-gradient(135deg, #1abc9c, #16a085); } /* Teal (Contrast to Red Shell) */
.item-star { background: linear-gradient(135deg, #34495e, #2c3e50); border: 2px solid #fff; box-shadow: 0 0 10px #ffeb3b; } /* Dark Blue/Grey (High contrast for Gold Star) */
.item-lightning { background: linear-gradient(135deg, #d35400, #c0392b); } /* Dark Orange/Red (Contrast to Yellow Lightning) */

.slot-label {
    margin-top: auto;
    padding-bottom: 2px;
    line-height: 1.1;
    font-size: 0.65em;
    font-weight: bold;
    color: #aaa;
}

table {
    border-collapse: collapse;
}

th {
    border-bottom: 2px solid #555;
    padding: 10px;
    font-family: 'Russo One', sans-serif;
    color: var(--accent-color);
}

td {
    padding: 10px;
    border-bottom: 1px solid #333;
}

/* Wallet UI Styles */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: #222;
  color: white;
  margin: 0 auto;
  padding: 20px;
  width: 90%;
  max-width: 400px;
  border-radius: 12px;
  position: relative;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  border: 1px solid #444;
  box-shadow: 0 0 20px rgba(0,0,0,0.8);
}

.close {
  position: absolute;
  right: 15px;
  top: 10px;
  font-size: 24px;
  cursor: pointer;
  color: #aaa;
  transition: color 0.2s;
}

.close:hover {
  color: white;
}

.wallet-list {
  list-style: none;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  margin-top: 10px;
}

.wallet-list li {
  margin: 10px 0;
}

/* Override existing wallet-btn styles for the list items */
#wallet-list .wallet-btn {
  position: static;
  transform: none;
  background: rgba(255,255,255,0.05);
  border: 1px solid #444;
  color: white;
  box-shadow: none;
  font-family: inherit;
  width: 100%;
  text-align: left;
  font-size: 1em;
  padding: 12px;
  display: block;
  border-radius: 8px;
  transition: background 0.2s;
}

#wallet-list .wallet-btn:hover {
  background: rgba(255,255,255,0.1);
  box-shadow: none;
  border-color: var(--accent-color);
}

#local-wallet-info {
  border-top: 1px solid #444;
  margin-top: 15px;
  padding-top: 15px;
}

/* Car Tooltip */
.car-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 10px;
    border-radius: 8px;
    font-size: 0.9em;
    pointer-events: none;
    z-index: 2000;
    border: 2px solid var(--accent-color);
    font-family: 'Exo 2', sans-serif;
    box-shadow: 0 0 15px rgba(0,0,0,0.8);
    display: none;
    min-width: 150px;
}
.car-tooltip h4 {
    margin: 0 0 5px 0;
    color: var(--accent-color);
    font-size: 1.1em;
}
.car-tooltip .stat-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2px;
}
.car-tooltip .stat-label {
    color: #aaa;
}
.car-tooltip .stat-value {
    font-weight: bold;
}

@media (max-width: 768px) {
  #content-wrapper {
    min-width: 0;
  }

  /* Hide ranking/leaderboard sidebar on mobile */
  #sidebar {
    display: none;
  }
}

/* Footer Link */
.bkl-footer-link {
  color: var(--accent-color);
  font-family: 'Exo 2', sans-serif;
  font-size: 0.85em;
  text-decoration: none;
  opacity: 0.6;
  transition: opacity 0.2s;
}
.bkl-footer-link:hover {
  opacity: 1;
  text-decoration: underline;
}

/* Overlay */
.bkl-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.bkl-overlay-box {
  background: #222;
  border: 1px solid #444;
  border-radius: 12px;
  padding: 30px 40px;
  text-align: center;
  position: relative;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
  max-width: 500px;
}
.bkl-overlay-close {
  position: absolute;
  top: 10px;
  right: 15px;
  background: none;
  border: none;
  color: #aaa;
  font-size: 1.4em;
  cursor: pointer;
  transition: color 0.2s;
}
.bkl-overlay-close:hover {
  color: #fff;
}
.bkl-popup-title {
  font-family: 'Russo One', sans-serif;
  text-transform: uppercase;
  letter-spacing: 2px;
  background: linear-gradient(to bottom, #fff, #aaa);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 0 0 10px;
}
.bkl-popup-desc {
  color: #ccc;
  font-size: 0.95em;
  line-height: 1.6;
  margin: 0 auto 20px;
}
.bkl-btn-primary,
.bkl-btn-outline {
  display: inline-block;
  font-family: 'Russo One', sans-serif;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 0.7em 1.5em;
  border-radius: 8px;
  font-size: 0.9em;
  text-decoration: none;
  margin: 5px 8px;
  transition: all 0.2s;
  cursor: pointer;
}
.bkl-btn-primary {
  background: linear-gradient(to bottom, #ff4444, #cc0000);
  color: #fff;
  border: none;
  box-shadow: 0 4px 0 #990000;
}
.bkl-btn-primary:hover {
  background: linear-gradient(to bottom, #ff6666, #dd0000);
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #990000;
}
.bkl-btn-outline {
  background: transparent;
  color: var(--accent-color);
  border: 1px solid var(--accent-color);
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.2);
}
.bkl-btn-outline:hover {
  background: rgba(0, 229, 255, 0.1);
  box-shadow: 0 0 15px rgba(0, 229, 255, 0.4);
}

/* Race Start Message */
@keyframes raceMessageFade {
  0% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

.race-start-message {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  pointer-events: none;
  animation: raceMessageFade 3s ease-in-out forwards;
}

.race-start-message-text {
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-family: 'Russo One', sans-serif;
  font-size: 1.4em;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 20px 40px;
  border-radius: 12px;
  border: 2px solid var(--accent-color);
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.3);
  text-align: center;
  max-width: 80%;
}

body.game-frame #sidebar,
body.game-frame #bkl-footer {
  display: none !important;
}

body.hide-connect-wallet #game-header {
  display: none !important;
}
