#app { position: relative; max-width: 1040px; margin: 0 auto; padding: 16px 20px; }

/* ---------- Pick a room ---------- */
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
#card-rooms { --main: #7b61ff; --on-main: #fff; }
.stars-total { margin: 10px 0 12px; font-size: 18px; font-weight: 900; }
.rooms { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.room {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: 78px;
  font: inherit; font-weight: 900; font-size: 26px; color: var(--ink);
  border: 3px solid var(--ink); border-radius: 16px;
  background-image: linear-gradient(rgba(255, 255, 255, .6), rgba(255, 255, 255, 0) 48%, rgba(0, 0, 0, .08));
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  transition: transform .1s;
}
@media (hover: hover) { .room:hover:not(:disabled) { transform: translateY(-3px) scale(1.04); } }
.room:focus-visible { outline: 4px solid var(--sun); outline-offset: 2px; }
.room.slide { background-color: #9bdcff; }
.room.flip { background-color: #d5c4ff; }
.room.turn { background-color: #ffcf9a; }
.room.all { background-color: #fff; background-image: linear-gradient(120deg, #ffc2d9, #ffe9a0, #b8f0c8, #b9dcff, #d9c8ff); }
.room .mini { font-size: 13px; letter-spacing: 1px; line-height: 1; }
.room:disabled { cursor: not-allowed; filter: grayscale(1); opacity: .5; box-shadow: none; }
.room.next { animation: bob 1s ease-in-out infinite; }
.rooms-key { margin: 14px 0 0; font-size: 13px; font-weight: 800; color: #6b6690; }

/* ---------- Play: one window tall, the 3D board takes the spare room ---------- */
#screen-play { display: flex; flex-direction: column; gap: 10px; height: calc(100dvh - 32px); min-height: 480px; }
.hud { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stat {
  padding: 6px 14px;
  font-size: 18px; font-weight: 900;
  background: rgba(255, 255, 255, .88);
  border: 3px solid var(--ink); border-radius: 999px;
  box-shadow: 0 4px 0 var(--ink);
  font-variant-numeric: tabular-nums;
}
.stat.title { margin-right: auto; }
.stat.moves { background: var(--sun); }

.field { position: relative; flex: 1 1 0; min-height: 220px; margin: 0 -20px; }
#stage {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  -webkit-mask-image: linear-gradient(transparent, #000 5%, #000 95%, transparent);
  mask-image: linear-gradient(transparent, #000 5%, #000 95%, transparent);
}

/* Flat board, shown only when the browser cannot draw 3D. */
.flat { position: absolute; inset: 10px; display: grid; place-content: center; grid-template-columns: repeat(8, minmax(0, 44px)); grid-auto-rows: minmax(0, 44px); gap: 3px; }
.flat i { border-radius: 6px; background: rgba(255, 255, 255, .7); }
.flat i.target { box-shadow: inset 0 0 0 4px #e0a000; background: #fff3b8; }
.flat i.shape { background: var(--main); border: 2px solid var(--ink); }
.flat i.pivot { background: var(--main); border: 2px solid var(--ink); box-shadow: inset 0 0 0 8px rgba(255, 255, 255, .7); }

.win {
  /* sits at the top of the board, so the solved shape stays in view */
  position: absolute; left: 50%; top: 4px; transform: translateX(-50%);
  width: min(560px, calc(100% - 40px));
  padding: 10px 20px 16px;
  text-align: center;
  background: linear-gradient(#fff, #f3f0ff);
  border: 4px solid var(--ink); border-radius: var(--radius);
  box-shadow: 0 8px 0 var(--ink), 0 22px 28px rgba(43, 35, 80, .3);
  animation: pop .35s cubic-bezier(.3, 1.5, .5, 1);
}
@keyframes pop { from { transform: translateX(-50%) scale(.6); opacity: 0; } }
.win-stars { font-size: 40px; line-height: 1.1; letter-spacing: 6px; }
.win-stars .off { filter: grayscale(1); opacity: .3; }
.win h2 { margin: 2px 0; font-size: 26px; font-weight: 900; }
.win p { margin: 0 0 12px; font-size: 16px; font-weight: 800; color: #4a4470; }
.win .btn.big { font-size: 20px; padding: 10px 24px; }
.row { display: flex; gap: 14px; justify-content: center; align-items: center; flex-wrap: wrap; }

.controls-card {
  flex: 0 0 auto;
  background: linear-gradient(#fff, #f3f0ff);
  border: 4px solid var(--ink);
  border-top: 12px solid var(--main);
  border-radius: var(--radius);
  box-shadow: 0 8px 0 var(--ink), 0 20px 26px rgba(43, 35, 80, .22);
  padding: 10px 18px 14px;
  margin-bottom: 10px;
}
.tip { margin: 0 0 10px; text-align: center; font-size: 16px; font-weight: 800; color: #4a4470; min-height: 22px; }
.tip.bad { color: #c92a2a; }
.controls { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; }
.group { display: flex; gap: 10px; align-items: center; }
.group[hidden] { display: none; }
.move { display: flex; flex-direction: column; align-items: center; gap: 0; min-width: 76px; padding: 6px 12px 8px; font-size: 15px; }
.move .icon { font-size: 30px; line-height: 1; }
.group[data-kind="turn"] .move { background-color: #ffcf9a; }
.group[data-kind="flip"] .move { background-color: #d5c4ff; }
.group[data-kind="slide"] .move { background-color: #9bdcff; }
.move kbd, .tools kbd { font: inherit; font-size: 11px; font-weight: 900; background: var(--ink); color: #fff; border-radius: 6px; padding: 0 6px; margin-top: 3px; }
.pad { display: grid; grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(2, 44px); gap: 6px; }
.pad .move { min-width: 0; padding: 0; font-size: 20px; justify-content: center; }
.pad .up { grid-column: 2; grid-row: 1; }
.pad .left { grid-column: 1; grid-row: 2; }
.pad .down { grid-column: 2; grid-row: 2; }
.pad .right { grid-column: 3; grid-row: 2; }
.tools { flex-direction: column; gap: 8px; }
.controls.locked { pointer-events: none; opacity: .55; }

#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 20; }
#confetti i { position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 900px) { .logo { margin-top: 50px; } }
@media (max-width: 640px) {
  .setup-grid { grid-template-columns: 1fr; }
  .hud { gap: 8px; }
  .stat { font-size: 15px; padding: 4px 10px; }
}

/* Phones: every move fits in one small block, so the board keeps most of the screen.
   Turns stack on the left, the arrow pad sits in the middle, flips stack on the right
   and Undo and Restart share a row underneath. */
@media (max-width: 640px), (orientation: landscape) and (max-height: 500px) {
  .controls-card { padding: 8px 12px 12px; border-top-width: 10px; }
  .tip { margin-bottom: 8px; font-size: 14px; min-height: 0; }
  .controls { gap: 8px 10px; flex-wrap: wrap; }
  .group[data-kind="turn"], .group[data-kind="flip"] { flex-direction: column; gap: 6px; }
  .group[data-kind="turn"] .move, .group[data-kind="flip"] .move {
    justify-content: center; width: 64px; min-width: 0; height: 44px; padding: 0; font-size: 12px; line-height: 1.1;
  }
  .move .icon { font-size: 20px; }
  .pad { grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(2, 44px); }
  .tools { flex: 1 0 100%; flex-direction: row; justify-content: center; }
  .btn.small { padding: 5px 12px; }
  .win { padding: 8px 14px 14px; width: min(560px, calc(100% - 24px)); }
  .win-stars { font-size: 30px; }
  .win h2 { font-size: 22px; }
  .win p { font-size: 14px; margin-bottom: 10px; }
  .win .row { flex-wrap: nowrap; gap: 8px; }
  .win .btn, .win .btn.big { font-size: 16px; padding: 8px 14px; }
}

/* A phone held sideways: the HUD runs along the top, the board fills the left
   and the controls sit beside it. */
@media (orientation: landscape) and (max-height: 500px) {
  #app { padding: 8px 16px; }
  #screen-play {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(340px, 46%);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px 14px;
    height: calc(100dvh - 16px); min-height: 0;
  }
  .hud { grid-column: 1 / -1; gap: 8px; }
  .stat { font-size: 15px; padding: 3px 10px; }
  .btn.small { padding: 4px 12px; }
  .field { grid-column: 1; grid-row: 2; min-height: 0; margin: 0 0 0 -16px; }
  .controls-card { grid-column: 2; grid-row: 2; align-self: center; margin-bottom: 8px; }
}
