/* Shared layout for every game page: top bar, level picker, panels, modal. */

.btn.small { padding: 8px 14px; font-size: .95rem; border-radius: 12px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1150px;
  margin: 0 auto;
  padding: 12px 16px;
}
.topbar h1 { margin: 0; font-size: clamp(1.3rem, 4vw, 2rem); text-align: center; color: var(--wall); }

/* ---------- Niveles ---------- */
.levels { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; padding: 0 16px 12px; }
.level-btn {
  font: inherit;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  position: relative;
}
.level-btn.done { border-color: var(--green); }
.level-btn.done::after {
  content: attr(data-stars);
  position: absolute;
  bottom: -9px; left: 50%;
  transform: translateX(-50%);
  font-size: .62rem;
  color: #d4a20a;
  background: var(--bg);
  padding: 0 2px;
  white-space: nowrap;
}
.level-btn:active:not(:disabled) { transform: scale(.92); }
.level-btn.current { background: var(--blue); border-color: var(--blue); color: #fff; }
.level-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Layout ---------- */
.game-layout {
  max-width: 1150px;
  margin: 0 auto;
  padding: 4px 16px 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 880px) {
  .game-layout { grid-template-columns: minmax(0, 1fr); }
  .panel { position: static; max-height: none; overflow: visible; }
}
/* The play area is sized from the screen height so a whole level fits without scrolling. */
.game-layout { --stage-h: calc(100vh - 250px); }
@supports (height: 100dvh) { .game-layout { --stage-h: calc(100dvh - 250px); } }
@media (max-width: 880px) and (min-width: 600px) {
  /* Portrait tablet: the panel goes under the board in two columns, so leave room for it. */
  .game-layout { --stage-h: max(320px, calc(100vh - 590px)); }
  @supports (height: 100dvh) { .game-layout { --stage-h: max(320px, calc(100dvh - 590px)); } }
}

.stage h2 { margin: 0; font-size: 1.5rem; }
.goal { margin: 4px 0 14px; font-size: 1.12rem; color: var(--muted); }

.panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 4px 0 var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 150px);
  max-height: calc(100dvh - 150px);
  overflow-y: auto;
}
.panel > * { flex-shrink: 0; }
.panel h2 { margin: 0; font-size: 1.3rem; }
.tip { margin: 0; color: var(--muted); line-height: 1.4; }
.tip:empty { display: none; }

.controls { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 6px; }
.controls .play { font-size: 1.3rem; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(30, 42, 74, .55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
  background: #fff;
  border-radius: 24px;
  padding: 26px 24px 22px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  animation: bounceIn .4s cubic-bezier(.2, 1.6, .4, 1);
}
.modal-emoji { font-size: 4rem; line-height: 1; }
.modal-card h2 { margin: 8px 0 4px; font-size: 2.2rem; }
.modal-card.fail h2 { color: var(--red); }
.modal-card.win h2 { color: var(--green); }
.modal-card p { font-size: 1.12rem; line-height: 1.45; margin: 8px 0 14px; }
.modal-stars { font-size: 2.4rem; letter-spacing: 6px; }
.modal-stars .star { display: inline-block; animation: starPop .4s cubic-bezier(.2, 1.8, .4, 1) both; }
.modal-stars .star.off { filter: grayscale(1); opacity: .3; }
.star-reasons { list-style: none; padding: 0; margin: 0 0 16px; text-align: left; display: inline-block; }
.star-reasons li { margin: 3px 0; }
.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
@keyframes bounceIn { from { transform: scale(.6); opacity: 0; } }
@keyframes starPop { from { transform: scale(0) rotate(-90deg); } }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
