/* Cubrick — 8-level flat polyomino puzzle */

/* ── Page theme ────────────────────────────────────────────────────────────── */
body[data-tab="cubrick"] {
  background: #E8DCC8;
  color: #1A1A1A;
}

/* ── Main wrap ─────────────────────────────────────────────────────────────── */
#cubrick-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #E8DCC8;
  overflow: hidden;
  position: relative;
}

/* ── HUD ───────────────────────────────────────────────────────────────────── */
#cub-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(26,26,26,0.15);
  min-height: 44px;
  gap: 8px;
}

#cub-hud-left {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

#cub-level-label,
#cub-moves-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  color: rgba(26,26,26,0.6);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

#cub-level,
#cub-moves {
  font-weight: 700;
  color: #1A1A1A;
}

#cub-hud-right {
  display: flex;
  gap: 6px;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.cub-btn {
  font-family: 'DM Sans', sans-serif;
  background: #E8DCC8;
  border: 1.5px solid #1A1A1A;
  color: #1A1A1A;
  padding: 5px 12px;
  border-radius: 7px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
  letter-spacing: 0.02em;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.cub-btn:hover:not(:disabled)  { background: #DDD3BE; }
.cub-btn:active:not(:disabled) { background: #D2C8B4; }
.cub-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.cub-btn-primary {
  background: #1A1A1A;
  color: #E8DCC8;
  border-color: #1A1A1A;
}
.cub-btn-primary:hover:not(:disabled)  { background: #2D2D2D; }
.cub-btn-primary:active:not(:disabled) { background: #3A3A3A; }

/* ── Board area ────────────────────────────────────────────────────────────── */
#cub-board-area {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  overflow: hidden;
}

/* ── Flat 8×8 grid ─────────────────────────────────────────────────────────── */
#cub-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 1px;
  background: rgba(26,26,26,0.35);
  border: 1.5px solid #1A1A1A;
  border-radius: 3px;
  width: min(calc(100vw - 28px), calc(100vh - 272px), 440px);
  aspect-ratio: 1 / 1;
}

@supports (height: 100dvh) {
  #cub-grid {
    width: min(calc(100vw - 28px), calc(100dvh - 272px), 440px);
  }
}

.cub-cell {
  background: #E8DCC8;
  aspect-ratio: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.07s;
}

/* ── Piece tray row ────────────────────────────────────────────────────────── */
#cub-tray-row {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  border-top: 1px solid rgba(26,26,26,0.18);
  background: #E8DCC8;
  min-height: 82px;
  max-height: 96px;
}

#cub-tray {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  height: 100%;
}
#cub-tray::-webkit-scrollbar { display: none; }

/* ── Tray items ────────────────────────────────────────────────────────────── */
.cub-tray-item {
  flex-shrink: 0;
  width: 58px;
  height: 58px;
  cursor: pointer;
  border-radius: 8px;
  border: 2px solid transparent;
  transition: border-color 0.13s, opacity 0.13s, box-shadow 0.13s;
  -webkit-tap-highlight-color: transparent;
  background: rgba(26,26,26,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.cub-tray-item.cub-selected {
  border-color: #1A1A1A;
  box-shadow: 0 2px 8px rgba(26,26,26,0.18);
}

.cub-tray-item.cub-placed {
  opacity: 0.35;
  cursor: default;
}

.cub-tray-check {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  color: #1A1A1A;
  background: rgba(232,220,200,0.72);
  border-radius: 6px;
  pointer-events: none;
}
.cub-tray-item.cub-placed .cub-tray-check {
  display: flex;
}

/* ── Progress cube widget ──────────────────────────────────────────────────── */
#cub-progress-wrap {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 12px;
  border-left: 1px solid rgba(26,26,26,0.14);
  height: 100%;
  justify-content: center;
}

#cub-progress-cube {
  display: block;
  width: 60px;
  height: 60px;
}

#cub-progress-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.58rem;
  font-weight: 600;
  color: rgba(26,26,26,0.45);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ── Overlays (level-complete + final win) ─────────────────────────────────── */
.cub-overlay {
  position: fixed;
  inset: 0;
  background: rgba(232,220,200,0.90);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
}
.cub-overlay.hidden {
  display: none;
}

.cub-modal {
  background: #F4EDE0;
  border: 1.5px solid #1A1A1A;
  border-radius: 16px;
  padding: 28px 24px;
  width: min(360px, 100%);
  text-align: center;
  box-shadow: 0 12px 40px rgba(26,26,26,0.16);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.cub-headline {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 1.85rem;
  font-weight: 400;
  color: #1A1A1A;
  margin: 0;
  letter-spacing: -0.01em;
}

.cub-subline {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  color: rgba(26,26,26,0.55);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
  margin: 0;
}

/* ── Win cube (large, in win modal) ───────────────────────────────────────── */
#cub-win-cube {
  display: block;
  margin: 0 auto;
}

.cub-modal-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Directions popup (Cubrick palette) ────────────────────────────────────── */
.directions-modal.popup--cubrick {
  background: #E8DCC8;
  border: 1.5px solid #1A1A1A;
}
.popup--cubrick .dir-heading {
  font-family: 'DM Serif Display', Georgia, serif;
  color: #1A1A1A;
}
.popup--cubrick .dir-pane {
  font-family: 'DM Sans', sans-serif;
  color: rgba(26,26,26,0.85);
}
.popup--cubrick .dir-close-btn {
  background: #E8DCC8;
  border: 1.5px solid #1A1A1A;
  color: #1A1A1A;
}
.popup--cubrick .dir-close-btn:hover  { background: #D9CCBA; }
.popup--cubrick .dir-close-btn:active { background: #CFC2AC; }

/* ── Invalid placement shake ───────────────────────────────────────────────── */
@keyframes cub-shake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-5px); }
  45%     { transform: translateX(5px); }
  65%     { transform: translateX(-3px); }
  85%     { transform: translateX(3px); }
}
#cub-board-area.cub-shake {
  animation: cub-shake 0.3s ease-out;
}
