#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;
}

#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;
}

.tapout-grid {
  display: grid;
  gap: 8px;
  position: relative;
  overflow: visible;
}

/* Individual Blocks & Multi-cell Pieces */
.tap-block {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 2px solid #000000;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.tap-block:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.12);
  z-index: 10;
}

.tap-block:active {
  transform: scale(0.97);
}

.block-arrow {
  position: absolute;
  left: var(--arrow-x);
  top: var(--arrow-y);
  width: var(--arrow-size);
  height: var(--arrow-size);
  pointer-events: none;
  display: block;
  flex-shrink: 0;
}

/* Gentle Bonk Rebound Animations (when blocked) */
@keyframes bonk-up {
  0% { transform: translateY(0); }
  40% { transform: translateY(-7px); }
  100% { transform: translateY(0); }
}

@keyframes bonk-down {
  0% { transform: translateY(0); }
  40% { transform: translateY(7px); }
  100% { transform: translateY(0); }
}

@keyframes bonk-left {
  0% { transform: translateX(0); }
  40% { transform: translateX(-7px); }
  100% { transform: translateX(0); }
}

@keyframes bonk-right {
  0% { transform: translateX(0); }
  40% { transform: translateX(7px); }
  100% { transform: translateX(0); }
}

.bonk-up {
  animation: bonk-up 0.2s cubic-bezier(0.2, 0.8, 0.4, 1.2);
}
.bonk-down {
  animation: bonk-down 0.2s cubic-bezier(0.2, 0.8, 0.4, 1.2);
}
.bonk-left {
  animation: bonk-left 0.2s cubic-bezier(0.2, 0.8, 0.4, 1.2);
}
.bonk-right {
  animation: bonk-right 0.2s cubic-bezier(0.2, 0.8, 0.4, 1.2);
}

/* Hint Pulse Animation */
@keyframes hint-glow {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  }
  50% {
    transform: scale(1.08);
    box-shadow: 0 0 10px rgba(58, 126, 222, 0.6);
  }
}

.hint-pulse {
  animation: hint-glow 0.6s infinite ease-in-out;
  z-index: 20;
}

/* 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;
  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;
  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;
  }
  .tapout-grid {
    gap: 4px;
  }
  .tap-block {
    border-radius: 8px;
  }
}

/* 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;
}
