body {
  margin: 0;
  font-family: sans-serif;
}

.game_card {
  position: relative;
  width: 160px;
  height: 300px;
  border: 2px solid #ccc;
  border-radius: 6px;
  overflow: hidden;
  font-family: sans-serif;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* suppresses Android/iOS long-press context menu */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Top bar */
.game_card > div:nth-child(1) {
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  background: #222;
  color: #fff;
  height: 24px;
  flex-shrink: 0;
  box-sizing: border-box;
}

.game_card > div:nth-child(1) > div:nth-child(1) {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  height: 100%;
}

.game_card > div:nth-child(1) > div:nth-child(1) span {
  font-size: 6px;
}

.game_card > div:nth-child(1) > div:nth-child(1) br {
  display: none;
}

.game_card > div:nth-child(1) > div:nth-child(2) {
  font-weight: bold;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.game_card > img {
  display: block;
  width: 100%;
  height: 240px;
  object-fit: cover;
  flex-shrink: 0;
}

.game_card > div:nth-child(3) {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 12px;
  color: #999;
  white-space: nowrap;
}

/* Description - hidden by default */
.game_card > div:nth-child(4) {
  display: none;
}

/* When toggled: overlay the description over the whole card */
/* Explicitly reinforce on the description overlay too */
.game_card.show_description > div:nth-child(4) {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 12px;
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  /*font-size: 12px;*/
  line-height: 1.4;
  box-sizing: border-box;
  overflow-y: auto;
  z-index: 10;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.description_highlight {
  color: #00d4ff;
  font-weight: bold;
}

.description_bold {
  font-weight: bolder;
}

.simple_god > div:nth-child(1) {
  background: pink;
}

.selected {
  border: 1px solid lime;
}

.selected {
  background-color: lime;
}

.game_card.incompatible {
  opacity: 0.35;
  filter: grayscale(100%);
  cursor: not-allowed;
  will-change: filter; /* hint to promote to its own layer */
}
#game_cards {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 0 12px 0;
}

nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: #1a1a1a;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100; /* stays above game cards when scrolling */
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

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

nav label {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
}

nav select {
  font-size: 16px; /* 16px prevents iOS Safari from auto-zooming in on focus */
  padding: 10px 14px;
  border-radius: 8px;
  border: none;
  background: #fff;
  color: #1a1a1a;
  min-height: 44px; /* comfortable tap target */
  box-sizing: border-box;
}

/* Checkbox: default checkboxes are tiny and hard to tap on mobile, so enlarge it */
.nav_group_checkbox input[type="checkbox"] {
  width: 26px;
  height: 26px;
  accent-color: #2d9cdb; /* colors the native checkbox check, supported in modern mobile browsers */
  cursor: pointer;
}

.nav_buttons {
  gap: 10px;
  flex-wrap: wrap;
}

nav button {
  font-size: 15px;
  font-weight: 600;
  padding: 12px 18px;
  min-height: 44px;
  border: none;
  border-radius: 8px;
  background: #2d9cdb;
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

nav button:active {
  background: #2286c2;
  transform: scale(0.97); /* subtle tactile press feedback */
}

#clear_and_fill_random_btn {
  background: #444; /* visually distinct as the more "destructive" action (clears first) */
}

#clear_and_fill_random_btn:active {
  background: #333;
}

/* Stack everything full-width on very small screens */
@media (max-width: 480px) {
  nav {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .nav_group {
    justify-content: space-between;
  }

  .nav_buttons {
    flex-direction: column;
  }

  nav button {
    width: 100%;
  }
}

#draw_container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
}

.nav_back_link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 18px;
  min-height: 44px;
  border: none;
  border-radius: 8px;
  background: #2d9cdb;
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color 0.15s ease, transform 0.1s ease;
  box-sizing: border-box;
}

.nav_back_link:active {
  background: #2286c2;
  transform: scale(0.97);
}

#discard_and_draw_btn {
  font-size: 15px;
  font-weight: 600;
  padding: 12px 20px;
  min-height: 44px;
  border: none;
  border-radius: 8px;
  background: #2d9cdb;
  color: #fff;
  cursor: pointer;
}

#discard_and_draw_btn:disabled {
  background: #555;
  cursor: not-allowed;
}

#deck_status {
  font-size: 13px;
  color: #888;
}

#custom_deck_container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
  color: #fff;
}

.deck_input_group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.deck_input_group label {
  font-weight: 600;
}

