#game-app, .modal-backdrop {
  --bg-board: #fdf6ea;
  --board-border: #000000;
  --slot-empty-bg: rgba(0, 0, 0, 0.04);
  --text-main: #222222;
  --text-muted: #555555;
  --accent-blue: #3a7ede;
  --accent-yellow: #f7e55f;
  --match-green: #589a56;
  --coral: #ec8d6f;
  --purple: #dcb0ed;
  /* Coin ladder: one step per site menu colour, lowest to highest */
  --coin-1: #bec6ce;
  --coin-2: #ec8d6f;
  --coin-3: #f7e55f;
  --coin-4: #589a56;
  --coin-5: #82dee6;
  --coin-6: #3a7ede;
  --coin-7: #dcb0ed;
  --coin-8: #a259cb;
  --coin-h: 26px;
  --capacity: 10;
}

#game-app, #game-app *, #game-app *::before, #game-app *::after,
.modal-backdrop, .modal-backdrop *, .modal-backdrop *::before, .modal-backdrop *::after {
  box-sizing: border-box;
}

#game-app {
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  font-family: "Comic Relief", system-ui, sans-serif;
  color: var(--text-main);
}

/* Header & Controls */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 12px;
}

.title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.title-group h1 {
  font-size: 1.8rem;
  margin: 0;
  font-weight: 700;
  color: #000;
}

.level-badge {
  font-size: 0.95rem;
  padding: 4px 14px;
  cursor: default;
}

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

button.icon-btn, .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 !important;
  border: 2px solid #000;
  border-radius: 50% !important;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  transition: transform 0.1s ease, background-color 0.1s;
}

button.icon-btn svg, .icon-btn svg {
  display: block;
  flex-shrink: 0;
  pointer-events: none;
}

.icon-btn:hover {
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(1px);
}

.game-instructions {
  font-size: 0.95rem;
  color: var(--text-muted);
  text-align: center;
  margin: 0 0 10px;
  max-width: 600px;
  line-height: 1.4;
}

/* Status Bar */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 540px;
  padding: 2px 12px 10px;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.status-bar strong {
  color: #000;
}

/* Playfield & Board */
.playfield-container {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 20px;
}

.board-frame {
  position: relative;
  padding: 16px;
  background: var(--bg-board);
  border: 2px solid var(--board-border);
  border-radius: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: visible;
}

.coin-board {
  display: grid;
  grid-template-columns: repeat(var(--columns, 4), minmax(0, 1fr));
  gap: 14px;
  width: min(640px, calc(100vw - 80px));
}

.coin-slot {
  position: relative;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  height: calc(var(--capacity) * (var(--coin-h) - 2px) + 2px + 20px);
  padding: 10px 8px;
  background: rgba(0, 0, 0, 0.045);
  border: 2px dotted #bec6ce;
  border-radius: 16px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.coin-slot:hover,
.coin-slot:focus-visible {
  border-color: #3a7ede;
}

.coin-slot.selected {
  border-style: solid;
  border-color: #3a7ede;
  box-shadow: 0 0 14px rgba(58, 126, 222, 0.35);
}

.coin-slot.bonk {
  animation: slot-bonk 0.26s ease;
}

@keyframes slot-bonk {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-4px); }
  70% { transform: translateX(4px); }
}

/* Stacked side-on coins share their 2px borders */
.coin {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 100%;
  max-width: 96px;
  height: var(--coin-h);
  margin-top: -2px;
  background: var(--coin-color);
  border: 2px solid #000;
  border-radius: 999px;
  color: var(--coin-text, #000);
  font-size: 0.9rem;
  font-weight: bold;
  line-height: 1;
}

.coin:last-child {
  margin-top: 0;
}

.coin-slot.selected .coin.picked {
  border-color: #3a7ede;
  box-shadow: 0 0 8px rgba(58, 126, 222, 0.45);
}

.coin.flying {
  position: fixed;
  z-index: 9000;
  margin: 0;
  pointer-events: none;
}

.coin.poofing {
  animation: poof-out 0.45s forwards cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes poof-out {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15) rotate(4deg); opacity: 0.8; }
  100% { transform: scale(0) rotate(-10deg); opacity: 0; }
}

.coin.popping {
  animation: coin-pop 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes coin-pop {
  from { transform: scale(0.2); }
  to { transform: scale(1); }
}

.coin-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 22px;
  vertical-align: middle;
  background: var(--coin-color);
  border: 2px solid #000;
  border-radius: 999px;
  color: var(--coin-text, #000);
  font-size: 0.8rem;
  font-weight: bold;
}

.coin-chip-big {
  width: 84px;
  height: 52px;
  font-size: 1.6rem;
}

/* Puff Particles */
.puff-particle {
  position: fixed;
  pointer-events: none;
  font-size: 1.4rem;
  z-index: 10000;
  animation: puff-fly 0.6s forwards ease-out;
}

@keyframes puff-fly {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(0.3); opacity: 0; }
}

