:root{
    --sunny:#ffc93c;
    --sky:#7bc8f6;
    --leaf:#5cb85c;
    --berry:#e8594f;
    --plum:#7b5ea7;
    --cream:#fff8ec;
    --ink:#3a2e2e;
    color-scheme: light;
  }
  *{box-sizing:border-box;}
  body{
    margin:0;
    font-family: 'Trebuchet MS', 'Segoe UI', Verdana, sans-serif;
    background: linear-gradient(180deg,#fef6e4 0%, #eaf6ff 100%);
    color: var(--ink);
    min-height:100vh;
  }
  header{
    text-align:center;
    padding: 22px 16px 10px;
  }
  header h1{
    margin:0 0 4px;
    font-size: 2.1rem;
    color:#c0392b;
    text-shadow: 1px 1px 0 #fff, 2px 2px 0 rgba(0,0,0,0.08);
  }
  header p{
    margin:0;
    color:#5a4b4b;
    font-size:1rem;
  }
  main{
    max-width: 1000px;
    margin: 0 auto;
    padding: 10px 16px 60px;
  }
  .screen{ display:none; }
  .screen.active{ display:block; }

  /* --- Compact chrome while a puzzle is open, so more height goes to the
     grid/pieces instead of the header and footer --- */
  body.is-playing header{ padding: 8px 16px 4px; }
  body.is-playing header h1{ font-size: 1.4rem; margin-bottom: 0; }
  body.is-playing header p{ display:none; }
  body.is-playing main{ padding-bottom: 16px; max-width: 1300px; }
  body.is-playing footer{ display:none; }

  /* --- Age group cards --- */
  .age-grid{
    display:grid;
    grid-template-columns: repeat(auto-fit, minmax(240px,1fr));
    gap:20px;
    margin-top: 20px;
  }
  .age-card{
    border:none;
    border-radius: 22px;
    padding: 26px 18px;
    cursor:pointer;
    font-family:inherit;
    text-align:center;
    color:#fff;
    box-shadow: 0 6px 0 rgba(0,0,0,0.15), 0 10px 18px rgba(0,0,0,0.12);
    transition: transform .12s ease;
  }
  .age-card:hover{ transform: translateY(-4px) scale(1.02); }
  .age-card:active{ transform: translateY(1px); }
  .age-card .emoji{ font-size:3rem; display:block; margin-bottom:8px; }
  .age-card h2{ margin:0 0 6px; font-size:1.3rem; }
  .age-card p{ margin:0; opacity:.9; font-size:.9rem; }
  .age-card.toddler{ background: linear-gradient(135deg,#ff9a76,#ff6f61); }
  .age-card.early{ background: linear-gradient(135deg,#5ec8e0,#3aa1c9); }
  .age-card.older{ background: linear-gradient(135deg,#8e7cc3,#6a5acd); }

  /* --- Activity row (Ten Commandments game) --- */
  .activity-row{
    margin-top: 26px;
    display:flex;
    justify-content:center;
  }
  .activity-card{
    display:flex;
    align-items:center;
    gap:16px;
    background: linear-gradient(135deg,#ffd36e,#ffb347);
    border:none;
    border-radius: 20px;
    padding: 18px 26px;
    cursor:pointer;
    color:#4a3418;
    box-shadow: 0 6px 0 rgba(0,0,0,0.12), 0 10px 18px rgba(0,0,0,0.1);
    max-width: 440px;
    width:100%;
    text-align:left;
    font-family:inherit;
    transition: transform .12s ease;
  }
  .activity-card:hover{ transform: translateY(-3px); }
  .activity-card:active{ transform: translateY(1px); }
  .activity-card .emoji{ font-size:2.4rem; flex-shrink:0; }
  .activity-card h2{ margin:0 0 2px; font-size:1.05rem; }
  .activity-card p{ margin:0; font-size:.85rem; opacity:.85; }

  /* --- Ten Commandments matching game --- */
  .cmd-header{
    text-align:center;
    margin-bottom: 20px;
    padding: 20px 16px 22px;
    border-radius: 22px;
    background: linear-gradient(180deg,#fff3d6 0%, #ffe6ae 100%);
    box-shadow: inset 0 -3px 0 rgba(0,0,0,0.05);
  }
  .cmd-header h2{ margin:0 0 4px; font-size:1.5rem; color:#8a5a1e; text-shadow: 1px 1px 0 #fff; }
  .cmd-header p{ margin:0 0 16px; color:#8a6a3a; font-size:.9rem; }
  .cmd-progress-wrap{
    display:flex;
    align-items:center;
    gap:10px;
    max-width:320px;
    margin:0 auto;
  }
  .cmd-progress-track{
    flex:1;
    height:14px;
    background: rgba(255,255,255,0.6);
    border-radius:999px;
    overflow:hidden;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.18);
  }
  .cmd-progress-fill{
    height:100%;
    width:0%;
    background: linear-gradient(90deg,#ffd36e,#e8594f);
    border-radius:999px;
    transition: width .4s ease;
  }
  .cmd-progress-label{
    font-weight:bold;
    color:#8a5a1e;
    font-size:.85rem;
    white-space:nowrap;
  }

  .cmd-game{
    display:flex;
    gap:28px;
    justify-content:center;
    flex-wrap:wrap;
    margin-top:6px;
  }
  .cmd-col-wrap{
    display:flex;
    flex-direction:column;
    align-items:center;
    width:320px;
    max-width:100%;
  }
  .cmd-col-label{
    font-size:.82rem;
    font-weight:bold;
    color:#6a5acd;
    background:#fff;
    padding:6px 16px;
    border-radius:999px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    margin-bottom:12px;
  }
  .cmd-col{
    display:flex;
    flex-direction:column;
    gap:18px;
    width:100%;
  }
  .cmd-tile{
    min-height:76px;
    border-radius:14px;
    padding:16px 18px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    cursor:pointer;
    font-size:.92rem;
    line-height:1.35;
    transition: transform .15s ease, box-shadow .15s ease;
    user-select:none;
    position:relative;
    box-sizing:border-box;
  }
  .cmd-tile:hover{ transform: translateY(-3px) scale(1.02); box-shadow: 0 8px 16px rgba(0,0,0,0.18); }
  .cmd-tile:active{ transform: translateY(0) scale(0.99); }

  .cmd-tile.tablet{
    display:flex;
    align-items:center;
    justify-content:center;
    background: linear-gradient(160deg,#9d97b8 0%, #6f6890 55%, #574f78 100%);
    color:#fdf6e3;
    text-align:center;
    font-weight:bold;
    border-radius: 50% 50% 14px 14px / 34px 34px 14px 14px;
    padding-top:14px;
    border: 2px solid rgba(255,255,255,0.25);
  }
  .cmd-tile.tablet::before{
    content:'';
    position:absolute;
    left:50%;
    top:6px;
    width:1px;
    height:calc(100% - 20px);
    background: rgba(255,255,255,0.18);
    transform: translateX(-50%);
  }
  .cmd-tile .cmd-num{
    font-size:1.9rem;
    font-family: Georgia, 'Times New Roman', serif;
    text-shadow: 0 2px 2px rgba(0,0,0,0.3);
    color:#ffe9b8;
  }

  .cmd-tile.phrase{
    display:flex;
    align-items:center;
    gap:12px;
    background: linear-gradient(135deg,#fffaf0,#fbf0d9);
    color:#4a3418;
    border: 1px dashed #e0c98f;
  }
  .cmd-icon{
    flex-shrink:0;
    width:38px;
    height:38px;
    display:flex;
    align-items:center;
    justify-content:center;
    font-size:1.3rem;
    background:#fff;
    border-radius:50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.12);
  }
  .cmd-text{ flex:1; }

  .cmd-tile.selected{ outline: 3px solid var(--berry); outline-offset:2px; }
  .cmd-tile.matched{
    opacity:.55;
    cursor:default;
    box-shadow:none;
    transform:none !important;
  }
  .cmd-tile.tablet.matched{ background: linear-gradient(160deg,#7fc98f,#4f9d63) !important; color:#fff !important; }
  .cmd-tile.tablet.matched .cmd-num{ color:#fff; }
  .cmd-tile.phrase.matched{ background:#e6f7e6 !important; color:#3a2e2e !important; border-color:#bfe3bf; }
  .cmd-tile.matched::after{
    content:'\2713';
    position:absolute;
    top:8px;
    right:10px;
    font-size:1rem;
    line-height:1;
    color:#fff;
    background: rgba(0,0,0,0.18);
    border-radius:50%;
    width:20px;
    height:20px;
    display:flex;
    align-items:center;
    justify-content:center;
  }

  .cmd-tile.wrong{ animation: cmd-shake .4s; background:#ffd3d3 !important; border-color:#e8594f; }
  @keyframes cmd-shake{
    0%,100%{ transform:translateX(0); }
    20%{ transform:translateX(-6px) rotate(-1deg); }
    40%{ transform:translateX(6px) rotate(1deg); }
    60%{ transform:translateX(-4px); }
    80%{ transform:translateX(4px); }
  }
  .cmd-recap{
    text-align:left;
    max-height: 260px;
    overflow-y:auto;
    margin: 0 0 18px;
    font-size:.85rem;
    color:#5a4b4b;
    background:#fffaf0;
    border-radius:12px;
    padding: 14px 18px;
    border: 1px dashed #e0c98f;
  }
  .cmd-recap .row{ margin-bottom:8px; }
  .cmd-recap b{ color:#6a5acd; }

  /* --- Nav / back button --- */
  .backbar{
    display:flex;
    align-items:center;
    gap:10px;
    margin-bottom: 14px;
  }
  .btn{
    font-family: inherit;
    font-size: 0.95rem;
    padding: 10px 18px;
    border-radius: 999px;
    border: none;
    cursor:pointer;
    background:#fff;
    color: var(--ink);
    box-shadow: 0 3px 0 rgba(0,0,0,0.15);
  }
  .btn:active{ transform: translateY(2px); box-shadow:none; }
  .btn.primary{ background: var(--berry); color:#fff; }
  .btn.primary:hover{ background:#d64b42; }

  /* --- Puzzle picker --- */
  .puzzle-grid{
    display:grid;
    grid-template-columns: repeat(auto-fit, minmax(230px,1fr));
    gap: 20px;
  }
  .puzzle-card{
    background:#fff;
    border-radius:18px;
    overflow:hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    cursor:pointer;
    transition: transform .12s ease;
  }
  .puzzle-card:hover{ transform: translateY(-3px); }
  .puzzle-card .thumb{ width:100%; display:block; aspect-ratio: 4/3; object-fit:cover; background:#eee; }
  .puzzle-card .info{ padding:12px 14px 16px; }
  .puzzle-card h3{ margin:0 0 4px; font-size:1.05rem; color:#333; }
  .puzzle-card .verse{ font-size:.82rem; color:#777; margin:0 0 6px; font-style: italic; }
  .puzzle-card .pieces-tag{
    display:inline-block;
    background:#f1eef9;
    color:#6a5acd;
    font-size:.75rem;
    padding:3px 9px;
    border-radius:999px;
    font-weight:bold;
  }

  /* --- Puzzle play screen --- */
  .puzzle-header{
    display:flex;
    justify-content:space-between;
    align-items:center;
    flex-wrap:wrap;
    gap:10px;
    margin-bottom: 8px;
  }
  .puzzle-header h2{ margin:0; font-size:1.3rem; }
  .puzzle-header .verse{ font-size:.85rem; color:#777; font-style:italic; margin:2px 0 0; }
  .progress-pill{
    background:#fff;
    border-radius:999px;
    padding:6px 14px;
    font-weight:bold;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    color: var(--plum);
  }

  .puzzle-stage{
    display:flex;
    flex-direction:column;
    align-items:center;
    gap:14px;
    margin-top: 14px;
    width:100%;
  }
  .stage-row{
    display:flex;
    flex-direction:row;
    align-items:flex-start;
    justify-content:center;
    gap:14px;
    flex-wrap:wrap;
    width:100%;
  }
  .grid-zone{
    position:relative;
    background: repeating-conic-gradient(#e9e9e9 0% 25%, #f7f7f7 0% 50%) 0 0/24px 24px;
    border-radius: 10px;
    border: 3px dashed #c9c2d8;
    touch-action:none;
    flex-shrink:0;
  }
  .dropzone{
    position:absolute;
    box-sizing:border-box;
    border: 1px dashed rgba(122,90,205,0.35);
  }
  .dropzone.filled{ border: 1px solid transparent; }

  .side-tray{
    display:flex;
    flex-direction:column;
    flex-wrap:wrap;
    align-content:flex-start;
    gap:8px;
    background:#fff;
    border-radius: 14px;
    border: 2px solid #eee;
    padding: 8px;
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.05);
    flex-shrink:0;
  }
  .side-tray.empty{ display:none; }

  .tray-zone{
    width:100%;
    min-height: 90px;
    background: #fff;
    border-radius: 14px;
    border: 2px solid #eee;
    padding: 10px;
    display:flex;
    flex-wrap:wrap;
    gap:8px;
    justify-content:center;
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.05);
  }
  .tray-zone.empty{ display:none; }

  @media (max-width:760px){
    .stage-row{ flex-direction:column; align-items:center; }
    .side-tray{
      flex-direction:row !important;
      flex-wrap:wrap !important;
      width:100% !important;
      height:auto !important;
      max-width: 100%;
      justify-content:center;
    }
  }

  .piece{
    position:relative;
    background-repeat:no-repeat;
    border-radius:4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.25);
    cursor: grab;
    touch-action:none;
    outline: 2px solid rgba(255,255,255,0.6);
    outline-offset:-2px;
  }
  .piece.dragging{
    cursor: grabbing;
    z-index: 500;
    box-shadow: 0 10px 18px rgba(0,0,0,0.35);
    outline: 2px solid #fff;
  }
  .piece.locked{
    cursor: default;
    box-shadow:none;
    outline: 1px solid rgba(0,0,0,0.08);
  }

  /* --- Celebration overlay --- */
  .overlay{
    position:fixed; inset:0;
    background: rgba(60,40,60,0.55);
    display:none;
    align-items:center;
    justify-content:center;
    z-index: 1000;
    padding: 20px;
  }
  .overlay.active{ display:flex; }
  .overlay-card{
    background:#fff8ec;
    border-radius: 24px;
    padding: 34px 30px;
    text-align:center;
    max-width: 420px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
  }
  .overlay-card .big-emoji{ font-size: 3.5rem; }
  .overlay-card h2{ margin: 6px 0 6px; color:#c0392b; }
  .overlay-card p{ margin: 0 0 18px; color:#5a4b4b; font-style: italic; }
  .overlay-actions{ display:flex; gap:10px; justify-content:center; flex-wrap:wrap; }

  footer{
    text-align:center;
    color:#999;
    font-size:.8rem;
    padding: 10px 16px 30px;
  }

  @media (max-width:480px){
    header h1{ font-size:1.6rem; }
    .age-card .emoji{ font-size:2.4rem; }
  }
