* { box-sizing: border-box; }

/* The .screen / .modal-overlay classes below set display:flex, which (being
   author CSS) overrides the browser's built-in [hidden]{display:none} rule.
   This forces hidden to always win so screens/modals actually hide. */
[hidden] { display: none !important; }

:root {
  --bg1: #fff4d6;
  --bg2: #cdeaff;
  --primary: #ff7a59;
  --primary-dark: #e8613f;
  --secondary: #4fb0ff;
  --secondary-dark: #2f8ede;
  --card-bg: #ffffff;
  --text: #333844;
  --radius: 18px;
}

body {
  margin: 0;
  font-family: "Comic Sans MS", "Segoe UI", Verdana, sans-serif;
  background: linear-gradient(135deg, var(--bg1), var(--bg2));
  min-height: 100vh;
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.6rem;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 4px 0 rgba(0,0,0,0.15);
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.15); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:not(:disabled):hover { background: var(--primary-dark); }

.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:not(:disabled):hover { background: var(--secondary-dark); }

.screen { padding: 10px 20px 40px; display: flex; justify-content: center; }

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 560px;
  width: 100%;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  text-align: center;
}

.card h2 { margin-top: 0; }

.upload-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  border: 3px dashed var(--secondary);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  min-height: 140px;
  background: #f7fbff;
  margin-bottom: 8px;
  transition: background 0.15s ease;
}
.upload-drop.dragover { background: #e2f2ff; }
.upload-drop img { max-width: 100%; max-height: 220px; border-radius: 12px; margin-top: 10px; }

.difficulty-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 14px 0 24px;
  flex-wrap: wrap;
}

.diff-btn {
  flex: 1 1 100px;
  border: 3px solid transparent;
  background: #f1f1f1;
  border-radius: 14px;
  padding: 12px 8px;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  font-size: 1rem;
}
.diff-btn small { font-weight: normal; opacity: 0.7; }
.diff-btn.selected { border-color: var(--primary); background: #fff0eb; }

.game-wrap {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 24px;
  align-items: stretch;
  justify-content: center;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

.board-area {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  max-width: 100%;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
}

.board {
  position: relative;
  background-repeat: no-repeat;
  background-size: cover;
  border-radius: 10px;
  overflow: hidden;
  border: 3px solid #ffe1b0;
}

.slot-outline {
  position: absolute;
  border: 1.5px dashed rgba(0,0,0,0.25);
  box-sizing: border-box;
  pointer-events: none;
}

.tray-area {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  flex: 1 1 380px;
  min-width: 280px;
  max-width: 520px;
  display: flex;
  flex-direction: column;
}

.tray-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: bold;
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.progress-label {
  background: #fff0eb;
  color: var(--primary-dark);
  padding: 4px 10px;
  border-radius: 999px;
}

.tray {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  gap: 12px;
  padding: 14px;
  flex: 1 1 auto;
  min-height: 260px;
  max-height: 72vh;
  overflow-y: auto;
  background: #fbfbfb;
  border-radius: 12px;
  margin-bottom: 12px;
}

.tray .puzzle-piece {
  position: relative;
}

.puzzle-piece {
  position: absolute;
  cursor: grab;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,0.35));
  touch-action: none;
  user-select: none;
}

.puzzle-piece img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.puzzle-piece.dragging {
  cursor: grabbing;
  z-index: 999;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.4));
}
.puzzle-piece.placed {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
  cursor: default;
}

#confettiCanvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1200;
  display: none;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 30, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1300;
}

.modal {
  background: white;
  border-radius: var(--radius);
  padding: 30px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}

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

@media (max-width: 720px) {
  .topbar h1 { font-size: 1.25rem; }
}
