:root{
  --bg:#4a7fc4;
  --panel:#ffffff;
  --accent:#2f5fa8;
  --text:#1c2b3a;
  --muted:#8a97a8;
}
*{box-sizing:border-box;}
body{
  margin:0;
  font-family:'Segoe UI', Arial, sans-serif;
  background:var(--bg);
  min-height:100vh;
  padding:16px;
  display:flex;
  flex-direction:column;
  align-items:center;
}

/* ===== Top bar ===== */
.topbar{
  width:100%; max-width:700px;
  display:flex; justify-content:space-between; align-items:center;
  margin-bottom:10px;
}
h1{
  color:#fff;
  font-size:clamp(20px, 4vw, 30px);
  letter-spacing:1px;
  margin:0;
}
.menu-btn{
  background:rgba(255,255,255,0.15);
  border:none; color:#fff;
  width:40px; height:40px; border-radius:8px;
  font-size:20px; cursor:pointer;
}
.menu{
  position:absolute; top:50px; right:0;
  background:#fff; border-radius:10px;
  box-shadow:0 8px 24px rgba(0,0,0,.2);
  overflow:hidden; display:none; z-index:20; min-width:190px;
}
.menu.open{display:block;}
.menu button{
  display:flex; justify-content:space-between; align-items:center;
  width:100%; padding:12px 18px;
  background:none; border:none; text-align:left;
  font-size:15px; cursor:pointer; color:var(--text);
}
.menu button:hover{background:#f0f0f0;}
.badge-count{
  background:var(--accent); color:#fff;
  font-size:12px; padding:2px 7px; border-radius:10px;
}

/* ===== Overall progress row ===== */
.progress-row{
  width:100%; max-width:560px;
  color:#fff; font-size:13px; font-weight:600;
  margin-bottom:8px;
}
.progress-row #progressText{
  display:block; margin-bottom:4px;
}
.progress-bar{
  width:100%; height:8px; border-radius:5px;
  background:rgba(255,255,255,.25);
  overflow:hidden;
}
.progress-fill{
  height:100%; width:0%;
  background:#ffd166;
  border-radius:5px;
  transition:width .4s ease;
}

