:root {
  --track-bg: #eaf6f8;
  --track-rail: #000000;
  --belt-color: #d8edf1;
  --box-bg: #fffaf0;
  --box-border: #000000;
  --text-main: #222222;
  --text-muted: #555555;
  --accent-blue: #3a7ede;
  --accent-gold: #f7e55f;
  --match-green: #589a56;
}

#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: 12px;
  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: 10px;
}

.icon-btn, .theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease;
  font-size: 1.3rem;
}

.icon-btn:active, .theme-toggle-btn:active {
  transform: scale(0.92);
}

.game-instructions {
  margin-bottom: 16px;
  font-size: 1rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 620px;
}

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

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

/* Floating Selected Item Preview */
.floating-item {
  position: fixed;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: #ffffff;
  border: 2px solid var(--accent-blue);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25), 0 0 16px rgba(58, 126, 222, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  pointer-events: none;
  z-index: 2000;
  transform: translate(-50%, -50%) scale(1.1);
  transition: transform 0.1s ease;
}

/* Conveyor Area */
.conveyor-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 10px 14px;
  overflow: hidden;
  position: relative;
}

.conveyor-stage {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: 820px;
}

/* Conveyor Track / Belt */
.conveyor-track {
  position: relative;
  height: 124px;
  background: var(--track-bg);
  border-radius: 20px;
  border: 2px solid var(--track-rail);
  overflow: hidden;
  display: flex;
  align-items: center;
}

/* Tunnel vignette at track edges */
.conveyor-track::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 20px;
  background: linear-gradient(
    to right,
    rgba(255, 255, 255, 0.95) 0%,
    rgba(255, 255, 255, 0) 40px,
    rgba(255, 255, 255, 0) calc(100% - 40px),
    rgba(255, 255, 255, 0.95) 100%
  );
  z-index: 50;
}

/* Mechanical track edge lines */
.track-rail {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: repeating-linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.03) 0px,
    rgba(0, 0, 0, 0.03) 20px,
    rgba(0, 0, 0, 0.07) 20px,
    rgba(0, 0, 0, 0.07) 40px
  );
  pointer-events: none;
}

.track-belt {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
}

/* Moving Box */
.moving-box {
  box-sizing: border-box;
  position: absolute;
  top: 20px;
  width: 196px;
  height: 84px;
  background: var(--box-bg);
  border: 2px solid var(--box-border);
  border-radius: 18px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  will-change: transform;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.moving-box.selected {
  border-color: var(--accent-blue);
  box-shadow: 0 4px 12px rgba(58, 126, 222, 0.2);
}

.moving-box.closed {
  background: #f0fdf4;
  border-color: var(--match-green);
  cursor: default;
}

.box-slots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  height: 52px;
  align-items: center;
}

.slot {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: transparent;
  border: none;
  border-radius: 12px;
}

.slot.empty {
  border: 2px dotted #bec6ce;
  background: rgba(0, 0, 0, 0.045);
}

.item, .conveyor-item {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  background: #ffffff;
  border: 2px solid #bec6ce;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.item.selected, .conveyor-item.selected {
  border: 2px solid var(--accent-blue);
  box-shadow: 0 2px 8px rgba(58, 126, 222, 0.35);
}

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

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

.box-lid-closed {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--match-green);
  font-weight: bold;
  font-size: 0.95rem;
  background: #dcfce7;
  border: 2px dashed var(--match-green);
  border-radius: 12px;
  grid-column: span 3;
  height: 100%;
}

/* Sparkle particles */
.puff-particle {
  position: fixed;
  pointer-events: none;
  font-size: 1.4rem;
  z-index: 10000;
  animation: puff-fly 0.55s 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; }
}

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

.toolbar button.button {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.toolbar button.button:active {
  transform: scale(0.95);
}

.toolbar button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* 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: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.3);
  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;
}

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