#json_textarea {
  font-family: monospace;
  font-size: 13px;
  padding: 10px;
  border-radius: 8px;
  border: none;
  resize: vertical;
}

.deck_errors {
  background: #4a1010;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
  font-size: 14px;
}

.deck_errors ul {
  margin: 8px 0 0 20px;
  padding: 0;
}

.deck_actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.deck_actions button,
.deck_input_group button {
  font-size: 15px;
  font-weight: 600;
  padding: 12px 18px;
  min-height: 44px;
  border: none;
  border-radius: 8px;
  background: #2d9cdb;
  color: #fff;
  cursor: pointer;
}

#reset_deck_btn {
  background: #444;
}

#active_deck_status {
  font-size: 13px;
  color: #aaa;
}

/* Hamburger button - hidden by default (desktop), shown only on small screens */
#nav_toggle_btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  background: transparent;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.burger_line {
  width: 26px;
  height: 3px;
  background: #fff;
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

/* Animate into an X when open */
#nav_toggle_btn.nav_toggle_active .burger_line:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}
#nav_toggle_btn.nav_toggle_active .burger_line:nth-child(2) {
  opacity: 0;
}
#nav_toggle_btn.nav_toggle_active .burger_line:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}

#nav_content {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

@media (max-width: 700px) {
  nav {
    flex-direction: column;
    align-items: stretch;
  }

  #nav_toggle_btn {
    display: flex;
    align-self: flex-end;
  }

  #nav_content {
    display: none; /* collapsed by default on small screens */
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    width: 100%;
    margin-top: 12px;
  }

  #nav_content.nav_open {
    display: flex;
  }

  .nav_group {
    justify-content: space-between;
  }

  .nav_buttons {
    flex-direction: column;
  }

  .nav_back_link,
  nav button {
    width: 100%;
  }
}

#selected_cards_container {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px;
  min-height: 20px; /* keeps the layout from jumping when empty */
  border-bottom: 2px solid #333;
  margin-bottom: 12px;
}

#board_page_container {
  display: flex;
  justify-content: center;
  padding: 20px;
  padding-bottom: 140px; /* increased to match new palette height + margin */
  overflow: auto;
}

#board_container {
  display: grid;
  gap: 2px;
  background: #333;
  border: 2px solid #333;
}

.board_cell {
  width: 48px;
  height: 48px;
  background: #f0e6d2;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  touch-action: none; /* prevents page scroll while dragging over cells */
  box-sizing: border-box;
}

.board_cell.drag_over {
  background: #cdeaff;
}

.board_piece {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#piece_palette {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 110px; /* taller, was implicitly ~75px before */
  display: flex;
  align-items: flex-end;
  gap: 20px; /* more breathing room between pieces */
  padding: 12px 16px;
  background: #1a1a1a;
  overflow-x: auto;
  overflow-y: hidden;
  box-sizing: border-box;
  z-index: 200;
  border-top: 2px solid #333;
  touch-action: pan-x; /* lets a swipe on the empty bar background scroll horizontally */
}

.palette_piece {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 10px; /* padding around each piece = more grabbable empty space per item */
}

.palette_piece_label {
  font-size: 11px;
  color: #ccc;
  white-space: nowrap;
}

.drag_ghost {
  position: fixed;
  pointer-events: none;
  z-index: 999;
  opacity: 0.85;
}

.board_piece_image {
  background: transparent;
  overflow: hidden;
  padding: 0;
}

.board_piece_image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%; /* keeps the circular shape even for rectangular source images */
  pointer-events: none; /* clicks/drags pass through to the parent .board_piece div */
  -webkit-user-drag: none; /* Safari-specific: disable native image drag */
}

#direction_container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 60px 20px;
  /*color: #fff;*/
}

#direction_arrow {
  font-size: 140px;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}

#direction_label {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 1px;
}

#randomize_direction_btn {
  font-size: 16px;
  font-weight: 600;
  padding: 14px 28px;
  min-height: 48px;
  border: none;
  border-radius: 8px;
  background: #2d9cdb;
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

#randomize_direction_btn:active {
  background: #2286c2;
  transform: scale(0.97);
}

#direction_arrow {
  width: 160px;
  height: 160px;
  transition: transform 0.5s ease-in-out;
}

#direction_arrow.spinning {
  animation: spin_arrow 0.5s ease-in-out;
}

@keyframes spin_arrow {
  from { transform: rotate(0deg); }
  to   { transform: rotate(720deg); }
}

.stack_badge {
  position: absolute;
  bottom: 2px;
  right: 2px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}