/* ===== Level pill + timer ===== */
.stats-bar{
  width:100%; max-width:560px;
  display:flex; justify-content:space-between; align-items:center;
  margin-bottom:12px; padding:0 2px; gap:10px;
}
.level-pill{
  background:rgba(255,255,255,.18);
  color:#fff; border:none;
  padding:8px 14px; border-radius:20px;
  font-size:14px; font-weight:700;
  cursor:pointer; text-align:left;
  max-width:75%;
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.level-pill:hover{ background:rgba(255,255,255,.28); }
.timer-tag{
  color:#fff; font-size:14px; font-weight:600; white-space:nowrap;
}

/* ===== Board ===== */
.board-wrap{
  background:var(--panel);
  border-radius:14px;
  padding:clamp(10px, 3vw, 24px);
  width:100%; max-width:560px;
  box-shadow:0 10px 30px rgba(0,0,0,.2);
  touch-action:none;
  user-select:none;
  position:relative;
}
.grid{
  display:grid;
  gap:2px;
  width:100%;
  aspect-ratio:1/1;
  position:relative;
  z-index:2;
}
.cell{
  display:flex; align-items:center; justify-content:center;
  font-weight:700;
  font-size:var(--cell-font, clamp(13px, 3.6vw, 22px));
  color:var(--text);
  background:transparent;
  position:relative;
}
.capsule-layer{
  position:absolute;
  z-index:1;
  pointer-events:none;
}
.capsule{
  position:absolute;
  border-radius:999px;
  opacity:.85;
}
.capsule.selecting{
  background:#bcd4f2;
  opacity:1;
}

/* ===== Word list ===== */
.wordlist{
  max-width:560px; width:100%;
  margin-top:16px;
  display:flex; flex-wrap:wrap;
  gap:10px 16px; justify-content:center;
}
.word{
  color:#fff; font-weight:600; letter-spacing:1px;
  font-size:clamp(13px,3vw,16px);
  text-transform:uppercase;
  display:flex; align-items:center; gap:6px;
}
.word .dot{
  width:10px; height:10px; border-radius:50%;
  display:inline-block;
}
.word.done{ text-decoration:line-through; opacity:.55; }

.status{
  color:#fff; margin-top:12px; font-size:14px; opacity:.9;
  min-height:18px; text-align:center;
}

/* ===== Modals ===== */
.modal-overlay{
  display:none;
  position:fixed; inset:0;
  background:rgba(0,0,0,.5);
  align-items:center; justify-content:center;
  z-index:100; padding:16px;
}
.modal-overlay.open{ display:flex; }
.modal{
  background:#fff; border-radius:14px;
  padding:24px; max-width:360px; width:100%;
  text-align:center;
}
.modal.wide{ max-width:460px; text-align:left; }
.modal h2{ margin-top:0; color:var(--text); }
.modal-header{
  display:flex; justify-content:space-between; align-items:center;
}
.close-btn{
  background:none; border:none; font-size:26px; line-height:1;
  cursor:pointer; color:var(--muted);
}
.modal-btn-row{ display:flex; gap:10px; margin-top:16px; justify-content:center; }
.primary-btn{
  padding:12px 22px; border:none; border-radius:10px;
  background:var(--accent); color:#fff; font-size:15px; font-weight:600;
  cursor:pointer;
}
.secondary-btn{
  padding:12px 22px; border:2px solid #e2e8f0; border-radius:10px;
  background:#fff; color:var(--text); font-size:15px; font-weight:600;
  cursor:pointer;
}

/* ===== Level grid popup ===== */
.jump-row{ display:flex; gap:8px; margin:14px 0; }
.jump-row input{
  flex:1; padding:10px; border-radius:8px; border:1px solid #dbe3ee; font-size:14px;
}
.jump-row button{
  padding:10px 16px; border:none; border-radius:8px;
  background:var(--accent); color:#fff; font-weight:600; cursor:pointer;
}
.level-list-wrap{ max-height:60vh; overflow-y:auto; padding-right:4px; }
.level-section-title{
  font-size:13px; font-weight:700; color:var(--muted);
  text-transform:uppercase; letter-spacing:1px;
  margin:14px 0 8px;
}
.level-grid{
  display:grid;
  grid-template-columns:repeat(5, 1fr);
  gap:8px;
}
.level-btn{
  aspect-ratio:1/1;
  border-radius:10px;
  border:2px solid #e2e8f0;
  background:#f8fafc;
  font-weight:700; font-size:14px;
  color:var(--text);
  cursor:pointer;
  display:flex; align-items:center; justify-content:center;
  position:relative;
}
.level-btn.completed{
  background:#7fd4a8; border-color:#5cc190; color:#0d3a22;
}
.level-btn.current{
  outline:3px solid var(--accent); outline-offset:1px;
}
.more-btn{
  display:block; width:100%; margin-top:14px;
  padding:10px; border-radius:8px; border:2px dashed #cbd5e1;
  background:#fff; color:var(--accent); font-weight:600; cursor:pointer;
}

/* ===== Confetti canvas ===== */
#confettiCanvas{
  position:fixed; inset:0; z-index:200; pointer-events:none;
}

@media print{
  body{
    background:#fff; padding:0;
    display:block;      /* override the flex layout so text-align:center can do the centering */
    text-align:center;
  }
  .topbar, .status, .stats-bar, .progress-row, .modal-overlay, .menu{ display:none; }
  .capsule-layer{ display:none; }           /* hide solved-word highlights */
  .board-wrap{
    display:inline-block;                   /* needed for margin:auto centering to take effect */
    width:500px; max-width:90%;
    margin:40px auto 20px;
    box-shadow:none; border:1px solid #ccc;
  }
  .wordlist{
    display:flex; justify-content:center;
    width:500px; max-width:90%;
    margin:20px auto 0;
  }
  .word{ color:#000; }                      /* white text isn't visible on paper */
  .word.done{ text-decoration:none; opacity:1; }  /* don't reveal which are solved */
}

/* ===== Footer ===== */
.site-footer{
  width:100%; max-width:560px;
  margin:32px auto 12px;
  text-align:center;
  color:rgba(255,255,255,.85);
  font-size:13px;
}
.site-footer a{
  color:#fff; text-decoration:none;
  margin:0 8px;
}
.site-footer a:hover{ text-decoration:underline; }
.site-footer .footer-note{
  margin-top:8px; color:rgba(255,255,255,.6); font-size:12px;
}
@media print{ .site-footer{ display:none; } }