.deal-btn {
  font-size: 1.1rem !important;
  padding: 10px 32px !important;
  margin-bottom: 4px;
}

.deal-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.toolbar button:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Bottom Toolbar */
.toolbar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 8px 16px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* Buttons Base & Design System Palette */
#game-app .button, .modal-backdrop .button {
  font-family: "Comic Relief", system-ui, sans-serif;
  font-size: 1rem;
  font-weight: bold;
  border: 2px solid #000;
  border-radius: 24px;
  padding: 8px 24px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #000;
  white-space: nowrap;
  text-decoration: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
  transition: transform 0.1s ease, background-color 0.1s ease;
}

#game-app .button:hover, .modal-backdrop .button:hover {
  transform: translateY(-1px);
}

#game-app .button:active, .modal-backdrop .button:active {
  transform: translateY(1px);
}

#game-app .button.aqua, .modal-backdrop .button.aqua {
  background-color: #82dee6;
  color: #000000;
}
#game-app .button.aqua:hover, .modal-backdrop .button.aqua:hover {
  background-color: #46ceda;
}

#game-app .button.grey, .modal-backdrop .button.grey {
  background-color: #bec6ce;
  color: #000000;
}
#game-app .button.grey:hover, .modal-backdrop .button.grey:hover {
  background-color: #a7b2bd;
}

#game-app .button.yellow, .modal-backdrop .button.yellow {
  background-color: #f7e55f;
  color: #000000;
}
#game-app .button.yellow:hover, .modal-backdrop .button.yellow:hover {
  background-color: #f4da1e;
}

#game-app .button.green, .modal-backdrop .button.green {
  background-color: #589a56;
  color: #ffffff;
}
#game-app .button.green:hover, .modal-backdrop .button.green:hover {
  background-color: #4f8b4d;
}

#game-app .button.coral, .modal-backdrop .button.coral {
  background-color: #ec8d6f;
  color: #000000;
}
#game-app .button.coral:hover, .modal-backdrop .button.coral:hover {
  background-color: #e87550;
}

#game-app .button.purple, .modal-backdrop .button.purple {
  background-color: #dcb0ed;
  color: #000000;
}
#game-app .button.purple:hover, .modal-backdrop .button.purple:hover {
  background-color: #cd8ee5;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  padding: 20px;
  transition: opacity 0.2s ease;
}

.modal-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  background: #ffffff;
  border: 2px solid #000;
  border-radius: 24px;
  padding: 32px 28px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
  position: relative;
  animation: modal-pop 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.celebration-icon {
  font-size: 3rem;
  margin-bottom: 8px;
  animation: bounce 0.6s infinite alternate ease-in-out;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}

.modal-card h2 {
  font-size: 1.8rem;
  margin-bottom: 8px;
  color: #000;
}

.modal-subtext {
  color: #666;
  margin-bottom: 20px;
  font-size: 1.05rem;
}

.modal-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 24px;
  padding: 12px 18px;
  background: #f4f8fa;
  border: 2px solid #ddd;
  border-radius: 16px;
}

.modal-stats div {
  font-size: 0.95rem;
  color: #555;
  display: flex;
  flex-direction: column;
}

.modal-stats strong {
  font-size: 1.5rem;
  color: #000;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
}

/* Settings Card */
.settings-card {
  text-align: left;
}

.settings-card h2 {
  text-align: center;
  margin-bottom: 18px;
}

.setting-row {
  margin-bottom: 16px;
}

.setting-row label {
  display: block;
  font-weight: bold;
  margin-bottom: 6px;
  font-size: 0.95rem;
  color: #333;
}

.setting-row select {
  width: 100%;
  padding: 10px 14px;
  font-size: 1rem;
  font-family: "Comic Relief", system-ui, sans-serif;
  border: 2px solid #000;
  border-radius: 16px;
  background: #ffffff;
  color: #000;
  outline: none;
}

.hidden {
  display: none !important;
}

/* Responsive adjustments */
@media (max-width: 540px) {
  .title-group {
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    gap: 8px;
  }
  .title-group h1 {
    text-align: left;
  }
  .level-badge {
    max-width: 100%;
  }
  .board-frame {
    padding: 10px;
  }
  .coin-board {
    gap: 8px;
    width: calc(100vw - 56px);
  }
  .coin-slot {
    padding: 8px 4px;
  }
}

/* Site page pattern: centred title, with the level badge and buttons as a nav row beneath it */
.game-header {
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 12px;
}

.title-group {
  display: contents;
}

.title-group h1 {
  flex-basis: 100%;
  margin: 0 0 4px;
  font-size: 2em;
  text-align: center;
}
